Explorar el Código

vslol: only apply our syntax highlighting to keywords and identifiers

and update the version of the extension for publishing.
legacy
Sam Hocevar sam hace 12 años
padre
commit
0eedbfd9f9
Se han modificado 3 ficheros con 39 adiciones y 13 borrados
  1. +36
    -10
      tools/vslol/CppKeywordClassifier.cs
  2. +2
    -2
      tools/vslol/Properties/AssemblyInfo.cs
  3. +1
    -1
      tools/vslol/source.extension.vsixmanifest

+ 36
- 10
tools/vslol/CppKeywordClassifier.cs Ver fichero

@@ -20,26 +20,43 @@ namespace Lol.VisualStudio.Plugin
{ {
[Import] [Import]
internal IClassificationTypeRegistryService m_type_registry = null; /* Set via MEF */ internal IClassificationTypeRegistryService m_type_registry = null; /* Set via MEF */

[Import]
internal IClassifierAggregatorService m_aggregator = null;
[Import] [Import]
internal IClassificationFormatMapService m_format_map = null; internal IClassificationFormatMapService m_format_map = null;


internal static bool m_inprogress = false;

public IClassifier GetClassifier(ITextBuffer buffer) public IClassifier GetClassifier(ITextBuffer buffer)
{ {
/* Avoid infinite recursion */
if (m_inprogress)
return null;

LolGenericFormat.SetRegistry(m_type_registry, m_format_map); LolGenericFormat.SetRegistry(m_type_registry, m_format_map);


return buffer.Properties.GetOrCreateSingletonProperty<CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_type_registry, buffer.ContentType); }); try
{
m_inprogress = true;
return buffer.Properties.GetOrCreateSingletonProperty<CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_type_registry, m_aggregator.GetClassifier(buffer), buffer.ContentType); });
}
finally { m_inprogress = false; }
} }
} }


class CppKeywordClassifier : IClassifier class CppKeywordClassifier : IClassifier
{ {
private IClassifier m_classifier;

private IClassificationType m_customclass_type; private IClassificationType m_customclass_type;
private Regex m_regex; private Regex m_customclass_regex;


internal CppKeywordClassifier(IClassificationTypeRegistryService registry, internal CppKeywordClassifier(IClassificationTypeRegistryService registry,
IClassifier classifier,
IContentType type) IContentType type)
{ {
m_classifier = classifier;

m_customclass_type = registry.GetClassificationType("LolCustomClass"); m_customclass_type = registry.GetClassificationType("LolCustomClass");


string tmp = @"\b("; string tmp = @"\b(";
@@ -56,21 +73,30 @@ namespace Lol.VisualStudio.Plugin
tmp += "u?int(8|16|32|64|ptr)_t|"; tmp += "u?int(8|16|32|64|ptr)_t|";
tmp += "real|half|explicit|typename|typedef|"; tmp += "real|half|explicit|typename|typedef|";
} }
tmp = tmp.Remove(tmp.Length - 1);
tmp += @")\b"; tmp += @")\b";
m_regex = new Regex(tmp); m_customclass_regex = new Regex(tmp);
} }


public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
{ {
List<ClassificationSpan> ret = new List<ClassificationSpan>(); List<ClassificationSpan> ret = new List<ClassificationSpan>();


string tmp = span.GetText(); foreach (ClassificationSpan cs in m_classifier.GetClassificationSpans(span))
var matches = m_regex.Matches(tmp);
foreach (Match m in matches)
{ {
Span newspan = new Span(span.Start.Position + m.Index, m.Length); string cs_class = cs.ClassificationType.Classification.ToLower();
SnapshotSpan newsnapshot = new SnapshotSpan(span.Snapshot, newspan); /* Only apply our rules if we found a keyword or an identifier */
ret.Add(new ClassificationSpan(newsnapshot, m_customclass_type)); if (cs_class == "keyword" || cs_class == "identifier")
{
if (m_customclass_regex.IsMatch(cs.Span.GetText()))
{
ret.Add(new ClassificationSpan(cs.Span, m_customclass_type));
continue;
}
}

ret.Add(cs);
} }


return ret; return ret;


+ 2
- 2
tools/vslol/Properties/AssemblyInfo.cs Ver fichero

@@ -20,5 +20,5 @@ using System.Runtime.InteropServices;
// The following GUID is for the ID of the typelib if this project is exposed to COM // The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("58968f91-edb8-4a4c-9f4f-ba39fdb4a21a")] [assembly: Guid("58968f91-edb8-4a4c-9f4f-ba39fdb4a21a")]


[assembly: AssemblyVersion("1.0.0.4")] [assembly: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.4")] [assembly: AssemblyFileVersion("1.0.0.5")]

+ 1
- 1
tools/vslol/source.extension.vsixmanifest Ver fichero

@@ -3,7 +3,7 @@
<Identifier Id="VsLol"> <Identifier Id="VsLol">
<Name>VsLol</Name> <Name>VsLol</Name>
<Author>Lol</Author> <Author>Lol</Author>
<Version>1.0.0.4</Version> <Version>1.0.0.5</Version>
<Description xml:space="preserve">Lol Engine Productivity Tools.</Description> <Description xml:space="preserve">Lol Engine Productivity Tools.</Description>
<Locale>1033</Locale> <Locale>1033</Locale>
<MoreInfoUrl>http://lol.zoy.org/</MoreInfoUrl> <MoreInfoUrl>http://lol.zoy.org/</MoreInfoUrl>


||||||
x
 
000:0
Cargando…
Cancelar
Guardar