You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

163 regels
5.3 KiB

  1. //
  2. // Lol Engine - VsLol add-in for Visual Studio
  3. //
  4. // Copyright: (c) 2010-2012 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://www.wtfpl.net/ for more details.
  9. //
  10. using System;
  11. using System.ComponentModel.Design;
  12. using System.Diagnostics;
  13. using System.Globalization;
  14. using System.Runtime.InteropServices;
  15. using System.Security.Permissions;
  16. using System.Text;
  17. using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
  18. using Microsoft.VisualStudio.Shell;
  19. using Microsoft.VisualStudio.Shell.Interop;
  20. namespace lol
  21. {
  22. [PackageRegistration(UseManagedResourcesOnly = true)]
  23. /* LolFx syntax highlighting */
  24. [ProvideServiceAttribute(typeof(LolFxLanguageService),
  25. ServiceName = "LolFx Service")]
  26. [ProvideLanguageServiceAttribute(typeof(LolFxLanguageService),
  27. "LolFx", 106 /* resource ID */,
  28. CodeSense = true,
  29. RequestStockColors = true,
  30. EnableCommenting = true,
  31. EnableAsyncCompletion = true)]
  32. [ProvideLanguageExtensionAttribute(typeof(LolFxLanguageService),
  33. ".lolfx")]
  34. [ProvideMenuResource(1000, 1)]
  35. [Guid("f96f7ac5-16ac-4061-8b92-0a02bb455ae9")]
  36. [InstalledProductRegistration("#110", "#112", "1.0", IconResourceID = 400)]
  37. [ComVisible(true)]
  38. /* Autoload package */
  39. [ProvideAutoLoad("f1536ef8-92ec-443c-9ed7-fdadf150da82")]
  40. public sealed class PluginPackage : Package
  41. {
  42. public PluginPackage()
  43. {
  44. Trace.WriteLine(String.Format("Entering constructor for: {0}", this.ToString()));
  45. }
  46. [SecurityPermission(SecurityAction.Demand, Flags=SecurityPermissionFlag.UnmanagedCode)]
  47. protected override void Initialize()
  48. {
  49. // Trace the beginning of this method and call the base implementation.
  50. Trace.WriteLine(String.Format("Entering Initialize() of: {0}", this.ToString()));
  51. base.Initialize();
  52. Logger.Initialize(GetService(typeof(SVsOutputWindow)) as IVsOutputWindow);
  53. /* Register the "Generate Compilers" context menu */
  54. OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;
  55. if (null != mcs)
  56. {
  57. CommandID id = new CommandID(GuidsList.guidVsLolCmdSet,
  58. VsLolIDList.cmdidGenerateCompilers);
  59. OleMenuCommand command = new MenuGenerateCompilers(new ServiceProvider((IOleServiceProvider)this.GetService(typeof(IOleServiceProvider))), id);
  60. mcs.AddCommand(command);
  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. internal static class Logger
  71. {
  72. public static void Initialize(IVsOutputWindow window)
  73. {
  74. m_window = window;
  75. OpenBuildPane();
  76. if (m_pane == null)
  77. Trace.WriteLine("Failed to get a reference to the Output window Build pane");
  78. }
  79. private static void OpenBuildPane()
  80. {
  81. /* Ensure the "Build" output pane exists */
  82. if (m_window != null)
  83. {
  84. Guid guidBuild = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid;
  85. m_window.CreatePane(guidBuild, "Build", 1, 0);
  86. if (Microsoft.VisualStudio.ErrorHandler.Failed(m_window.GetPane(ref guidBuild, out m_pane)))
  87. m_pane = null;
  88. }
  89. if (m_pane != null)
  90. m_pane.Activate();
  91. }
  92. public static void Clear()
  93. {
  94. OpenBuildPane();
  95. if (m_pane == null)
  96. {
  97. m_backlog = "";
  98. return;
  99. }
  100. m_pane.Clear();
  101. }
  102. public static void Info(string s)
  103. {
  104. OpenBuildPane();
  105. if (m_pane == null)
  106. {
  107. m_backlog += s;
  108. return;
  109. }
  110. m_pane.OutputString(m_backlog);
  111. m_backlog = "";
  112. m_pane.OutputString(s);
  113. }
  114. private static IVsOutputWindow m_window = null;
  115. private static IVsOutputWindowPane m_pane = null;
  116. private static string m_backlog = "";
  117. }
  118. internal static class GuidsList
  119. {
  120. // Now define the list of guids as public static members.
  121. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  122. public static readonly Guid guidVsLolPkg = new Guid("{f96f7ac5-16ac-4061-8b92-0a02bb455ae9}");
  123. public static readonly Guid guidVsLolCmdSet = new Guid("{ce508d12-530e-45d0-8b52-1e9ee3f8eaaf}");
  124. [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  125. public static readonly Guid guidGearBmp = new Guid("{560dba06-c26b-4731-8229-b816818e5992}");
  126. }
  127. internal static class VsLolIDList
  128. {
  129. public const int cmdidGenerateCompilers = 0x2001;
  130. public const int cmdidUnused1 = 0x2002;
  131. public const int cmdidUnused2 = 0x2003;
  132. }
  133. } /* namespace lol */