Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

152 righe
5.4 KiB

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