Example #1
0
        public void CollectActiveProjectItem()
        {
            try
            {
                DTE      dte            = (DTE)VsServiceProvider.GetService(typeof(DTE));
                Document activeDocument = dte.ActiveDocument;

                if (activeDocument == null)
                {
                    return;
                }

                IItem item        = null;
                var   projectName = activeDocument.ProjectItem.ContainingProject.FullName;

                if (SolutionInfo.IsOpenFolderModeActive())
                {
                    item = new CurrentDocument(activeDocument);
                    Items.Add(item);
                }
                else if (string.IsNullOrWhiteSpace(projectName) == false)
                {
                    item = new CurrentProjectItem(activeDocument.ProjectItem);
                    Items.Add(item);
                }
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Example #2
0
        // TODO : Refactor this method. Generics can be a solution.
        public void CollectActiveProjectItem()
        {
            try
            {
                DTE      dte            = (DTE)VsServiceProvider.GetService(typeof(DTE));
                Document activeDocument = dte.ActiveDocument;

                if (activeDocument == null)
                {
                    return;
                }

                IItem item = null;
                if (SolutionInfo.IsOpenFolderModeActive())
                {
                    item = new CurrentDocument(activeDocument);
                }
                else
                {
                    item = new CurrentProjectItem(activeDocument.ProjectItem);
                }

                Items.Add(item);
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Example #3
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);
                    }
                }
            });
        }
Example #4
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);
                }
            });
        }
Example #5
0
        public void Run(Document document, int commandId)
        {
            try
            {
                #region Create currnet project item

                if (document == null || document.ProjectItem == null)
                {
                    return;
                }

                var projectName = document.ProjectItem.ContainingProject.FullName;
                if (string.IsNullOrWhiteSpace(projectName))
                {
                    return;
                }

                IItem item = new CurrentProjectItem(document.ProjectItem);

                #endregion


                #region Get VS edition and version

                var dte = (DTE2)VsServiceProvider.GetService(typeof(DTE));

                var vsEdition = dte.Edition;
                mVsVersions.TryGetValue(dte.Version, out string vsVersion);

                #endregion


                #region Generate powershell script

                string runModeParameters = ScriptGenerator.GetRunModeParamaters();
                string genericParameters = ScriptGenerator.GetGenericParamaters(commandId, vsEdition, vsVersion, false);

                CMakeBuilder cMakeBuilder = new CMakeBuilder();
                cMakeBuilder.Build();

                var vsSolution = SolutionInfo.IsOpenFolderModeActive() == false ?
                                 (IVsSolution)VsServiceProvider.GetService(typeof(SVsSolution)) : null;

                var itemRelatedParameters = ScriptGenerator.GetItemRelatedParameters(item);

                var psScript = JoinUtility.Join(" ", runModeParameters.Remove(runModeParameters.Length - 1), itemRelatedParameters, genericParameters, "'");

                #endregion


                #region PowerShell Invocation

                powerShell.Invoke(psScript, new RunningProcesses(true));

                #endregion

                cMakeBuilder.ClearBuildCashe();
            }
            catch (Exception)
            {
                //MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #6
0
        public void OnWindowActivated(Window GotFocus, Window LostFocus)
        {
            VsWindowController.SetPreviousActiveWindow(LostFocus);

            if (ReleaseNotesView.WasShown == false)
            {
                var releaseNotesView = new ReleaseNotesView(true);
                releaseNotesView.Show();
            }

            if (showOpenFolderWarning)
            {
                var    registryUtility      = new RegistryUtility(registryName);
                string showCMakeBetaWarning = registryUtility.ReadCurrentUserKey(keyName);

                if (showCMakeBetaWarning == null && SolutionInfo.IsOpenFolderModeActive())
                {
                    showOpenFolderWarning = false;
                    CMakeBetaWarning cMakeBetaWarning = new CMakeBetaWarning();
                    cMakeBetaWarning.Show();
                }
            }

            if (SettingsProvider.CompilerSettingsModel.ShowSquiggles == false)
            {
                return;
            }

            if (running || vsBuildRunning)
            {
                return;
            }

            Document document = GotFocus.Document;

            if (document == null)
            {
                return;
            }

            if (!string.IsNullOrEmpty(oldActiveDocumentName) && oldActiveDocumentName == document.FullName)
            {
                return;
            }

            oldActiveDocumentName = document.FullName;
            if (!ScriptConstants.kAcceptedFileExtensions.Contains(Path.GetExtension(document.FullName)))
            {
                return;
            }

            _ = Task.Run(() =>
            {
                lock (mutex)
                {
                    try
                    {
                        TaskErrorViewModel.FileErrorsPair.Clear();
                        using BackgroundTidy backgroundTidyCommand = new BackgroundTidy();
                        backgroundTidyCommand.Run(document, CommandIds.kTidyId);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            });
        }