source: trunk/tools/vslol/VsLol.cs @ 2118

Last change on this file since 2118 was 2118, checked in by sam, 11 years ago

vslol: add the skeleton for a real LolFx syntax highlighter.

File size: 5.1 KB
Line 
1using System;
2using System.ComponentModel.Design;
3using System.Diagnostics;
4using System.Globalization;
5using System.Runtime.InteropServices;
6using System.Security.Permissions;
7using System.Text;
8using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
9using Microsoft.VisualStudio.Shell;
10using Microsoft.VisualStudio.Shell.Interop;
11
12namespace Lol.VisualStudio.Plugin
13{
14    [PackageRegistration(UseManagedResourcesOnly = true)]
15
16    /* LolFx syntax highlighting */
17    [ProvideServiceAttribute(typeof(LolFxLanguageService),
18                             ServiceName = "LolFx Service")]
19    [ProvideLanguageServiceAttribute(typeof(LolFxLanguageService),
20                                     "LolFx", 106 /* resource ID */,
21                                     CodeSense = true,
22                                     RequestStockColors = true,
23                                     EnableCommenting = true,
24                                     EnableAsyncCompletion = true)]
25    [ProvideLanguageExtensionAttribute(typeof(LolFxLanguageService),
26                                       ".lolfx")]
27
28    [ProvideMenuResource(1000, 1)]
29    [Guid("f96f7ac5-16ac-4061-8b92-0a02bb455ae9")]
30    [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
31    [ComVisible(true)]
32
33    /* Autoload package */
34    [ProvideAutoLoad("f1536ef8-92ec-443c-9ed7-fdadf150da82")]
35
36    public sealed class PluginPackage : Package
37    {
38        public PluginPackage()
39        {
40            Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering constructor for: {0}", this.ToString()));
41        }
42
43        [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
44        protected override void Initialize()
45        {
46            // Trace the beginning of this method and call the base implementation.
47            Trace.WriteLine(String.Format(CultureInfo.CurrentUICulture, "Entering Initialize() of: {0}", this.ToString()));
48            base.Initialize();
49
50            Logger.Initialize(GetService(typeof(SVsOutputWindow)) as IVsOutputWindow);
51
52            /* Register the "Generate Compilers" context menu */
53            OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
54            if (null != mcs)
55            {
56                CommandID id = new CommandID(GuidsList.guidVsLolCmdSet,
57                                             VsLolIDList.cmdidGenerateCompilers);
58                OleMenuCommand command = new MenuGenerateCompilers(new ServiceProvider((IOleServiceProvider)this.GetService(typeof(IOleServiceProvider))), id);
59                mcs.AddCommand(command);
60            }
61
62            /* Register the LolFx language service */
63            IServiceContainer serviceContainer = this as IServiceContainer;
64            LolFxLanguageService lolfxserv = new LolFxLanguageService();
65            lolfxserv.SetSite(this);
66            serviceContainer.AddService(typeof(LolFxLanguageService),
67                                        lolfxserv, true);
68        }
69
70    }
71
72    internal static class Logger
73    {
74        public static void Initialize(IVsOutputWindow window)
75        {
76            m_window = window;
77
78            OpenBuildPane();
79
80            if (m_pane == null)
81                Trace.WriteLine("Failed to get a reference to the Output window Build pane");
82        }
83
84        private static void OpenBuildPane()
85        {
86            /* Ensure the "Build" output pane exists */
87            if (m_window != null)
88            {
89                Guid guidBuild = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid;
90                m_window.CreatePane(guidBuild, "Build", 1, 0);
91
92                if (Microsoft.VisualStudio.ErrorHandler.Failed(m_window.GetPane(ref guidBuild, out m_pane)))
93                    m_pane = null;
94            }
95        }
96
97        public static void Clear()
98        {
99            OpenBuildPane();
100
101            if (m_pane != null)
102            {
103                m_pane.Activate();
104                m_pane.Clear();
105            }
106        }
107
108        public static void Info(string s)
109        {
110            OpenBuildPane();
111
112            if (m_pane != null)
113                m_pane.OutputString(s);
114        }
115
116        private static IVsOutputWindow m_window = null;
117        private static IVsOutputWindowPane m_pane = null;
118    }
119
120    internal static class GuidsList
121    {
122        // Now define the list of guids as public static members.
123        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
124        public static readonly Guid guidVsLolPkg = new Guid("{f96f7ac5-16ac-4061-8b92-0a02bb455ae9}");
125
126        public static readonly Guid guidVsLolCmdSet = new Guid("{ce508d12-530e-45d0-8b52-1e9ee3f8eaaf}");
127
128        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
129        public static readonly Guid guidGearBmp = new Guid("{560dba06-c26b-4731-8229-b816818e5992}");
130    }
131
132    internal static class VsLolIDList
133    {
134        public const int cmdidGenerateCompilers = 0x2001;
135        public const int cmdidUnused1 = 0x2002;
136        public const int cmdidUnused2 = 0x2003;
137    }
138}
Note: See TracBrowser for help on using the repository browser.