Ejemplo n.º 1
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void RunClangTidy(object sender, EventArgs e)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;
            mFix = SetTidyFixParameter(sender);

            var task = System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    DocumentsHandler.SaveActiveDocuments();

                    if (!VsServiceProvider.TryGetService(typeof(DTE), out object dte))
                    {
                        return;
                    }

                    var dte2 = dte as DTE2;
                    AutomationUtil.SaveDirtyProjects(dte2.Solution);

                    CollectSelectedItems(false, ScriptConstants.kAcceptedFileExtensions);

                    using (var silentFileController = new SilentFileChangerController())
                    {
                        using (var fileChangerWatcher = new FileChangerWatcher())
                        {
                            if (mFix || mTidyOptions.AutoTidyOnSave)
                            {
                                fileChangerWatcher.OnChanged += FileOpener.Open;

                                string solutionFolderPath = dte2.Solution.FullName
                                                            .Substring(0, dte2.Solution.FullName.LastIndexOf('\\'));

                                fileChangerWatcher.Run(solutionFolderPath);

                                FilePathCollector fileCollector = new FilePathCollector();
                                var filesPath = fileCollector.Collect(mItemsCollector.GetItems).ToList();

                                silentFileController.SilentFiles(filesPath);
                                silentFileController.SilentFiles(dte2.Documents);
                            }
                            RunScript(OutputWindowConstants.kTidyCodeCommand, mTidyOptions, mTidyChecks, mTidyCustomChecks, mClangFormatView, mFix);
                        }
                    }
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
                finally
                {
                    mForceTidyToFix = false;
                }
            }).ContinueWith(tsk => mCommandsController.OnAfterClangCommand());
        }
Ejemplo n.º 2
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void MenuItemCallback(object sender, EventArgs e)
 {
     mCommandsController.Running = true;
     var task = System.Threading.Tasks.Task.Run(() =>
     {
         try
         {
             AutomationUtil.SaveAllProjects(Package, DTEObj.Solution);
             CollectSelectedItems();
             mFileWatcher = new FileChangerWatcher();
             using (var guard = new SilentFileChangerGuard())
             {
                 if (mTidyOptions.Fix)
                 {
                     WatchFiles();
                     SilentFiles(guard);
                 }
                 RunScript(OutputWindowConstants.kTidyCodeCommand, mTidyOptions, mTidyChecks, mTidyCustomChecks);
             }
         }
         catch (Exception exception)
         {
             VsShellUtilities.ShowMessageBox(Package, exception.Message, "Error",
                                             OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
         }
     }).ContinueWith(tsk => mCommandsController.AfterExecute());;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void RunClangCompile(object sender, EventArgs e)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;
            var task = System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    DocumentsHandler.SaveActiveDocuments((DTE)DTEObj);
                    AutomationUtil.SaveDirtyProjects(ServiceProvider, DTEObj.Solution);

                    CollectSelectedItems(ScriptConstants.kAcceptedFileExtensions);
                    RunScript(OutputWindowConstants.kComplileCommand);
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(Package, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }).ContinueWith(tsk => mCommandsController.AfterExecute());
        }
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private async void RunClangCompile(object sender, EventArgs e)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;

            await System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    if (VsServiceProvider.TryGetService(typeof(DTE), out object dte))
                    {
                        DocumentsHandler.SaveActiveDocuments();
                        AutomationUtil.SaveDirtyProjects((dte as DTE2).Solution);
                    }

                    CollectSelectedItems(ScriptConstants.kAcceptedFileExtensions);
                    RunScript(OutputWindowConstants.kComplileCommand);
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            });

            mCommandsController.OnAfterClangCommand();
        }
Ejemplo n.º 5
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);
            }
        }
        private void GetProjectItem(Solution aSolution)
        {
            foreach (var item in AutomationUtil.GetAllProjects(aSolution))
            {
                var project = (item as SelectedProject).GetObject() as Project;
                if (project == null)
                {
                    continue;
                }

                GetProjectItem(project);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// This function is the callback used to execute the command when the menu item is clicked.
        /// See the constructor to see how the menu item is associated with this function using
        /// OleMenuCommandService service and MenuCommand class.
        /// </summary>
        /// <param name="sender">Event sender.</param>
        /// <param name="e">Event args.</param>
        private void RunClangTidy(object sender, EventArgs e)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;
            System.Threading.Tasks.Task.Run(() =>
            {
                try
                {
                    DocumentsHandler.SaveActiveDocuments((DTE)DTEObj);
                    AutomationUtil.SaveDirtyProjects(DTEObj.Solution);

                    CollectSelectedItems(ScriptConstants.kAcceptedFileExtensions);

                    mFileWatcher             = new FileChangerWatcher();
                    mFileOpener              = new FileOpener(DTEObj);
                    var silentFileController = new SilentFileController();

                    using (var guard = silentFileController.GetSilentFileChangerGuard())
                    {
                        if (true == mTidyOptions.Fix || true == mTidyOptions.AutoTidyOnSave)
                        {
                            WatchFiles();

                            FilePathCollector fileCollector = new FilePathCollector();
                            var filesPath = fileCollector.Collect(mItemsCollector.GetItems).ToList();

                            silentFileController.SilentFiles(AsyncPackage, guard, filesPath);
                            silentFileController.SilentOpenFiles(AsyncPackage, guard, DTEObj);
                        }
                        RunScript(OutputWindowConstants.kTidyCodeCommand, mTidyOptions, mTidyChecks, mTidyCustomChecks, mClangFormatView);
                    }
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
                finally
                {
                    mForceTidyToFix = false;
                }
            }).ContinueWith(tsk => mCommandsController.AfterExecute());
        }
Ejemplo n.º 8
0
 /// <summary>
 /// This function is the callback used to execute the command when the menu item is clicked.
 /// See the constructor to see how the menu item is associated with this function using
 /// OleMenuCommandService service and MenuCommand class.
 /// </summary>
 /// <param name="sender">Event sender.</param>
 /// <param name="e">Event args.</param>
 private void MenuItemCallback(object sender, EventArgs e)
 {
     mCommandsController.Running = true;
     var task = System.Threading.Tasks.Task.Run(() =>
     {
         try
         {
             AutomationUtil.SaveAllProjects(Package, DTEObj.Solution);
             CollectSelectedItems();
             RunScript(OutputWindowConstants.kComplileCommand);
         }
         catch (Exception exception)
         {
             VsShellUtilities.ShowMessageBox(Package, exception.Message, "Error",
                                             OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
         }
     }).ContinueWith(tsk => mCommandsController.AfterExecute());
 }
 private void GetProjectsFromSolution(Solution aSolution)
 {
     items = AutomationUtil.GetAllProjects(aSolution);
 }
Ejemplo n.º 10
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);
            }
        }
Ejemplo n.º 11
0
 private void GetProjectsFromSolution(Solution aSolution)
 {
     mItems = AutomationUtil.GetAllProjects(mServiceProvider, aSolution);
 }