using a naive regex for now.legacy
| @@ -0,0 +1,115 @@ | |||||
| using System; | |||||
| using System.Collections.Generic; | |||||
| using System.ComponentModel.Composition; | |||||
| using System.Windows.Media; | |||||
| using System.Text.RegularExpressions; | |||||
| using Microsoft.VisualStudio.Text; | |||||
| using Microsoft.VisualStudio.Text.Classification; | |||||
| using Microsoft.VisualStudio.Language.StandardClassification; | |||||
| using Microsoft.VisualStudio.Utilities; | |||||
| namespace Lol.VisualStudio.Plugin | |||||
| { | |||||
| [Export(typeof(IClassifierProvider))] | |||||
| [ContentType("c/c++")] | |||||
| [ContentType("csharp")] | |||||
| [ContentType("lolfx")] | |||||
| internal class LolClassifierProvider : IClassifierProvider | |||||
| { | |||||
| [Import] | |||||
| internal IClassificationTypeRegistryService m_class_registry = null; /* Set via MEF */ | |||||
| //[Import] | |||||
| //internal IClassificationFormatMapService m_lol = null; | |||||
| public IClassifier GetClassifier(ITextBuffer buffer) | |||||
| { | |||||
| //var test = m_lol.GetClassificationFormatMap("Text Editor"); | |||||
| //string[] foo = { "Comment", "Keyword", "C/C++ User Keywords", "Call Return", "HTML Comment" }; | |||||
| //foreach (var s in foo) | |||||
| //{ | |||||
| // var type = m_class_registry.GetClassificationType(s); | |||||
| // if (type == null) | |||||
| // continue; | |||||
| // var prop = test.GetExplicitTextProperties(type); | |||||
| // if (prop == null) | |||||
| // continue; | |||||
| // var c1 = prop.ForegroundBrush as SolidColorBrush; | |||||
| // var c2 = prop.BackgroundBrush as SolidColorBrush; | |||||
| // Logger.Info("[" + s + "]: " + c1.ToString() + " " + c2.ToString() + "\n"); | |||||
| //} | |||||
| return buffer.Properties.GetOrCreateSingletonProperty<CppKeywordClassifier>(delegate { return new CppKeywordClassifier(m_class_registry, buffer.ContentType); }); | |||||
| } | |||||
| } | |||||
| class CppKeywordClassifier : IClassifier | |||||
| { | |||||
| private IClassificationType m_customclass_type; | |||||
| private Regex m_regex; | |||||
| internal CppKeywordClassifier(IClassificationTypeRegistryService registry, | |||||
| IContentType type) | |||||
| { | |||||
| m_customclass_type = registry.GetClassificationType("LolCustomClass"); | |||||
| string tmp = @"\b("; | |||||
| tmp += "void|int|unsigned|char|short|long|float|double|"; | |||||
| tmp += "class|struct|template|const|static|volatile|inline|namespace|"; | |||||
| if (type.IsOfType("lolfx")) | |||||
| tmp += "attribute|varying|uniform|in|out|"; | |||||
| if (type.IsOfType("csharp")) | |||||
| tmp += "var|string|internal|sealed|public|private|"; | |||||
| if (!type.IsOfType("csharp")) | |||||
| tmp += "vec2|vec3|vec4|quat|mat2|mat3|mat4|"; | |||||
| if (type.IsOfType("c/c++")) | |||||
| tmp += "real|half|"; | |||||
| tmp += @")\b"; | |||||
| m_regex = new Regex(tmp); | |||||
| } | |||||
| public IList<ClassificationSpan> GetClassificationSpans(SnapshotSpan span) | |||||
| { | |||||
| List<ClassificationSpan> ret = new List<ClassificationSpan>(); | |||||
| string tmp = span.GetText(); | |||||
| var matches = m_regex.Matches(tmp); | |||||
| foreach (Match m in matches) | |||||
| { | |||||
| Span newspan = new Span(span.Start.Position + m.Index, m.Length); | |||||
| SnapshotSpan newsnapshot = new SnapshotSpan(span.Snapshot, newspan); | |||||
| ret.Add(new ClassificationSpan(newsnapshot, m_customclass_type)); | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| public event EventHandler<ClassificationChangedEventArgs> ClassificationChanged; | |||||
| } | |||||
| internal static class LolClassifierClassificationDefinition | |||||
| { | |||||
| [Export(typeof(ClassificationTypeDefinition))] | |||||
| [Name(LolCppTypeFormat.m_name)] | |||||
| internal static ClassificationTypeDefinition LolCustomClassType = null; | |||||
| } | |||||
| [Export(typeof(EditorFormatDefinition))] | |||||
| [ClassificationType(ClassificationTypeNames = LolCppTypeFormat.m_name)] | |||||
| [Name(LolCppTypeFormat.m_name)] | |||||
| [UserVisible(true)] | |||||
| [Order(After = Priority.Default)] /* Override the Visual Studio classifiers */ | |||||
| internal sealed class LolCppTypeFormat : ClassificationFormatDefinition | |||||
| { | |||||
| public const string m_name = "LolCustomClass"; | |||||
| public LolCppTypeFormat() | |||||
| { | |||||
| this.DisplayName = "C/C++ Types and Qualifiers"; | |||||
| //this.BackgroundColor = Colors.BlueViolet; | |||||
| this.ForegroundColor = Colors.Lime; | |||||
| this.IsBold = true; | |||||
| //this.TextDecorations = System.Windows.TextDecorations.Underline; | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -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.3")] | |||||
| [assembly: AssemblyFileVersion("1.0.0.3")] | |||||
| [assembly: AssemblyVersion("1.0.0.4")] | |||||
| [assembly: AssemblyFileVersion("1.0.0.4")] | |||||
| @@ -92,29 +92,42 @@ namespace Lol.VisualStudio.Plugin | |||||
| if (Microsoft.VisualStudio.ErrorHandler.Failed(m_window.GetPane(ref guidBuild, out m_pane))) | if (Microsoft.VisualStudio.ErrorHandler.Failed(m_window.GetPane(ref guidBuild, out m_pane))) | ||||
| m_pane = null; | m_pane = null; | ||||
| } | } | ||||
| if (m_pane != null) | |||||
| m_pane.Activate(); | |||||
| } | } | ||||
| public static void Clear() | public static void Clear() | ||||
| { | { | ||||
| OpenBuildPane(); | OpenBuildPane(); | ||||
| if (m_pane != null) | |||||
| if (m_pane == null) | |||||
| { | { | ||||
| m_pane.Activate(); | |||||
| m_pane.Clear(); | |||||
| m_backlog = ""; | |||||
| return; | |||||
| } | } | ||||
| m_pane.Clear(); | |||||
| } | } | ||||
| public static void Info(string s) | public static void Info(string s) | ||||
| { | { | ||||
| OpenBuildPane(); | OpenBuildPane(); | ||||
| if (m_pane != null) | |||||
| m_pane.OutputString(s); | |||||
| if (m_pane == null) | |||||
| { | |||||
| m_backlog += s; | |||||
| return; | |||||
| } | |||||
| m_pane.OutputString(m_backlog); | |||||
| m_backlog = ""; | |||||
| m_pane.OutputString(s); | |||||
| } | } | ||||
| private static IVsOutputWindow m_window = null; | private static IVsOutputWindow m_window = null; | ||||
| private static IVsOutputWindowPane m_pane = null; | private static IVsOutputWindowPane m_pane = null; | ||||
| private static string m_backlog = ""; | |||||
| } | } | ||||
| internal static class GuidsList | internal static class GuidsList | ||||
| @@ -54,27 +54,38 @@ | |||||
| <HintPath>..\..\..\..\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\PublicAssemblies\envdte.dll</HintPath> | <HintPath>..\..\..\..\Program Files (x86)\Common Files\Microsoft Shared\MSEnv\PublicAssemblies\envdte.dll</HintPath> | ||||
| </Reference> | </Reference> | ||||
| <Reference Include="Microsoft.CSharp" /> | <Reference Include="Microsoft.CSharp" /> | ||||
| <Reference Include="Microsoft.VisualStudio.ComponentModelHost, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="Microsoft.VisualStudio.CoreUtility, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="Microsoft.VisualStudio.Language.StandardClassification, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="Microsoft.VisualStudio.OLE.Interop" /> | <Reference Include="Microsoft.VisualStudio.OLE.Interop" /> | ||||
| <Reference Include="Microsoft.VisualStudio.Package.LanguageService.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | <Reference Include="Microsoft.VisualStudio.Package.LanguageService.10.0, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | ||||
| <Reference Include="Microsoft.VisualStudio.Shell.Interop" /> | <Reference Include="Microsoft.VisualStudio.Shell.Interop" /> | ||||
| <Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0" /> | <Reference Include="Microsoft.VisualStudio.Shell.Interop.8.0" /> | ||||
| <Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0" /> | <Reference Include="Microsoft.VisualStudio.Shell.Interop.9.0" /> | ||||
| <Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0" /> | <Reference Include="Microsoft.VisualStudio.Shell.Interop.10.0" /> | ||||
| <Reference Include="Microsoft.VisualStudio.Text.Data, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="Microsoft.VisualStudio.Text.Logic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="Microsoft.VisualStudio.Text.UI, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="Microsoft.VisualStudio.Text.UI.Wpf, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> | |||||
| <Reference Include="Microsoft.VisualStudio.TextManager.Interop" /> | <Reference Include="Microsoft.VisualStudio.TextManager.Interop" /> | ||||
| <Reference Include="Microsoft.VisualStudio.Shell.10.0"> | <Reference Include="Microsoft.VisualStudio.Shell.10.0"> | ||||
| <Private>false</Private> | <Private>false</Private> | ||||
| </Reference> | </Reference> | ||||
| <Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0" /> | <Reference Include="Microsoft.VisualStudio.Shell.Immutable.10.0" /> | ||||
| <Reference Include="Microsoft.VisualStudio.TextManager.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> | <Reference Include="Microsoft.VisualStudio.TextManager.Interop.8.0, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" /> | ||||
| <Reference Include="PresentationCore" /> | |||||
| <Reference Include="System" /> | <Reference Include="System" /> | ||||
| <Reference Include="System.ComponentModel.Composition" /> | |||||
| <Reference Include="System.Core" /> | <Reference Include="System.Core" /> | ||||
| <Reference Include="System.Data" /> | <Reference Include="System.Data" /> | ||||
| <Reference Include="System.Design" /> | <Reference Include="System.Design" /> | ||||
| <Reference Include="System.Drawing" /> | <Reference Include="System.Drawing" /> | ||||
| <Reference Include="System.Windows.Forms" /> | <Reference Include="System.Windows.Forms" /> | ||||
| <Reference Include="System.Xml" /> | <Reference Include="System.Xml" /> | ||||
| <Reference Include="WindowsBase" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <Compile Include="CppKeywordClassifier.cs" /> | |||||
| <Compile Include="LolFxLanguageService.cs" /> | <Compile Include="LolFxLanguageService.cs" /> | ||||
| <Compile Include="MenuGenerateCompilers.cs" /> | <Compile Include="MenuGenerateCompilers.cs" /> | ||||
| <Compile Include="GlobalSuppressions.cs" /> | <Compile Include="GlobalSuppressions.cs" /> | ||||
| @@ -84,7 +95,7 @@ | |||||
| <DependentUpon>VsLol.resx</DependentUpon> | <DependentUpon>VsLol.resx</DependentUpon> | ||||
| </Compile> | </Compile> | ||||
| <Compile Include="VsLol.cs" /> | <Compile Include="VsLol.cs" /> | ||||
| <Compile Include="AssemblyInfo.cs" /> | |||||
| <Compile Include="Properties\AssemblyInfo.cs" /> | |||||
| </ItemGroup> | </ItemGroup> | ||||
| <ItemGroup> | <ItemGroup> | ||||
| <VSCTCompile Include="VsLol.vsct"> | <VSCTCompile Include="VsLol.vsct"> | ||||
| @@ -3,7 +3,7 @@ | |||||
| <Identifier Id="VsLol.Sample"> | <Identifier Id="VsLol.Sample"> | ||||
| <Name>VsLol</Name> | <Name>VsLol</Name> | ||||
| <Author>Lol</Author> | <Author>Lol</Author> | ||||
| <Version>1.0.0.3</Version> | |||||
| <Version>1.0.0.4</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> | ||||
| @@ -21,5 +21,6 @@ | |||||
| <References /> | <References /> | ||||
| <Content> | <Content> | ||||
| <VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage> | <VsPackage>|%CurrentProject%;PkgdefProjectOutputGroup|</VsPackage> | ||||
| <MefComponent>|%CurrentProject%|</MefComponent> | |||||
| </Content> | </Content> | ||||
| </Vsix> | </Vsix> | ||||