/// <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()); }
private void WatchFiles() { mFileWatcher.OnChanged += mFileOpener.FileChanged; string solutionFolderPath = mDte.Solution.FullName .Substring(0, mDte.Solution.FullName.LastIndexOf('\\')); mFileWatcher.Run(solutionFolderPath); }
private void WatchFiles() { try { mFileWatcher.OnChanged += mFileOpener.FileChanged; string solutionFolderPath = DTEObj.Solution.FullName .Substring(0, DTEObj.Solution.FullName.LastIndexOf('\\')); mFileWatcher.Run(solutionFolderPath); } catch (Exception) { } }