示例#1
0
        public IEnumerable <ITagSpan <KeywordTag> > GetTags(NormalizedSnapshotSpanCollection spans)
        {
            if (spans.Count == 0)
            {
                yield break;
            }
            ILanguage            lang    = GetLanguageByContentType(this.theBuffer.ContentType);
            ILanguageWithStrings langStr = lang as ILanguageWithStrings;

            if (!lang.Settings.Enabled)
            {
                yield break;
            }
            // ugly, ugly hack
            bool isCpp = this.theBuffer.ContentType.IsOfType(ContentTypes.Cpp);

            bool eshe = this.settings.EscapeSequencesEnabled;
            bool kce  = this.settings.KeywordClassifierEnabled;

            if (!(kce || eshe))
            {
                yield break;
            }

            ITextSnapshot snapshot = spans[0].Snapshot;

            // Get all spans that contain interesting tags
            // translated into our snapshot
            var interestingSpans = from tagSpan in this.aggregator.GetTags(spans)
                                   let classificationType = tagSpan.Tag.ClassificationType
                                                            where IsInterestingTag(lang, classificationType)
                                                            select tagSpan.ToTagSpan(snapshot);

            // GetTags() coalesce adjacent spans with the same tag
            // so that we can process them as a single span
            foreach (var tagSpan in GetTags(interestingSpans, snapshot))
            {
                var    classificationType = tagSpan.Tag.ClassificationType;
                String name = classificationType.Classification;

                if (eshe && IsString(langStr, name))
                {
                    foreach (var escapeTag in ProcessEscapeSequences(lang, name, tagSpan.Span, isCpp))
                    {
                        yield return(escapeTag);
                    }
                }

                if (kce && lang.IsKeywordClassification(classificationType.Classification))
                {
                    // Is this one of the keywords we care about?
                    var result = IsInterestingKeyword(lang, tagSpan.Span);
                    if (result != null)
                    {
                        yield return(result);
                    }
                }
            }
        }
示例#2
0
 private bool IsString(ILanguageWithStrings langStr, string name)
 {
     if (langStr != null)
     {
         return(langStr.IsStringClassification(name));
     }
     return(name.IndexOf(name, StringComparison.OrdinalIgnoreCase) >= 0);
 }