private Task <IEnumerable <Diagnostic> > ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(
     Project project,
     ProjectDiagnosticAnalyzer analyzer,
     Compilation?compilation,
     CancellationToken cancellationToken)
 {
     return(AnalyzerService.ComputeProjectDiagnosticAnalyzerDiagnosticsAsync(project, analyzer, compilation, DiagnosticLogAggregator, cancellationToken));
 }
示例#2
0
        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;
            }
        }