protected override Comment SpecificParse(SnapshotSpan span, CommentType commentType) { var spanText = span.GetText().ToLower(); var commentSpans = new List <SnapshotSpan>(); var startOffset = ParseHelper.SingleLineCommentStartIndex(spanText, "////", commentType); // single line comment if (spanText.StartsWith("//", OrdinalIgnoreCase)) { commentSpans.Add( new SnapshotSpan(span.Snapshot, span.Start + startOffset, span.Length - startOffset)); } // delimited comment in a single line else if (spanText.StartsWith("/*", OrdinalIgnoreCase) && spanText.EndsWith("*/", OrdinalIgnoreCase) && spanText.Length > 5) { startOffset = ParseHelper.DelimitedCommentStartIndex(spanText, commentType); var indexOfStarter = spanText.IndexOf("*/", OrdinalIgnoreCase); var spanLength = spanText.IndexOfFirstCharReverse(indexOfStarter - 1) - (startOffset - 1); if (spanLength > 0) { commentSpans.Add(new SnapshotSpan(span.Snapshot, span.Start + startOffset, spanLength)); } } return(new Comment(commentSpans, commentType)); }
protected override Comment SpecificParse(SnapshotSpan span, CommentType commentType) { var spanText = span.GetText().ToLower(); if (spanText.StartsWith("//", OrdinalIgnoreCase)) //! The comment span consists of a single line. { var fullSpan = ParseHelper.CompleteSingleLineCommentSpan(span, "//"); spanText = fullSpan.GetText().ToLower(); var startOffset = ParseHelper.SingleLineCommentStartIndex(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.DelimitedCommentStartIndex(spanText, commentType); var closerIndex = spanText.IndexOf("*/", OrdinalIgnoreCase); var spanLength = spanText.IndexOfFirstCharReverse(closerIndex - 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)); }
protected override Comment SpecificParse(SnapshotSpan span, CommentType commentType) { var spanText = span.GetText().ToLower(); var commentSpans = new List <SnapshotSpan>(); var startOffset = ParseHelper.SingleLineCommentStartIndex(spanText, "////", commentType); if (spanText.StartsWith("//", OrdinalIgnoreCase) && startOffset > 0) { commentSpans.Add(new SnapshotSpan(span.Snapshot, span.Start + startOffset, span.Length - startOffset)); } else if (spanText.Contains("(*") && spanText.Contains("*)")) { startOffset = ParseHelper.DelimitedCommentStartIndex(spanText, commentType); var closerIndex = spanText.IndexOf("*)", OrdinalIgnoreCase); var spanLength = spanText.IndexOfFirstCharReverse(closerIndex - 1) - (startOffset - 1); commentSpans.Add(new SnapshotSpan(span.Snapshot, span.Start + startOffset, spanLength)); } return(new Comment(commentSpans, commentType)); }
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.SingleLineCommentStartIndex(spanText, "////", commentType); var spanLength = 0; if (spanText.StartsWith("//", OrdinalIgnoreCase)) { spanLength = span.Length - startOffset; } else { var closerIndex = spanText.IndexOf("*/", OrdinalIgnoreCase); spanLength = spanText.IndexOfFirstCharReverse(closerIndex - 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.DelimitedCommentStartIndex(spanText, commentType); var token = Settings.Instance.GetTokenValue(commentType); for (var curr = firstLineNumber; curr <= lastLineNumber; curr++) { 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("/*", OrdinalIgnoreCase); if (commentType == CommentType.Task) { startOffset = lineText.IndexOf(token, OrdinalIgnoreCase); } else { var indexOfToken = lineText.IndexOf(token, OrdinalIgnoreCase); startOffset = lineText.IndexOfFirstChar(indexOfToken + token.Length); } commentSpans.Add(new SnapshotSpan(span.Snapshot, line.Start + startOffset, line.Length - startOffset)); } else if (curr > firstLineNumber && curr < lastLineNumber) //! Line in the middle { if (!string.IsNullOrWhiteSpace(lineText)) { startOffset = lineText.IndexOfFirstChar(); commentSpans.Add(new SnapshotSpan(span.Snapshot, line.Start + startOffset, line.Length - startOffset)); } } //! Last line . Handle it ONLY if it is more than just a comment ender. else if (lineText.Contains("*/") && !lineText.Trim().StartsWith("*/", OrdinalIgnoreCase)) { startOffset = lineText.IndexOfFirstChar(); var closerIndex = lineText.IndexOf("*/", OrdinalIgnoreCase); var spanLength = lineText.IndexOfFirstCharReverse(closerIndex - 1) - startOffset + 1; commentSpans.Add(new SnapshotSpan(span.Snapshot, line.Start + startOffset, spanLength)); } } } return(new Comment(commentSpans, commentType)); }