protected void RunScript(string aCommandName, ClangTidyOptionsView mTidyOptions = null, ClangTidyChecksOptionsView mTidyChecks = null, ClangTidyCustomChecksOptionsView mTidyCustomChecks = null, ClangFormatOptionsView aClangFormatView = null) { try { mCompileTidyScriptBuilder = new ClangCompileTidyScript(); mCompileTidyScriptBuilder.ConstructParameters(mGeneralOptions, mTidyOptions, mTidyChecks, mTidyCustomChecks, aClangFormatView, DTEObj, VsEdition, VsVersion); string solutionPath = DTEObj.Solution.FullName; mOutputManager = new OutputManager(DTEObj); InitPowerShell(); ClearWindows(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kStart} {aCommandName}\n"); StatusBarHandler.Status(aCommandName + " started...", 1, vsStatusAnimation.vsStatusAnimationBuild, 1); foreach (var item in mItemsCollector.GetItems) { var script = mCompileTidyScriptBuilder.GetScript(item, solutionPath); if (!mCommandsController.Running) { break; } mOutputManager.Hierarchy = AutomationUtil.GetItemHierarchy(ServiceProvider, item); var process = mPowerShell.Invoke(script, mRunningProcesses); if (mOutputManager.MissingLlvm) { mOutputManager.AddMessage(ErrorParserConstants.kMissingLlvmMessage); break; } } if (!mOutputManager.EmptyBuffer) { mOutputManager.AddMessage(String.Join("\n", mOutputManager.Buffer)); } if (!mOutputManager.MissingLlvm) { mOutputManager.Show(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kDone} {aCommandName}\n"); } if (mOutputManager.HasErrors) { ErrorManager.Instance.AddErrors(mOutputManager.Errors); } } catch (Exception) { mOutputManager.Show(); mOutputManager.AddMessage($"\n{OutputWindowConstants.kDone} {aCommandName}\n"); } finally { StatusBarHandler.Status(aCommandName + " finished", 0, vsStatusAnimation.vsStatusAnimationBuild, 0); } }
/// <summary> /// Initializes a new instance of the <see cref="TidyCommand"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> private TidyCommand(OleMenuCommandService aCommandService, CommandsController aCommandsController, ErrorWindowController aErrorWindow, OutputWindowController aOutputWindow, AsyncPackage aPackage, Guid aGuid, int aId) : base(aCommandsController, aErrorWindow, aOutputWindow, aPackage, aGuid, aId) { mTidyOptions = (ClangTidyOptionsView)AsyncPackage.GetDialogPage(typeof(ClangTidyOptionsView)); mTidyChecks = (ClangTidyPredefinedChecksOptionsView)AsyncPackage.GetDialogPage(typeof(ClangTidyPredefinedChecksOptionsView)); mTidyCustomChecks = (ClangTidyCustomChecksOptionsView)AsyncPackage.GetDialogPage(typeof(ClangTidyCustomChecksOptionsView)); mClangFormatView = (ClangFormatOptionsView)AsyncPackage.GetDialogPage(typeof(ClangFormatOptionsView)); if (null != aCommandService) { var menuCommandID = new CommandID(CommandSet, Id); var menuCommand = new OleMenuCommand(RunClangTidy, menuCommandID); menuCommand.BeforeQueryStatus += mCommandsController.OnBeforeClangCommand; menuCommand.Enabled = true; aCommandService.AddCommand(menuCommand); } }
/// <summary> /// Initializes a new instance of the <see cref="TidyCommand"/> class. /// Adds our command handlers for menu (commands must exist in the command table file) /// </summary> /// <param name="package">Owner package, not null.</param> public TidyCommand(Package aPackage, Guid aGuid, int aId, CommandsController aCommandsController) : base(aCommandsController, aPackage, aGuid, aId) { mTidyOptions = (ClangTidyOptionsView)Package.GetDialogPage(typeof(ClangTidyOptionsView)); mTidyChecks = (ClangTidyPredefinedChecksOptionsView)Package.GetDialogPage(typeof(ClangTidyPredefinedChecksOptionsView)); mTidyCustomChecks = (ClangTidyCustomChecksOptionsView)Package.GetDialogPage(typeof(ClangTidyCustomChecksOptionsView)); mClangFormatView = (ClangFormatOptionsView)Package.GetDialogPage(typeof(ClangFormatOptionsView)); mFileOpener = new FileOpener(DTEObj); if (ServiceProvider.GetService(typeof(IMenuCommandService)) is OleMenuCommandService commandService) { var menuCommandID = new CommandID(CommandSet, Id); var menuCommand = new OleMenuCommand(this.RunClangTidy, menuCommandID); menuCommand.BeforeQueryStatus += mCommandsController.QueryCommandHandler; menuCommand.Enabled = true; commandService.AddCommand(menuCommand); } }
protected void RunScript(string aCommandName, ClangTidyOptionsView mTidyOptions = null, ClangTidyPredefinedChecksOptionsView mTidyChecks = null, ClangTidyCustomChecksOptionsView mTidyCustomChecks = null, ClangFormatOptionsView aClangFormatView = null, bool aTidyFixFlag = false) { try { var dte = VsServiceProvider.GetService(typeof(DTE)) as DTE2; dte.Solution.SaveAs(dte.Solution.FullName); IBuilder <string> runModeScriptBuilder = new RunModeScriptBuilder(); runModeScriptBuilder.Build(); var runModeParameters = runModeScriptBuilder.GetResult(); IBuilder <string> genericScriptBuilder = new GenericScriptBuilder(mGeneralOptions, mTidyOptions, mTidyChecks, mTidyCustomChecks, aClangFormatView, VsEdition, VsVersion, aTidyFixFlag); genericScriptBuilder.Build(); var genericParameters = genericScriptBuilder.GetResult(); string solutionPath = dte.Solution.FullName; InitPowerShell(); ClearWindows(); mOutputWindow.Write($"\n{OutputWindowConstants.kStart} {aCommandName}\n"); StatusBarHandler.Status(aCommandName + " started...", 1, vsStatusAnimation.vsStatusAnimationBuild, 1); VsServiceProvider.TryGetService(typeof(SVsSolution), out object vsSolutionService); var vsSolution = vsSolutionService as IVsSolution; foreach (var item in mItemsCollector.GetItems) { if (!mCommandsController.Running) { break; } IBuilder <string> itemRelatedScriptBuilder = new ItemRelatedScriptBuilder(item); itemRelatedScriptBuilder.Build(); var itemRelatedParameters = itemRelatedScriptBuilder.GetResult(); // From the first parameter is removed the last character which is mandatory "'" // and added to the end of the string to close the script var script = $"{runModeParameters.Remove(runModeParameters.Length - 1)} {itemRelatedParameters} {genericParameters}'"; if (null != vsSolution) { mOutputWindow.Hierarchy = AutomationUtil.GetItemHierarchy(vsSolution as IVsSolution, item); } var process = mPowerShell.Invoke(script, mRunningProcesses); if (mOutputWindow.MissingLlvm) { mOutputWindow.Write(ErrorParserConstants.kMissingLlvmMessage); break; } } if (!mOutputWindow.MissingLlvm) { mOutputWindow.Show(); mOutputWindow.Write($"\n{OutputWindowConstants.kDone} {aCommandName}\n"); } if (mOutputWindow.HasErrors) { mErrorWindow.AddErrors(mOutputWindow.Errors); } } catch (Exception) { mOutputWindow.Show(); mOutputWindow.Write($"\n{OutputWindowConstants.kDone} {aCommandName}\n"); } finally { StatusBarHandler.Status(aCommandName + " finished", 0, vsStatusAnimation.vsStatusAnimationBuild, 0); } }