Exemple #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 Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var mySettings     = new Settings <PropertyPage.PropertyPage>(package);
            var compileCommand = mySettings.GetPage().CompileCommand;

            if (compileCommand == null || compileCommand.Length == 0)
            {
                TidyControl.CancelAndShowHelp(package);
                return;
            }
            CLangHelpers.CreateCompilationDatabase(package, compileCommand);
        }
Exemple #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 Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (TidyControl.RunningTidy != null)
            {
                TidyControl.RunningTidy.Cancel();
                m_output.Write(Resources.Cancelled + "\n");
                return;
            }
            m_output = new ExtensionOutput(package, "CLang Output", ExtensionOutput.DefaultOutputWindowGuid);
            var mySettings     = new Settings <PropertyPage.PropertyPage>(package);
            var clangPath      = mySettings.GetPage().CLangTidy;
            var compileCommand = mySettings.GetPage().CompileCommand;

            if (clangPath == null || clangPath.Length == 0 ||
                compileCommand == null || compileCommand.Length == 0)
            {
                TidyControl.CancelAndShowHelp(package);
                return;
            }
            var clangOptions = mySettings.GetPage().AnalysisOptions;

            if (clangOptions == null)
            {
                clangOptions = "";
            }
            var selection = m_cppProject.GetVCFilesFromSelected();
            Dictionary <string, List <string> > projectsToFiles = new Dictionary <string, List <string> >();

            foreach (var(vcFile, project) in selection)
            {
                var compileDatabaseDirectory = new FileInfo(project.FileName).DirectoryName;
                var file = vcFile.FullPath;
                if (!projectsToFiles.ContainsKey(compileDatabaseDirectory))
                {
                    projectsToFiles.Add(compileDatabaseDirectory, new List <string>());
                }
                if (!new FileInfo(CLangHelpers.GetCompileDatabasePath(compileDatabaseDirectory)).Exists)
                {
                    CLangHelpers.CreateCompilationDatabase(package, compileCommand);
                }

                projectsToFiles[compileDatabaseDirectory].Add(file);
            }
            TidyControl.RunningTidy = new CancellationTokenSource();
            var cancel        = TidyControl.RunningTidy.Token;
            var errorProvider = new AnalysisOutputParser(selection.Count);
            var executeShell  = new ExecuteShellCommand(m_output, errorProvider);

            _ = ExecuteTidySetAsync(executeShell, clangPath, projectsToFiles, clangOptions, cancel);
        }
Exemple #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 Execute(object sender, EventArgs e)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            if (TidyControl.RunningTidy != null)
            {
                TidyControl.RunningTidy.Cancel();
                m_output.Write(Resources.Cancelled + "\n");
                return;
            }

            var project       = m_cppSupport.GetProjectFromSelected();
            var vcProject     = project.Object as VCProject;
            var configuration = m_cppSupport.GetActiveConfiguration(project);

            m_cppSupport.Save(project); // ensure that project is saved before we do anything
            var hierarchy = m_cppSupport.ToHierarchy(project as EnvDTE.Project);
            var compileDatabaseDirectory = new FileInfo(project.FileName).DirectoryName;

            var mySettings     = new Settings <PropertyPage.PropertyPage>(package);
            var clangPath      = mySettings.GetPage().CLangTidy;
            var compileCommand = mySettings.GetPage().CompileCommand;

            if (clangPath == null || clangPath.Length == 0 ||
                compileCommand == null || compileCommand.Length == 0)
            {
                TidyControl.CancelAndShowHelp(package);
                return;
            }

            var clangOptions = mySettings.GetPage().AnalysisOptions;

            if (clangOptions == null)
            {
                clangOptions = "";
            }
            var visitor = new CollectProjectFilesVisitor(m_output, m_cppSupport);

            m_cppSupport.VisitHierarchy(hierarchy, visitor);
            if (!new FileInfo(CLangHelpers.GetCompileDatabasePath(compileDatabaseDirectory)).Exists)
            {
                CLangHelpers.CreateCompilationDatabase(package, compileCommand);
            }
            TidyControl.RunningTidy = new CancellationTokenSource();
            var cancel = TidyControl.RunningTidy.Token;

            var errorProvider = new AnalysisOutputParser(visitor.ProjectFiles.Count);
            var executeShell  = new ExecuteShellCommand(m_output, errorProvider);

            _ = ExecuteTidyAsync(executeShell, clangPath, compileDatabaseDirectory, clangOptions, visitor.ProjectFiles, cancel);
        }