public static async Task<ImmutableArray<Diagnostic>> GetAllDiagnosticsAsync(Compilation compilation, CompilationWithAnalyzers compilationWithAnalyzers, ImmutableArray<DiagnosticAnalyzer> analyzers, IEnumerable<Document> documents, bool includeCompilerDiagnostics, CancellationToken cancellationToken) { if (GetAnalyzerSyntaxDiagnosticsAsync == null || GetAnalyzerSemanticDiagnosticsAsync == null) { // In everything except Roslyn 1.1, we use GetAllDiagnosticsAsync and return the result. var allDiagnostics = await compilationWithAnalyzers.GetAllDiagnosticsAsync().ConfigureAwait(false); return allDiagnostics; } compilationWithAnalyzers.Compilation.GetDeclarationDiagnostics(cancellationToken); // Note that the following loop to obtain syntax and semantic diagnostics for each document cannot operate // on parallel due to our use of a single CompilationWithAnalyzers instance. var diagnostics = ImmutableArray.CreateBuilder<Diagnostic>(); foreach (var document in documents) { var syntaxTree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var syntaxDiagnostics = await GetAnalyzerSyntaxDiagnosticsAsync(compilationWithAnalyzers, syntaxTree, cancellationToken).ConfigureAwait(false); diagnostics.AddRange(syntaxDiagnostics); var semanticModel = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); var semanticDiagnostics = await GetAnalyzerSemanticDiagnosticsAsync(compilationWithAnalyzers, semanticModel, default(TextSpan?), cancellationToken).ConfigureAwait(false); diagnostics.AddRange(semanticDiagnostics); } foreach (var analyzer in analyzers) { diagnostics.AddRange(await GetAnalyzerCompilationDiagnosticsAsync(compilationWithAnalyzers, ImmutableArray.Create(analyzer), cancellationToken).ConfigureAwait(false)); } if (includeCompilerDiagnostics) { // This is the special handling for cases where code fixes operate on warnings produced by the C# // compiler, as opposed to being created by specific analyzers. var compilerDiagnostics = compilation.GetDiagnostics(cancellationToken); diagnostics.AddRange(compilerDiagnostics); } return diagnostics.ToImmutable(); }
public static async Task<ImmutableArray<Diagnostic>> GetAllDiagnosticsAsync(Compilation compilation, CompilationWithAnalyzers compilationWithAnalyzers, ImmutableArray<DiagnosticAnalyzer> analyzers, IEnumerable<Document> documents, bool includeCompilerDiagnostics, CancellationToken cancellationToken) { return await compilationWithAnalyzers.GetAllDiagnosticsAsync().ConfigureAwait(false); }