private Task <IEnumerable <Diagnostic> > ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync( Document document, DocumentDiagnosticAnalyzer analyzer, AnalysisKind kind, Compilation?compilation, CancellationToken cancellationToken) { return(AnalyzerService.ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, analyzer, kind, compilation, DiagnosticLogAggregator, cancellationToken)); }
private async Task <ImmutableDictionary <DiagnosticAnalyzer, DiagnosticAnalysisResult> > MergeProjectDiagnosticAnalyzerDiagnosticsAsync( Project project, ImmutableArray <DiagnosticAnalyzer> ideAnalyzers, Compilation?compilation, ImmutableDictionary <DiagnosticAnalyzer, DiagnosticAnalysisResult> result, CancellationToken cancellationToken) { try { var version = await GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false); var(fileLoadAnalysisResult, failedDocuments) = await GetDocumentLoadFailuresAsync(project, version, cancellationToken).ConfigureAwait(false); result = result.SetItem(FileContentLoadAnalyzer.Instance, fileLoadAnalysisResult); foreach (var analyzer in ideAnalyzers) { var builder = new DiagnosticAnalysisResultBuilder(project, version); switch (analyzer) { case DocumentDiagnosticAnalyzer documentAnalyzer: foreach (var document in project.Documents) { // don't analyze documents whose content failed to load if (failedDocuments == null || !failedDocuments.Contains(document)) { var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (tree != null) { builder.AddSyntaxDiagnostics(tree, await AnalyzerService.ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Syntax, compilation, DiagnosticLogAggregator, cancellationToken).ConfigureAwait(false)); builder.AddSemanticDiagnostics(tree, await AnalyzerService.ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Semantic, compilation, DiagnosticLogAggregator, cancellationToken).ConfigureAwait(false)); } else { builder.AddExternalSyntaxDiagnostics(document.Id, await AnalyzerService.ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Syntax, compilation, DiagnosticLogAggregator, cancellationToken).ConfigureAwait(false)); builder.AddExternalSemanticDiagnostics(document.Id, await AnalyzerService.ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync(document, documentAnalyzer, AnalysisKind.Semantic, compilation, DiagnosticLogAggregator, cancellationToken).ConfigureAwait(false)); } } } break; case ProjectDiagnosticAnalyzer projectAnalyzer: builder.AddCompilationDiagnostics(await AnalyzerService.ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(project, projectAnalyzer, compilation, DiagnosticLogAggregator, cancellationToken).ConfigureAwait(false)); break; } // merge the result to existing one. // there can be existing one from compiler driver with empty set. overwrite it with // ide one. result = result.SetItem(analyzer, DiagnosticAnalysisResult.CreateFromBuilder(builder)); } return(result); } catch (Exception e) when(FatalError.ReportUnlessCanceled(e)) { throw ExceptionUtilities.Unreachable; } }