예제 #1
0
        public async Task RunClangTidyAsync(int aCommandId, CommandUILocation commandUILocation, Document document = null)
        {
            await PrepareCommmandAsync(commandUILocation);

            await Task.Run(() =>
            {
                lock (mutex)
                {
                    try
                    {
                        using var silentFileController = new SilentFileChangerController();
                        using var fileChangerWatcher   = new FileChangerWatcher();

                        var tidySettings = SettingsProvider.TidySettingsModel;

                        if (CommandIds.kTidyFixId == aCommandId || tidySettings.TidyOnSave)
                        {
                            fileChangerWatcher.OnChanged += FileOpener.Open;

                            var dte2 = VsServiceProvider.GetService(typeof(DTE)) as DTE2;
                            string solutionFolderPath = SolutionInfo.IsOpenFolderModeActive() ?
                                                        dte2.Solution.FullName : dte2.Solution.FullName
                                                        .Substring(0, dte2.Solution.FullName.LastIndexOf('\\'));

                            fileChangerWatcher.Run(solutionFolderPath);

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

                            silentFileController.SilentFiles(filesPath);
                            silentFileController.SilentFiles(dte2.Documents);
                        }

                        if (tidySettings.DetectClangTidyFile && !mItemsCollector.IsEmpty)
                        {
                            // Check for .clang-tidy congif file
                            if (FileSystem.SearchAllTopDirectories(mItemsCollector.Items[0].GetPath(), FileSystem.ConfigClangTidyFileName))
                            {
                                tidySettings.UseChecksFrom = ClangTidyUseChecksFrom.TidyFile;
                            }
                            else
                            {
                                tidySettings.UseChecksFrom = ClangTidyUseChecksFrom.PredefinedChecks;
                            }

                            var settingsHandlder = new SettingsHandler();
                            settingsHandlder.SaveSettings();
                        }

                        RunScript(aCommandId, false);
                    }
                    catch (Exception exception)
                    {
                        VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                        OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                    }
                }
            });
        }
예제 #2
0
        public void RunClangTidy(int aCommandId)
        {
            if (mCommandsController.Running)
            {
                return;
            }

            mCommandsController.Running = true;

            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())
                        {
                            var tidySettings = SettingsProvider.GetSettingsPage(typeof(ClangTidyOptionsView)) as ClangTidyOptionsView;

                            if (CommandIds.kTidyFixId == aCommandId || tidySettings.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(aCommandId);
                        }
                    }
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            }).ContinueWith(tsk => DispatcherHandler.Invoke(() => mCommandsController.OnAfterClangCommand(), DispatcherPriority.Background));
        }
예제 #3
0
        public async Task RunClangTidyAsync(int aCommandId, CommandUILocation commandUILocation)
        {
            await PrepareCommmandAsync(commandUILocation);

            await Task.Run(() =>
            {
                try
                {
                    using (var silentFileController = new SilentFileChangerController())
                    {
                        using (var fileChangerWatcher = new FileChangerWatcher())
                        {
                            SettingsProvider settingsProvider = new SettingsProvider();
                            TidySettingsModel tidySettings    = settingsProvider.GetTidySettingsModel();

                            if (CommandIds.kTidyFixId == aCommandId || tidySettings.TidyOnSave)
                            {
                                fileChangerWatcher.OnChanged += FileOpener.Open;

                                var dte2 = VsServiceProvider.GetService(typeof(DTE)) as DTE2;
                                string solutionFolderPath = SolutionInfo.IsOpenFolderModeActive() ?
                                                            dte2.Solution.FullName : dte2.Solution.FullName
                                                            .Substring(0, dte2.Solution.FullName.LastIndexOf('\\'));

                                fileChangerWatcher.Run(solutionFolderPath);

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

                                silentFileController.SilentFiles(filesPath);
                                silentFileController.SilentFiles(dte2.Documents);
                            }
                            RunScript(aCommandId);
                        }
                    }
                }
                catch (Exception exception)
                {
                    VsShellUtilities.ShowMessageBox(AsyncPackage, exception.Message, "Error",
                                                    OLEMSGICON.OLEMSGICON_CRITICAL, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);
                }
            });
        }