Changeset 2122 for trunk/tools


Ignore:
Timestamp:
Nov 30, 2012, 1:51:53 AM (8 years ago)
Author:
sam
Message:

vslol: only apply our syntax highlighting to keywords and identifiers
and update the version of the extension for publishing.

Location:
trunk/tools/vslol
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/vslol/CppKeywordClassifier.cs

    r2121 r2122  
    2121        [Import]
    2222        internal IClassificationTypeRegistryService m_type_registry = null; /* Set via MEF */
    23 
     23        [Import]
     24        internal IClassifierAggregatorService m_aggregator = null;
    2425        [Import]
    2526        internal IClassificationFormatMapService m_format_map = null;
    2627
     28        internal static bool m_inprogress = false;
     29
    2730        public IClassifier GetClassifier(ITextBuffer buffer)
    2831        {
     32            /* Avoid infinite recursion */
     33            if (m_inprogress)
     34                return null;
     35
    2936            LolGenericFormat.SetRegistry(m_type_registry, m_format_map);
    3037
    31             return buffer.Properties.GetOrCreateSingletonProperty<CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_type_registry, buffer.ContentType); });
     38            try
     39            {
     40                m_inprogress = true;
     41                return buffer.Properties.GetOrCreateSingletonProperty<CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_type_registry, m_aggregator.GetClassifier(buffer), buffer.ContentType); });
     42            }
     43            finally { m_inprogress = false; }
    3244        }
    3345    }
     
    3547    class CppKeywordClassifier : IClassifier
    3648    {
     49        private IClassifier m_classifier;
     50
    3751        private IClassificationType m_customclass_type;
    38         private Regex m_regex;
     52        private Regex m_customclass_regex;
    3953
    4054        internal CppKeywordClassifier(IClassificationTypeRegistryService registry,
     55                                      IClassifier classifier,
    4156                                      IContentType type)
    4257        {
     58            m_classifier = classifier;
     59
    4360            m_customclass_type = registry.GetClassificationType("LolCustomClass");
    4461
     
    5774                tmp += "real|half|explicit|typename|typedef|";
    5875            }
     76            tmp = tmp.Remove(tmp.Length - 1);
    5977            tmp += @")\b";
    60             m_regex = new Regex(tmp);
     78            m_customclass_regex = new Regex(tmp);
    6179        }
    6280
     
    6583            List<ClassificationSpan> ret = new List<ClassificationSpan>();
    6684
    67             string tmp = span.GetText();
    68             var matches = m_regex.Matches(tmp);
    69             foreach (Match m in matches)
     85            foreach (ClassificationSpan cs in m_classifier.GetClassificationSpans(span))
    7086            {
    71                 Span newspan = new Span(span.Start.Position + m.Index, m.Length);
    72                 SnapshotSpan newsnapshot = new SnapshotSpan(span.Snapshot, newspan);
    73                 ret.Add(new ClassificationSpan(newsnapshot, m_customclass_type));
     87                string cs_class = cs.ClassificationType.Classification.ToLower();
     88
     89                /* Only apply our rules if we found a keyword or an identifier */
     90                if (cs_class == "keyword" || cs_class == "identifier")
     91                {
     92                    if (m_customclass_regex.IsMatch(cs.Span.GetText()))
     93                    {
     94                        ret.Add(new ClassificationSpan(cs.Span, m_customclass_type));
     95                        continue;
     96                    }
     97                }
     98
     99                ret.Add(cs);
    74100            }
    75101
  • trunk/tools/vslol/Properties/AssemblyInfo.cs

    r2119 r2122  
    2121[assembly: Guid("58968f91-edb8-4a4c-9f4f-ba39fdb4a21a")]
    2222
    23 [assembly: AssemblyVersion("1.0.0.4")]
    24 [assembly: AssemblyFileVersion("1.0.0.4")]
     23[assembly: AssemblyVersion("1.0.0.5")]
     24[assembly: AssemblyFileVersion("1.0.0.5")]
  • trunk/tools/vslol/source.extension.vsixmanifest

    r2121 r2122  
    44    <Name>VsLol</Name>
    55    <Author>Lol</Author>
    6     <Version>1.0.0.4</Version>
     6    <Version>1.0.0.5</Version>
    77    <Description xml:space="preserve">Lol Engine Productivity Tools.</Description>
    88    <Locale>1033</Locale>
Note: See TracChangeset for help on using the changeset viewer.