Esempio n. 1
0
 static CommentTagger()
 {
     CommentTagger.Comments = new string[]
     {
         "//",
         "///",
         "'",
         "#",
         "<!--"
     };
     CommentTagger.ImportantComments = new string[]
     {
         "! ",
         "# "
     };
     CommentTagger.QuestionComments = new string[]
     {
         "? "
     };
     CommentTagger.WtfComments = new string[]
     {
         "& ",
         "!? ",
         "‽ ",
         "WTF ",
         "WTF: "
     };
     CommentTagger.RemovedComments = new string[]
     {
         "x ",
         "¤ ",
         "// ",
         "//"
     };
     CommentTagger.TaskComments = new string[]
     {
         "TODO ",
         "TODO:",
         "TODO@",
         "HACK ",
         "HACK:",
         "@ "
     };
     CommentTagger.EmptyTags = new List <ITagSpan <ClassificationTag> >();
     CommentTagger._enabled  = CommentTagger.IsEnabled();
 }
Esempio n. 2
0
 private static bool Match(string commentText, int startIndex, string[] templates, out string match)
 {
     return(CommentTagger.Match(commentText, startIndex, templates, StringComparison.Ordinal, out match));
 }
Esempio n. 3
0
 private bool IsMarkup(IContentType contentType)
 {
     return(CommentTagger.IsHtmlMarkup(contentType) || CommentTagger.IsXmlMarkup(contentType));
 }
Esempio n. 4
0
        private IEnumerable <ITagSpan <ClassificationTag> > GetTagsInternal(NormalizedSnapshotSpanCollection spans)
        {
            if (!CommentTagger._enabled || spans.Count == 0)
            {
                return(CommentTagger.EmptyTags);
            }
            ITextSnapshot snapshot    = spans[0].Snapshot;
            IContentType  contentType = snapshot.TextBuffer.ContentType;

            if (!contentType.IsOfType("code"))
            {
                return(CommentTagger.EmptyTags);
            }
            bool flag = this.IsMarkup(contentType);
            Dictionary <Classification, ClassificationTag> dictionary = this._classifications;

            if (CommentTagger.IsHtmlMarkup(contentType))
            {
                dictionary = this._htmlClassifications;
            }
            else if (CommentTagger.IsXmlMarkup(contentType))
            {
                dictionary = this._xmlClassifications;
            }
            List <ITagSpan <ClassificationTag> > list = null;

            foreach (IMappingTagSpan <IClassificationTag> current in this._aggregator.GetTags(spans))
            {
                string classification = current.Tag.ClassificationType.Classification;
                if (classification.Contains("comment", StringComparison.OrdinalIgnoreCase))
                {
                    NormalizedSnapshotSpanCollection spans2 = current.Span.GetSpans(snapshot);
                    if (spans2.Count > 0)
                    {
                        SnapshotSpan snapshotSpan = spans2[0];
                        string       text         = snapshotSpan.GetText();
                        if (!string.IsNullOrWhiteSpace(text))
                        {
                            string text2 = text.StartsWithOneOf(CommentTagger.Comments, StringComparison.Ordinal);
                            if (text2 == null)
                            {
                                if (!flag)
                                {
                                    continue;
                                }
                                text2 = "";
                            }
                            int length = text2.Length;
                            int num    = 0;
                            if (flag && text2.Length > 0)
                            {
                                if (!text.EndsWith("-->"))
                                {
                                    continue;
                                }
                                num = 3;
                            }
                            ClassificationTag classificationTag = null;
                            string            text3;
                            if (CommentTagger.Match(text, length, CommentTagger.ImportantComments, out text3))
                            {
                                classificationTag = dictionary[Classification.Important];
                            }
                            else if (CommentTagger.Match(text, length, CommentTagger.QuestionComments, out text3))
                            {
                                classificationTag = dictionary[Classification.Question];
                            }
                            else if (CommentTagger.Match(text, length, CommentTagger.RemovedComments, out text3))
                            {
                                if (text2 == "//" && text3 == "//")
                                {
                                    int num2 = length + text3.Length;
                                    if (text.Length > num2 && text[num2] != '/')
                                    {
                                        classificationTag = dictionary[Classification.Removed];
                                    }
                                }
                                else
                                {
                                    classificationTag = dictionary[Classification.Removed];
                                }
                            }
                            else if (CommentTagger.Match(text, length, CommentTagger.TaskComments, StringComparison.OrdinalIgnoreCase, out text3))
                            {
                                CommentTagger.FixTaskComment(text, length, ref text3);
                                classificationTag = dictionary[Classification.Task];
                            }
                            else if (CommentTagger.Match(text, length, CommentTagger.WtfComments, out text3))
                            {
                                classificationTag = dictionary[Classification.Wtf];
                            }
                            if (classificationTag != null)
                            {
                                int          num3                = text2.Length + text3.Length;
                                int          num4                = snapshotSpan.Length - (num3 + num);
                                SnapshotSpan snapshotSpan2       = new SnapshotSpan(snapshotSpan.Snapshot, snapshotSpan.Start + num3, num4);
                                TagSpan <ClassificationTag> item = new TagSpan <ClassificationTag>(snapshotSpan2, classificationTag);
                                if (list == null)
                                {
                                    list = new List <ITagSpan <ClassificationTag> >();
                                }
                                list.Add(item);
                            }
                        }
                    }
                }
            }
            return(list ?? CommentTagger.EmptyTags);
        }