Esempio n. 1
0
        /// <summary>
        /// Reformat all comments between the specified start and end point. Comments that start
        /// within the range, even if they overlap the end are included.
        /// </summary>
        /// <param name="textDocument">The text document.</param>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        public bool FormatComments(TextDocument textDocument, EditPoint start, EditPoint end)
        {
            bool foundComments = false;
            int  tabSize       = CodeCommentHelper.GetTabSize(_package, textDocument);

            while (start.Line <= end.Line)
            {
                if (CodeCommentHelper.IsCommentLine(start))
                {
                    var comment = new CodeComment(start, tabSize);
                    if (comment.IsValid)
                    {
                        comment.Format();
                        foundComments = true;
                    }

                    if (comment.EndPoint != null)
                    {
                        start = comment.EndPoint.CreateEditPoint();
                    }
                }

                if (start.Line == textDocument.EndPoint.Line)
                {
                    break;
                }

                start.LineDown();
                start.StartOfLine();
            }

            return(foundComments);
        }
Esempio n. 2
0
        /// <summary>
        /// Reformat all comments between the specified start and end point. Comments that start
        /// within the range, even if they overlap the end are included.
        /// </summary>
        /// <param name="textDocument">The text document.</param>
        /// <param name="start">The start point.</param>
        /// <param name="end">The end point.</param>
        public bool FormatComments(TextDocument textDocument, EditPoint start, EditPoint end)
        {
            bool foundComments = false;

            var options = new FormatterOptions
            {
                TabSize      = CodeCommentHelper.GetTabSize(_package, textDocument),
                IgnoreTokens = CodeCommentHelper
                               .GetTaskListTokens(_package)
                               .Concat(Settings.Default.Formatting_IgnoreLinesStartingWith.Cast <string>())
                               .ToArray()
            };

            while (start.Line <= end.Line)
            {
                if (CodeCommentHelper.IsCommentLine(start))
                {
                    var comment = new CodeComment(start, options);

                    if (comment.IsValid)
                    {
                        comment.Format();
                        foundComments = true;
                    }

                    if (comment.EndPoint != null)
                    {
                        start = comment.EndPoint.CreateEditPoint();
                    }
                }

                if (start.Line == textDocument.EndPoint.Line)
                {
                    break;
                }

                start.LineDown();
                start.StartOfLine();
            }

            return(foundComments);
        }
Esempio n. 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CodeCommentOptions" /> class.
 /// </summary>
 /// <param name="settings">The settings container.</param>
 /// <param name="package">The hosting package.</param>
 /// <param name="document">The text document.</param>
 public CodeCommentOptions(Settings settings, CodeMaidPackage package, TextDocument document)
     : this(settings, CodeCommentHelper.GetTabSize(package, document))
 {
 }