示例#1
0
        public void ExecuteAnalysis(string path, string charset, IEnumerable <AnalysisLanguage> detectedLanguages, IIssueConsumer consumer, ProjectItem projectItem)
        {
            Debug.Assert(IsAnalysisSupported(detectedLanguages));

            var request = CFamilyHelper.CreateRequest(logger, projectItem, path, cFamilyRulesConfigProvider);

            if (request == null)
            {
                return;
            }

            TriggerAnalysisAsync(request, consumer)
            .Forget();     // fire and forget
        }
        private async Task TriggerAnalysisAsync(Request request, IIssueConsumer consumer, CancellationToken cancellationToken)
        {
            // For notes on VS threading, see https://github.com/microsoft/vs-threading/blob/master/doc/cookbook_vs.md
            // Note: we support multiple versions of VS which prevents us from using some threading helper methods
            // that are only available in newer versions of VS e.g. [Import] IThreadHandling.

            // Switch a background thread
            await TaskScheduler.Default;

            logger.WriteLine($"Analyzing {request.File}");

            // We're tying up a background thread waiting for out-of-process analysis. We could
            // change the process runner so it works asynchronously. Alternatively, we could change the
            // RequestAnalysis method to be synchronous, rather than fire-and-forget.
            var response = CFamilyHelper.CallClangAnalyzer(request, new ProcessRunner(settings, logger), logger, cancellationToken);

            if (response != null)
            {
                Debug.Assert(response.Messages.All(m => m.Filename == request.File), "Issue for unexpected file returned");

                var issues = response.Messages
                             .Where(m => IsIssueForActiveRule(m, request.RulesConfiguration))
                             .Select(m => CFamilyHelper.ToSonarLintIssue(m, request.CFamilyLanguage, request.RulesConfiguration))
                             .ToList();

                telemetryManager.LanguageAnalyzed(request.CFamilyLanguage); // different keys for C and C++

                logger.WriteLine($"Found {issues.Count} issue(s)");

                // Switch back to the UI thread
                await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                // Note: the file being analyzed might have been closed by the time the analysis results are
                // returned. This doesn't cause a crash; all active taggers will have been detached from the
                // TextBufferIssueTracker when the file was closed, but the TextBufferIssueTracker will
                // still exist and handle the call.
                consumer.Accept(request.File, issues);
            }
        }
示例#3
0
        .Forget();         // fire and forget

        protected /* for testing */ virtual void CallSubProcess(Action <Message> handleMessage, Request request, ISonarLintSettings settings, ILogger logger, CancellationToken cancellationToken)
        {
            CFamilyHelper.CallClangAnalyzer(handleMessage, request, new ProcessRunner(settings, logger), logger, cancellationToken);
        }
示例#4
0
 protected /* for testing */ virtual Request CreateRequest(ILogger logger, ProjectItem projectItem, string absoluteFilePath, ICFamilyRulesConfigProvider cFamilyRulesConfigProvider, IAnalyzerOptions analyzerOptions) =>
 CFamilyHelper.CreateRequest(logger, projectItem, absoluteFilePath, cFamilyRulesConfigProvider, analyzerOptions);