Exemple #1
0
        protected override Comment SpecificParse(SnapshotSpan span, CommentType commentType)
        {
            var spanText = span.GetText().ToLower();

            var commentSpans = new List <SnapshotSpan>();

            var startOffset = ParseHelper.ComputeSingleLineCommentStartIndex(spanText, "////", commentType);

            if (spanText.StartsWith("//"))
            {
                commentSpans.Add(new SnapshotSpan(span.Snapshot, span.Start + startOffset, span.Length - startOffset));
            }
            else if (spanText.StartsWith("/*") && spanText.EndsWith("*/") && spanText.Length > 5)
            {
                startOffset = ParseHelper.ComputeDelimitedCommentStartIndex(spanText, commentType);
                var spanLength = spanText.IndexOfFirstCharReverse(spanText.IndexOf("*/") - 1) - (startOffset - 1);

                if (spanLength > 0)
                {
                    commentSpans.Add(new SnapshotSpan(span.Snapshot, span.Start + startOffset, spanLength));
                }
            }

            return(new Comment(commentSpans, commentType));
        }
Exemple #2
0
        protected override Comment SpecificParse(SnapshotSpan span, CommentType commentType)
        {
            var spanText = span.GetText().ToLower();

            var commentSpans = new List <SnapshotSpan>();

            var firstLineNumber = span.Snapshot.GetLineFromPosition(span.Start).LineNumber;
            var lastLineNumber  = span.Snapshot.GetLineFromPosition(span.End).LineNumber;

            if (firstLineNumber == lastLineNumber) //! The comment span consists of a single line.
            {
                var startOffset = ParseHelper.ComputeSingleLineCommentStartIndex(spanText, "////", commentType);

                var spanLength = spanText.StartsWith("//")
                               ? span.Length - startOffset
                               : spanText.IndexOfFirstCharReverse(spanText.IndexOf("*/") - 1) - (startOffset - 1);

                if (spanLength > 0)
                {
                    commentSpans.Add(new SnapshotSpan(span.Snapshot, span.Start + startOffset, spanLength));
                }
            }
            else //! The comment spans multiple lines
            {
                var startOffset = ParseHelper.ComputeDelimitedCommentStartIndex(spanText, commentType);

                for (var curr = firstLineNumber; curr <= lastLineNumber; curr++)
                {
                    var token    = Settings.Instance.GetTokenValue(commentType);
                    var line     = span.Snapshot.GetLineFromLineNumber(curr);
                    var lineText = line.GetText().ToLower();

                    if (curr == firstLineNumber && lineText.Length > token.Length + 2) //! First line.
                    {
                        var index = lineText.IndexOf("/*");

                        startOffset = commentType == CommentType.Task
                                    ? lineText.IndexOf(token)
                                    : lineText.IndexOfFirstChar(lineText.IndexOf(token) + token.Length);

                        commentSpans.Add(new SnapshotSpan(span.Snapshot, line.Start + startOffset, line.Length - startOffset));
                    }
                    else if (curr > firstLineNumber && curr < lastLineNumber) //! Line in the middle
                    {
                        startOffset = lineText.IndexOfFirstChar();
                        commentSpans.Add(new SnapshotSpan(span.Snapshot, line.Start + startOffset, line.Length - startOffset));
                    }
                    else if (lineText.Contains("*/") && !lineText.Trim().StartsWith("*/"))//! Last line . Handle it ONLY if it is more than just a comment ender.
                    {
                        startOffset = lineText.IndexOfFirstChar();
                        var spanLength = lineText.IndexOfFirstCharReverse(lineText.IndexOf("*/") - 1) - startOffset + 1;

                        commentSpans.Add(new SnapshotSpan(span.Snapshot, line.Start + startOffset, spanLength));
                    }
                }
            }

            return(new Comment(commentSpans, commentType));
        }
        protected override Comment SpecificParse(SnapshotSpan span, CommentType commentType)
        {
            var spanText = span.GetText().ToLower();

            if (spanText.StartsWith("//")) //! The comment span consists of a single line.
            {
                var fullSpan = ParseHelper.CompleteSingleLineCommentSpan(span, "//");

                spanText = fullSpan.GetText().ToLower();

                var startOffset = ParseHelper.ComputeSingleLineCommentStartIndex(spanText, "////", commentType);
                var spanLength  = spanText.Length - startOffset;

                if (spanLength > 0)
                {
                    return(new Comment(
                               new SnapshotSpan(fullSpan.Snapshot, fullSpan.Start + startOffset, spanLength),
                               commentType));
                }
            }
            else if (spanText.Contains("/*"))
            {
                var fullSpans = ParseHelper.CompleteDelimitedCommentSpan(span, "/*", "*/");

                if (fullSpans.Count == 1)
                {
                    spanText = fullSpans[0].GetText().ToLower();
                    var startOffset = ParseHelper.ComputeDelimitedCommentStartIndex(spanText, commentType);
                    var spanLength  = spanText.IndexOfFirstCharReverse(spanText.IndexOf("*/") - 1) - (startOffset - 1);

                    if (spanLength > 0)
                    {
                        return(new Comment(
                                   new SnapshotSpan(fullSpans[0].Snapshot, fullSpans[0].Start + startOffset, spanLength),
                                   commentType));
                    }
                }
            }

            return(new Comment(new List <SnapshotSpan>(), commentType));
        }