Exemplo n.º 1
0
        protected void RunScript(string aCommandName, ClangTidyOptionsView mTidyOptions = null,
                                 ClangTidyPredefinedChecksOptionsView 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);
            }
        }
Exemplo n.º 2
0
        public int OnAfterOpenSolution(object aPUnkReserved, int aFNewSolution)
        {
            try
            {
                mCommandsController = new CommandsController(this, mDte);

                InitializeCommands();

                StatusBarHandler.Initialize(this);
                ErrorManager.Initialize(this);

                var generalOptions = (ClangGeneralOptionsView)this.GetDialogPage(typeof(ClangGeneralOptionsView));
                var currentVersion = GetPackageVersion();

                if (0 != string.Compare(generalOptions.Version, currentVersion))
                {
                    OutputManager outputManager = new OutputManager(mDte);
                    outputManager.Show();
                    outputManager.AddMessage($"🎉\tClang Power Tools was upgraded to v{currentVersion}\n" +
                                             $"\tCheck out what's new at http://www.clangpowertools.com/CHANGELOG");

                    generalOptions.Version = currentVersion;
                    generalOptions.SaveSettingsToStorage();
                }

                mBuildEvents.OnBuildBegin += ErrorManager.Instance.OnBuildBegin;

                mBuildEvents.OnBuildBegin += mCommandsController.OnBuildBegin;
                mBuildEvents.OnBuildDone  += mCommandsController.OnBuildDone;

                mBuildEvents.OnBuildDone += mCompileCmd.OnBuildDone;

                mCommandEvents.BeforeExecute += mCompileCmd.CommandEventsBeforeExecute;
                mCommandEvents.BeforeExecute += mTidyCmd.CommandEventsBeforeExecute;

                mRunningDocTableEvents.BeforeSave += mTidyCmd.OnBeforeSave;
                mRunningDocTableEvents.BeforeSave += mClangFormatCmd.OnBeforeSave;
            }
            catch (Exception)
            {
            }

            return(VSConstants.S_OK);
        }
Exemplo n.º 3
0
        protected void RunScript(int aCommandId)
        {
            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(VsEdition, VsVersion, aCommandId);
                genericScriptBuilder.Build();
                var genericParameters = genericScriptBuilder.GetResult();

                string solutionPath = dte.Solution.FullName;

                InitPowerShell();
                ClearWindows();
                mOutputWindow.Write($"\n{OutputWindowConstants.kStart} {OutputWindowConstants.kCommandsNames[aCommandId]}\n");

                StatusBarHandler.Status(OutputWindowConstants.kCommandsNames[aCommandId] + " 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} {OutputWindowConstants.kCommandsNames[aCommandId]}\n");
                }

                if (mOutputWindow.HasErrors)
                {
                    mErrorWindow.AddErrors(mOutputWindow.Errors);
                }
            }
            catch (Exception)
            {
                mOutputWindow.Show();
                mOutputWindow.Write($"\n{OutputWindowConstants.kDone} {OutputWindowConstants.kCommandsNames[aCommandId]}\n");
            }
            finally
            {
                StatusBarHandler.Status(OutputWindowConstants.kCommandsNames[aCommandId] + " finished", 0, vsStatusAnimation.vsStatusAnimationBuild, 0);
            }
        }
 private void DisplayStoppedMessage(bool clearOutput)
 {
     OnClangCommandMessageTransfer(new ClangCommandMessageEventArgs($"\n--- {OutputWindowConstants.commandName[currentCommand].ToUpper()} STOPPED ---", clearOutput));
     StatusBarHandler.Status("Command stopped", 0, vsStatusAnimation.vsStatusAnimationBuild, 0);
 }
 private void DisplayFinishedMessage(bool clearOutput)
 {
     OnClangCommandMessageTransfer(new ClangCommandMessageEventArgs($"\n--- {OutputWindowConstants.commandName[currentCommand].ToUpper()} FINISHED ---\n", clearOutput));
     StatusBarHandler.Status(OutputWindowConstants.commandName[currentCommand] + " finished", 0, vsStatusAnimation.vsStatusAnimationBuild, 0);
 }
 private void DisplayNoActiveDocumentMessage(bool clearOutput)
 {
     OnClangCommandMessageTransfer(new ClangCommandMessageEventArgs($"\nToolbar Clang commands can only run on open files. Open a file or use the context menu commands by right-clicking in the Solution Explorer.\n", clearOutput));
     StatusBarHandler.Status("Ready", 0, vsStatusAnimation.vsStatusAnimationBuild, 0);
 }
 private void DisplayStartedMessage(int aCommandId, bool clearOutput)
 {
     OnClangCommandMessageTransfer(new ClangCommandMessageEventArgs($"\n--- {OutputWindowConstants.commandName[aCommandId].ToUpper()} STARTED ---\n", clearOutput));
     StatusBarHandler.Status(OutputWindowConstants.commandName[aCommandId] + " started...", 1, vsStatusAnimation.vsStatusAnimationBuild, 1);
 }
Exemplo n.º 8
0
 private void DisplayCannotFormatMessage(bool clearOutput, string message)
 {
     OnClangCommandMessageTransfer(new ClangCommandMessageEventArgs(message, clearOutput));
     StatusBarHandler.Status("Command stopped", 0, vsStatusAnimation.vsStatusAnimationBuild, 0);
 }
 private void DisplayCannotFormatMessage(bool clearOutput)
 {
     OnClangCommandMessageTransfer(new ClangCommandMessageEventArgs($"\n--- ERROR ---\nFormat config file not found.\nCreate the config file and place it the solution folder or select one of the predefined format styles from Settings.", clearOutput));
     StatusBarHandler.Status("Command stopped", 0, vsStatusAnimation.vsStatusAnimationBuild, 0);
 }