コード例 #1
0
        public IEnumerable <ITagSpan <BookmarkHeaderTag> > GetTags(NormalizedSnapshotSpanCollection source)
        {
            foreach (var curSpan in tagAggregator.GetCommentSnapshotSpans(source))
            {
                var targetSpan = curSpan;

                if (contentType.IsOfType("TypeScript"))
                {
                    if (!targetSpan.GetText().StartsWith("//"))
                    {
                        continue;
                    }

                    var line   = targetSpan.Snapshot.GetLineFromPosition(targetSpan.Start);
                    var offset = line.GetText().IndexOf(commentDelimiter);

                    targetSpan = new SnapshotSpan(targetSpan.Snapshot, line.Start + offset, line.Length - offset);
                }

                var spanText = targetSpan.GetText();

                // Make sure text is not empty, and that it's more than an empty comment
                if (spanText.Length < commentDelimiter.Length)
                {
                    continue;
                }

                spanText = spanText.Substring(commentDelimiter.Length).TrimStart();

                foreach (var cls in configs.Classifications)
                {
                    if (spanText.StartsWith($"{cls.Token} ", StringComparison.OrdinalIgnoreCase))
                    {
                        var tokenIndex = targetSpan.GetText().IndexOf(cls.Token, commentDelimiter.Length, StringComparison.OrdinalIgnoreCase);
                        var emptySpace = tokenIndex - commentDelimiter.Length;
                        var length     = commentDelimiter.Length + emptySpace + cls.Token.Length;

                        var newSpan = new SnapshotSpan(targetSpan.Start, length);

                        yield return(new TagSpan <BookmarkHeaderTag>(
                                         newSpan,
                                         new BookmarkHeaderTag(cls)
                                         ));
                    }
                }
            }
        }