public void ExecuteAnalysis(string path, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, IAnalyzerOptions analyzerOptions, IAnalysisStatusNotifier statusNotifier, CancellationToken cancellationToken) { var projectItem = dte?.Solution?.FindProjectItem(path); if (projectItem == null) { return; } Debug.Assert(IsAnalysisSupported(detectedLanguages)); var request = CreateRequest(logger, projectItem, path, cFamilyRulesConfigProvider, analyzerOptions); if (request == null) { return; } TriggerAnalysis(request, consumer, statusNotifier, cancellationToken); }
public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, ProjectItem projectItem, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { RequestAnalysisCallCount++; RequestAnalysisOperation?.Invoke(); }
public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { detectedLanguages.Should().NotBeNull(); detectedLanguages.Any().Should().BeTrue(); IsAnalysisSupported(detectedLanguages).Should().BeTrue(); RequestAnalysisCalled = true; }
public void RequestAnalysis(IAnalyzerOptions options) { FilePath = document.FilePath; // Refresh the stored file path in case the document has been renamed var issueConsumer = new AccumulatingIssueConsumer(textBuffer.CurrentSnapshot, FilePath, HandleNewIssues, converter); // Call the consumer with no analysis issues to immediately clear issies for this file // from the error list issueConsumer.Accept(FilePath, Enumerable.Empty <IAnalysisIssue>()); Provider.RequestAnalysis(FilePath, charset, detectedLanguages, issueConsumer, options); }
public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { Debug.Assert(IsAnalysisSupported(detectedLanguages)); ExecuteAnalysis(path, consumer, cancellationToken).Forget(); // fire and forget }
public void RequestAnalysis(IAnalyzerOptions analyzerOptions, params string[] filePaths) { try { var args = new AnalysisRequestEventArgs(analyzerOptions, filePaths); AnalysisRequested?.Invoke(this, args); } catch (Exception ex) when(!ErrorHandler.IsCriticalException(ex)) { logger.WriteLine(Analysis.AnalysisStrings.Requester_Error, ex); } }
/// <summary> /// Executes analysis for the given path. CancellationToken is not currently supported. /// </summary> public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { if (!IsAnalysisSupported(detectedLanguages)) { return; } // Optimise for the common case of daemon up and running if (installer.IsInstalled() && daemon.IsRunning) { InvokeDaemon(path, charset, detectedLanguages, consumer, cancellationToken, analyzerOptions); return; } new DelayedRequest(this, path, charset, detectedLanguages, consumer).Execute(); }
private Request GetSuccessfulRequest(IAnalyzerOptions analyzerOptions) { var loggerMock = new Mock <ILogger>(); var rulesConfig = GetDummyRulesConfiguration(); var rulesConfigProviderMock = new Mock <ICFamilyRulesConfigProvider>(); rulesConfigProviderMock .Setup(x => x.GetRulesConfiguration(It.IsAny <string>())) .Returns(rulesConfig); var projectItemMock = CreateProjectItemWithProject("c:\\foo\\file.cpp"); var request = CFamilyHelper.CreateRequest(loggerMock.Object, projectItemMock.Object, "c:\\foo\\file.cpp", rulesConfigProviderMock.Object, analyzerOptions); return(request); }
public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { if (!settings.IsActivateMoreEnabled) { // User might have disable additional languages in the meantime return; } if (!IsRunning) // daemon might not have finished starting / might have shutdown { // TODO: handle as part of #926: Delay starting the daemon until a file needs to be analyzed // https://github.com/SonarSource/sonarlint-visualstudio/issues/926 logger.WriteLine("Daemon has not started yet. Analysis will not be performed"); return; } RequestAnalysis(path, charset, "js", consumer); }
public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { bool handled = false; foreach (var analyzer in analyzers) { if (analyzer.IsAnalysisSupported(detectedLanguages)) { handled = true; analyzer.ExecuteAnalysis(path, charset, detectedLanguages, consumer, analyzerOptions, cancellationToken); } } if (!handled) { logger.WriteLine($"No analyzer supported analysis of {path}"); } }
public void Execute_ReanalysisTriggered() { // Arrange SetActiveDocument(ValidTextDocument, AnalysisLanguage.CFamily); IAnalyzerOptions actualOptions = null; string[] actualFilePaths = null; analysisRequesterMock.Setup(x => x.RequestAnalysis(It.IsAny <IAnalyzerOptions>(), It.IsAny <string[]>())) .Callback <IAnalyzerOptions, string[]>((opts, filePaths) => { actualOptions = opts; actualFilePaths = filePaths; }); // Act testSubject.Invoke(); // Assert logger.AssertOutputStringExists(CFamilyStrings.ReproCmd_ExecutingReproducer); actualOptions.Should().BeOfType <CFamilyAnalyzerOptions>(); ((CFamilyAnalyzerOptions)actualOptions).CreateReproducer.Should().BeTrue(); actualFilePaths.Should().BeEquivalentTo(ValidTextDocument.FilePath); }
public AnalysisRequestEventArgs(IAnalyzerOptions analyzerOptions, IEnumerable <string> filePaths) { Options = analyzerOptions; FilePaths = filePaths; }
public void RequestAnalysis(IAnalyzerOptions options) { Provider.RequestAnalysis(FilePath, charset, detectedLanguages, this, ProjectItem, options); }
protected override Request CreateRequest(ILogger logger, ProjectItem projectItem, string absoluteFilePath, ICFamilyRulesConfigProvider cFamilyRulesConfigProvider, IAnalyzerOptions analyzerOptions) { CreateRequestCallCount++; return(RequestToReturn); }
public void RequestAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer issueConsumer, IAnalyzerOptions analyzerOptions) { // May be called on the UI thread -> unhandled exceptions will crash VS try { var analysisTimeout = GetAnalysisTimeoutInMilliseconds(); scheduler.Schedule(path, cancellationToken => analyzerController.ExecuteAnalysis(path, charset, detectedLanguages, issueConsumer, analyzerOptions, cancellationToken), analysisTimeout); } catch (NotSupportedException ex) { // Display a simple user-friendly message for options we know are not supported. // See https://github.com/SonarSource/sonarlint-visualstudio/pull/2212 logger.WriteLine($"Unable to analyze: {ex.Message}"); } catch (Exception ex) when(!Microsoft.VisualStudio.ErrorHandler.IsCriticalException(ex)) { logger.WriteLine($"Analysis error: {ex}"); } }
public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, ProjectItem projectItem, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { Debug.Assert(IsAnalysisSupported(detectedLanguages)); var request = CFamilyHelper.CreateRequest(logger, projectItem, path, cFamilyRulesConfigProvider, analyzerOptions); if (request == null) { return; } TriggerAnalysisAsync(request, consumer, cancellationToken) .Forget(); // fire and forget }
public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, IAnalyzerOptions analyzerOptions, CancellationToken cancellationToken) { ExecuteAnalysis(path, detectedLanguages, consumer, analyzerOptions, analysisStatusNotifier, cancellationToken); }
protected /* for testing */ virtual Request CreateRequest(ILogger logger, ProjectItem projectItem, string absoluteFilePath, ICFamilyRulesConfigProvider cFamilyRulesConfigProvider, IAnalyzerOptions analyzerOptions) => CFamilyHelper.CreateRequest(logger, projectItem, absoluteFilePath, cFamilyRulesConfigProvider, analyzerOptions);
internal static FileConfig TryGetConfig(ILogger logger, ProjectItem projectItem, string absoluteFilePath, IAnalyzerOptions analyzerOptions) { Debug.Assert(IsFileInSolution(projectItem), $"Not expecting to be called for files that are not in the solution: {absoluteFilePath}"); try { // Note: if the C++ tools are not installed then it's likely an exception will be thrown when // the framework tries to JIT-compile the TryGet method (since it won't be able to find the MS.VS.VCProjectEngine // types). var fileConfig = FileConfig.TryGet(logger, projectItem, absoluteFilePath); if (analyzerOptions is CFamilyAnalyzerOptions cFamilyAnalyzerOptions && cFamilyAnalyzerOptions.CreateReproducer) { SaveFileConfig(fileConfig, logger); } return(fileConfig); } catch (Exception e) { logger.WriteLine($"Unable to collect C/C++ configuration for {absoluteFilePath}: {e}"); return(null); } }
public static Request CreateRequest(ILogger logger, ProjectItem projectItem, string absoluteFilePath, ICFamilyRulesConfigProvider cFamilyRulesConfigProvider, IAnalyzerOptions analyzerOptions) { if (analyzerOptions is CFamilyAnalyzerOptions cFamilyAnalyzerOptions && cFamilyAnalyzerOptions.CreatePreCompiledHeaders) { // In case the requeset is coming from PCH generation, we don't log failures. // This is to avoid redundant messages while navigating unsupoported files. logger = noOpLogger; } if (!IsFileInSolution(projectItem)) { logger.WriteLine($"Unable to retrieve the configuration for file '{absoluteFilePath}'. Check the file is part of a project in the current solution."); return(null); } var fileConfig = TryGetConfig(logger, projectItem, absoluteFilePath, analyzerOptions); if (fileConfig == null) { return(null); } return(CreateRequest(fileConfig, absoluteFilePath, cFamilyRulesConfigProvider, analyzerOptions)); }
private static Request CreateRequest(FileConfig fileConfig, string absoluteFilePath, ICFamilyRulesConfigProvider cFamilyRulesConfigProvider, IAnalyzerOptions analyzerOptions) { var request = fileConfig.ToRequest(absoluteFilePath); if (request?.File == null || request?.CFamilyLanguage == null) { return(null); } request.RulesConfiguration = cFamilyRulesConfigProvider.GetRulesConfiguration(request.CFamilyLanguage); Debug.Assert(request.RulesConfiguration != null, "RulesConfiguration should be set for the analysis request"); request.Options = GetKeyValueOptionsList(request.RulesConfiguration); if (analyzerOptions is CFamilyAnalyzerOptions cFamilyAnalyzerOptions && cFamilyAnalyzerOptions.CreateReproducer) { request.Flags |= Request.CreateReproducer; } return(request); }
private void InvokeDaemon(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, ProjectItem projectItem, CancellationToken cancellationToken, IAnalyzerOptions analyzerOptions) { Debug.Assert(detectedLanguages?.Contains(AnalysisLanguage.Javascript) ?? false, "Not expecting the daemon to be called for languages other than JavaScript"); // TODO refactor the daemon so it does not implement IAnalyzer or make any // decisions about whether to run or not. That should all be handled by // this class. telemetryManager.LanguageAnalyzed("js"); daemon.ExecuteAnalysis(path, charset, detectedLanguages, consumer, projectItem, analyzerOptions, cancellationToken); }
private static Request CreateRequest(FileConfig fileConfig, string absoluteFilePath, ICFamilyRulesConfigProvider cFamilyRulesConfigProvider, IAnalyzerOptions analyzerOptions) { var request = ToRequest(fileConfig, absoluteFilePath); if (request?.File == null || request?.CFamilyLanguage == null) { return(null); } request.PchFile = PchFilePath; bool isPCHBuild = false; if (analyzerOptions is CFamilyAnalyzerOptions cFamilyAnalyzerOptions) { Debug.Assert(!(cFamilyAnalyzerOptions.CreateReproducer && cFamilyAnalyzerOptions.CreatePreCompiledHeaders), "Only one flag (CreateReproducer, CreatePreCompiledHeaders) can be set at a time"); if (cFamilyAnalyzerOptions.CreateReproducer) { request.Flags |= Request.CreateReproducer; } if (cFamilyAnalyzerOptions.CreatePreCompiledHeaders) { request.Flags |= Request.BuildPreamble; isPCHBuild = true; } } if (!isPCHBuild) { // We don't need to calculate / set the rules configuration for PCH builds request.RulesConfiguration = cFamilyRulesConfigProvider.GetRulesConfiguration(request.CFamilyLanguage); Debug.Assert(request.RulesConfiguration != null, "RulesConfiguration should be set for the analysis request"); request.Options = GetKeyValueOptionsList(request.RulesConfiguration); } return(request); }
public void RequestAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer issueConsumer, ProjectItem projectItem, IAnalyzerOptions analyzerOptions) { // May be called on the UI thread -> unhandled exceptions will crash VS try { scheduler.Schedule(path, cancellationToken => analyzerController.ExecuteAnalysis(path, charset, detectedLanguages, issueConsumer, projectItem, analyzerOptions, cancellationToken)); } catch (Exception ex) when(!Microsoft.VisualStudio.ErrorHandler.IsCriticalException(ex)) { logger.WriteLine($"Analysis error: {ex}"); } }
public static Request CreateRequest(ILogger logger, ProjectItem projectItem, string absoluteFilePath, ICFamilyRulesConfigProvider cFamilyRulesConfigProvider, IAnalyzerOptions analyzerOptions) { if (IsHeaderFile(absoluteFilePath)) { // We can't analyze header files currently because we can't get all // of the required configuration information logger.WriteLine($"Cannot analyze header files. File: '{absoluteFilePath}'"); return(null); } if (!IsFileInSolution(projectItem)) { logger.WriteLine($"Unable to retrieve the configuration for file '{absoluteFilePath}'. Check the file is part of a project in the current solution."); return(null); } var fileConfig = TryGetConfig(logger, projectItem, absoluteFilePath); if (fileConfig == null) { return(null); } return(CreateRequest(fileConfig, absoluteFilePath, cFamilyRulesConfigProvider, analyzerOptions)); }