Selaa lähdekoodia

vslol: new feature: disable syntax highlighting for Microsoft "extensions"

that aren't exactly extensions and perfectly valid C++ identifiers.
legacy
Sam Hocevar sam 12 vuotta sitten
vanhempi
commit
37129661ea
3 muutettua tiedostoa jossa 67 lisäystä ja 21 poistoa
  1. +64
    -18
      tools/vslol/CppKeywordClassifier.cs
  2. +2
    -2
      tools/vslol/Properties/AssemblyInfo.cs
  3. +1
    -1
      tools/vslol/source.extension.vsixmanifest

+ 64
- 18
tools/vslol/CppKeywordClassifier.cs Näytä tiedosto

@@ -60,8 +60,8 @@ class CppKeywordClassifier : IClassifier
{
private IClassifier m_classifier;

private IClassificationType m_types_type, m_constant_type;
private Regex m_types_regex, m_constant_regex;
private IClassificationType m_types_type, m_constant_type, m_normal_type;
private Regex m_types_regex, m_constant_regex, m_normal_regex;

private static string[] m_all_types =
{
@@ -121,37 +121,55 @@ class CppKeywordClassifier : IClassifier
"gl_Position|gl_FragColor",
};

private static string[] m_all_normal =
{
};

private static string[] m_cpp_normal =
{
"interface|delegate|event|finally",
"gcnew|generic|initonly|property|sealed",
};

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

/* Regex for types and specifiers */
m_types_type = registry.GetClassificationType("LolAnyType");

List<string> types_list = m_all_types.ToList();
if (type.IsOfType("c/c++"))
types_list = types_list.Concat(m_cpp_types).ToList();
if (type.IsOfType("csharp"))
types_list = types_list.Concat(m_csharp_types).ToList();
if (type.IsOfType("lolfx"))
types_list = types_list.Concat(m_lolfx_types).ToList();
m_types_regex =
new Regex(@"\b(" + String.Join("|", types_list.ToArray()) + @")\b");

/* Regex for constant words */
m_normal_type = registry.GetClassificationType("LolAnyIdentifier");
m_constant_type = registry.GetClassificationType("LolAnyConstant");

List<string> types_list = m_all_types.ToList();
List<string> constants_list = m_all_constants.ToList();
List<string> normals_list = m_all_normal.ToList();

if (type.IsOfType("c/c++"))
{
types_list = types_list.Concat(m_cpp_types).ToList();
constants_list = constants_list.Concat(m_cpp_constants).ToList();
normals_list = normals_list.Concat(m_cpp_normal).ToList();
}

if (type.IsOfType("csharp"))
{
types_list = types_list.Concat(m_csharp_types).ToList();
constants_list = constants_list.Concat(m_csharp_constants).ToList();
}

if (type.IsOfType("lolfx"))
{
types_list = types_list.Concat(m_lolfx_types).ToList();
constants_list = constants_list.Concat(m_lolfx_constants).ToList();
}

m_types_regex =
new Regex("^(" + String.Join("|", types_list.ToArray()) + ")$");
m_constant_regex =
new Regex(@"\b(" + String.Join("|", constants_list.ToArray()) + @")\b");
new Regex("^(" + String.Join("|", constants_list.ToArray()) + ")$");
m_normal_regex =
new Regex("^(" + String.Join("|", normals_list.ToArray()) + ")$");
}

public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span)
@@ -176,6 +194,12 @@ class CppKeywordClassifier : IClassifier
ret.Add(new ClassificationSpan(cs.Span, m_constant_type));
continue;
}

if (m_normal_regex.IsMatch(cs.Span.GetText()))
{
ret.Add(new ClassificationSpan(cs.Span, m_normal_type));
continue;
}
}

ret.Add(cs);
@@ -242,6 +266,10 @@ internal static class LolClassifierClassificationDefinition
[Export(typeof(ClassificationTypeDefinition))]
[Name(LolCppConstantFormat.m_name)]
internal static ClassificationTypeDefinition LolCustomConstantType = null;

[Export(typeof(ClassificationTypeDefinition))]
[Name(LolCppIdentifierFormat.m_name)]
internal static ClassificationTypeDefinition LolCustomIdentifierType = null;
}

[Export(typeof(EditorFormatDefinition))]
@@ -254,7 +282,7 @@ internal sealed class LolCppTypeFormat : LolGenericFormat
public const string m_name = "LolAnyType";
public LolCppTypeFormat()
{
this.DisplayName = "C/C++ Types and Qualifiers";
this.DisplayName = "C/C++ Types and Qualifiers (VsLol)";
this.ForegroundColor = Colors.Lime;
this.ForegroundOpacity = 1.0;
this.IsBold = true;
@@ -272,7 +300,7 @@ internal sealed class LolCppConstantFormat : LolGenericFormat
public const string m_name = "LolAnyConstant";
public LolCppConstantFormat()
{
this.DisplayName = "C/C++ Constants";
this.DisplayName = "C/C++ Constants (VsLol)";
this.ForegroundColor = Colors.Magenta;
this.ForegroundOpacity = 1.0;
this.IsBold = true;
@@ -280,4 +308,22 @@ internal sealed class LolCppConstantFormat : LolGenericFormat
}
}

[Export(typeof(EditorFormatDefinition))]
[ClassificationType(ClassificationTypeNames = LolCppIdentifierFormat.m_name)]
[Name(LolCppIdentifierFormat.m_name)]
[UserVisible(true)]
[Order(After = Priority.Default)] /* Override the Visual Studio classifiers */
internal sealed class LolCppIdentifierFormat : LolGenericFormat
{
public const string m_name = "LolAnyIdentifier";
public LolCppIdentifierFormat()
{
this.DisplayName = "C/C++ Identifiers (VsLol)";
this.ForegroundColor = Colors.Silver;
this.ForegroundOpacity = 1.0;
this.IsBold = false;
CopyStyleColor(PredefinedClassificationTypeNames.Identifier);
}
}

} /* namespace lol */

+ 2
- 2
tools/vslol/Properties/AssemblyInfo.cs Näytä tiedosto

@@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
// 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: AssemblyVersion("1.0.0.5")]
[assembly: AssemblyFileVersion("1.0.0.5")]
[assembly: AssemblyVersion("1.0.0.6")]
[assembly: AssemblyFileVersion("1.0.0.6")]

+ 1
- 1
tools/vslol/source.extension.vsixmanifest Näytä tiedosto

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


Ladataan…
Peruuta
Tallenna