public async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeAsync(CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken) { var remoteHostClient = await project.Solution.Workspace.Services.GetService<IRemoteHostClientService>().GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); if (remoteHostClient == null) { // remote host is not running. this can happen if remote host is disabled. return await AnalyzeInProcAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false); } // TODO: later, make sure we can run all analyzer on remote host. // for now, we will check whether built in analyzer can run on remote host and only those run on remote host. var inProcResultTask = AnalyzeInProcAsync(CreateAnalyzerDriver(analyzerDriver, a => a.MustRunInProcess()), project, cancellationToken); var outOfProcResultTask = AnalyzeOutOfProcAsync(remoteHostClient, analyzerDriver, project, cancellationToken); // run them concurrently in vs and remote host await Task.WhenAll(inProcResultTask, outOfProcResultTask).ConfigureAwait(false); // make sure things are not cancelled cancellationToken.ThrowIfCancellationRequested(); // merge 2 results return DiagnosticAnalysisResultMap.Create( inProcResultTask.Result.AnalysisResult.AddRange(outOfProcResultTask.Result.AnalysisResult), inProcResultTask.Result.TelemetryInfo.AddRange(outOfProcResultTask.Result.TelemetryInfo)); }
private async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeOutOfProcAsync( RemoteHostClient client, CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken) { var solution = project.Solution; var snapshotService = solution.Workspace.Services.GetService<ISolutionChecksumService>(); // TODO: this should be moved out var hostChecksums = GetHostAnalyzerReferences(snapshotService, _analyzerService.GetHostAnalyzerReferences(), cancellationToken); var analyzerMap = CreateAnalyzerMap(analyzerDriver.Analyzers.Where(a => !a.MustRunInProcess())); if (analyzerMap.Count == 0) { return DiagnosticAnalysisResultMap.Create(ImmutableDictionary<DiagnosticAnalyzer, DiagnosticAnalysisResult>.Empty, ImmutableDictionary<DiagnosticAnalyzer, AnalyzerTelemetryInfo>.Empty); } // TODO: send telemetry on session using (var session = await client.CreateCodeAnalysisServiceSessionAsync(solution, cancellationToken).ConfigureAwait(false)) { var argument = new DiagnosticArguments( analyzerDriver.AnalysisOptions.ReportSuppressedDiagnostics, analyzerDriver.AnalysisOptions.LogAnalyzerExecutionTime, project.Id, hostChecksums, analyzerMap.Keys.ToArray()); var result = await session.InvokeAsync( WellKnownServiceHubServices.CodeAnalysisService_CalculateDiagnosticsAsync, new object[] { argument }, (s, c) => GetCompilerAnalysisResultAsync(s, analyzerMap, project, c)).ConfigureAwait(false); ReportAnalyzerExceptions(project, result.Exceptions); return result; } }
public async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeAsync(CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken) { var remoteHostClient = await project.Solution.Workspace.Services.GetService<IRemoteHostClientService>().GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); if (remoteHostClient == null) { // remote host is not running. this can happen if remote host is disabled. return await InProcCodeAnalysisDiagnosticAnalyzerExecutor.Instance.AnalyzeAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false); } // this will let VS.Next dll to be loaded var executor = project.Solution.Workspace.Services.GetService<IRemoteHostDiagnosticAnalyzerExecutor>(); return await executor.AnalyzeAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false); }
public void GetAnalyzerTelemetry() { var compilation = CSharpCompilation.Create("c", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); DiagnosticAnalyzer analyzer = new AnalyzerWithDisabledRules(); var analyzers = ImmutableArray.Create(analyzer); var analyzerOptions = new AnalyzerOptions(ImmutableArray<AdditionalText>.Empty); var compWithAnalyzers = new CompilationWithAnalyzers(compilation, analyzers, analyzerOptions, CancellationToken.None); var analysisResult = compWithAnalyzers.GetAnalysisResultAsync(CancellationToken.None).Result; Assert.Empty(analysisResult.CompilationDiagnostics); // Even though the analyzer registers a symbol action, it should never be invoked because all of its rules are disabled. var analyzerTelemetry = compWithAnalyzers.GetAnalyzerTelemetryInfoAsync(analyzer, CancellationToken.None).Result; Assert.Equal(0, analyzerTelemetry.SymbolActionsCount); }
public async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeAsync(CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken) { var remoteHostClient = await project.Solution.Workspace.Services.GetService<IRemoteHostClientService>().GetRemoteHostClientAsync(cancellationToken).ConfigureAwait(false); if (remoteHostClient == null) { // remote host is not running. this can happen if remote host is disabled. return await InProcCodeAnalysisDiagnosticAnalyzerExecutor.Instance.AnalyzeAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false); } var outOfProcResult = await AnalyzeOutOfProcAsync(remoteHostClient, analyzerDriver, project, cancellationToken).ConfigureAwait(false); // make sure things are not cancelled cancellationToken.ThrowIfCancellationRequested(); return DiagnosticAnalysisResultMap.Create(outOfProcResult.AnalysisResult, outOfProcResult.TelemetryInfo); }
private CompilationWithAnalyzers CreateAnalyzerDriver(CompilationWithAnalyzers analyzerDriver, Func<DiagnosticAnalyzer, bool> predicate) { var analyzers = analyzerDriver.Analyzers.Where(predicate).ToImmutableArray(); if (analyzers.Length == 0) { // we can't create analyzer driver with 0 analyzers return null; } return analyzerDriver.Compilation.WithAnalyzers(analyzers, analyzerDriver.AnalysisOptions); }
private static void AssertThatCompilationSucceeded(CompilationWithAnalyzers compilationWithAnalyzers) { var compilationDiagnostics = compilationWithAnalyzers.Compilation.GetDiagnostics(); if (compilationDiagnostics.Any()) { var messageBuilder = new StringBuilder(); messageBuilder.Append("Test code compilation failed. Error(s) encountered:"); foreach (var diagnostic in compilationDiagnostics) { messageBuilder.AppendLine(); messageBuilder.AppendFormat(" {0}", diagnostic); } throw new ArgumentException(messageBuilder.ToString()); } }
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(); }
private async Task<DiagnosticAnalysisResultMap<DiagnosticAnalyzer, DiagnosticAnalysisResult>> AnalyzeInProcAsync(CompilationWithAnalyzers analyzerDriver, Project project, CancellationToken cancellationToken) { return await InProcCodeAnalysisDiagnosticAnalyzerExecutor.Instance.AnalyzeAsync(analyzerDriver, project, cancellationToken).ConfigureAwait(false); }
private CompilationWithAnalyzers CreateAnalyzerDriver(CompilationWithAnalyzers analyzerDriver, Func<DiagnosticAnalyzer, bool> predicate) { var analyzers = analyzerDriver.Analyzers.Where(predicate).ToImmutableArray(); return analyzerDriver.Compilation.WithAnalyzers(analyzers, analyzerDriver.AnalysisOptions); }
public async Task <IEnumerable <DiagnosticData> > ComputeDiagnosticsAsync(DiagnosticAnalyzer analyzer, CancellationToken cancellationToken) { Contract.ThrowIfFalse(AnalysisScope.Analyzers.Contains(analyzer)); var document = AnalysisScope.Document; var span = AnalysisScope.Span; var kind = AnalysisScope.Kind; var loadDiagnostic = await document.State.GetLoadDiagnosticAsync(cancellationToken).ConfigureAwait(false); if (analyzer == FileContentLoadAnalyzer.Instance) { return(loadDiagnostic != null? SpecializedCollections.SingletonEnumerable(DiagnosticData.Create(loadDiagnostic, document)) : SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } if (loadDiagnostic != null) { return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } if (analyzer is DocumentDiagnosticAnalyzer documentAnalyzer) { var diagnostics = await AnalyzerHelper.ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync( documentAnalyzer, document, kind, _compilationWithAnalyzers?.Compilation, cancellationToken).ConfigureAwait(false); return(diagnostics.ConvertToLocalDiagnostics(document, span)); } // quick optimization to reduce allocations. if (_compilationWithAnalyzers == null || !analyzer.SupportAnalysisKind(kind)) { if (kind == AnalysisKind.Syntax) { Logger.Log(FunctionId.Diagnostics_SyntaxDiagnostic, (r, d, a, k) => $"Driver: {r != null}, {d.Id}, {d.Project.Id}, {a}, {k}", _compilationWithAnalyzers, document, analyzer, kind); } return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } // if project is not loaded successfully then, we disable semantic errors for compiler analyzers var isCompilerAnalyzer = analyzer.IsCompilerAnalyzer(); if (kind != AnalysisKind.Syntax && isCompilerAnalyzer) { var isEnabled = await document.Project.HasSuccessfullyLoadedAsync(cancellationToken).ConfigureAwait(false); Logger.Log(FunctionId.Diagnostics_SemanticDiagnostic, (a, d, e) => $"{a}, ({d.Id}, {d.Project.Id}), Enabled:{e}", analyzer, document, isEnabled); if (!isEnabled) { return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } } var skippedAnalyzerInfo = document.Project.GetSkippedAnalyzersInfo(_analyzerInfoCache); ImmutableArray <string> filteredIds; switch (kind) { case AnalysisKind.Syntax: var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); if (tree == null) { return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } var diagnostics = await GetSyntaxDiagnosticsAsync(tree, analyzer, isCompilerAnalyzer, cancellationToken).ConfigureAwait(false); if (diagnostics.IsDefaultOrEmpty) { Logger.Log(FunctionId.Diagnostics_SyntaxDiagnostic, (d, a, t) => $"{d.Id}, {d.Project.Id}, {a}, {t.Length}", document, analyzer, tree); } else if (skippedAnalyzerInfo.FilteredDiagnosticIdsForAnalyzers.TryGetValue(analyzer, out filteredIds)) { diagnostics = diagnostics.Filter(filteredIds); } Debug.Assert(diagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, _compilationWithAnalyzers.Compilation).Count()); return(diagnostics.ConvertToLocalDiagnostics(document, span)); case AnalysisKind.Semantic: var model = await document.GetSemanticModelAsync(cancellationToken).ConfigureAwait(false); if (model == null) { return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } diagnostics = await GetSemanticDiagnosticsAsync(model, analyzer, isCompilerAnalyzer, cancellationToken).ConfigureAwait(false); if (skippedAnalyzerInfo.FilteredDiagnosticIdsForAnalyzers.TryGetValue(analyzer, out filteredIds)) { diagnostics = diagnostics.Filter(filteredIds); } Debug.Assert(diagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, _compilationWithAnalyzers.Compilation).Count()); return(diagnostics.ConvertToLocalDiagnostics(document, span)); default: throw ExceptionUtilities.UnexpectedValue(kind); } }
/// <summary> /// Return all local diagnostics (syntax, semantic) that belong to given document for the given analyzer by calculating them. /// </summary> public async Task <IEnumerable <DiagnosticData> > ComputeDiagnosticsAsync(DiagnosticAnalyzer analyzer, CancellationToken cancellationToken) { Contract.ThrowIfFalse(AnalysisScope.Analyzers.Contains(analyzer)); var textDocument = AnalysisScope.TextDocument; var span = AnalysisScope.Span; var kind = AnalysisScope.Kind; var document = textDocument as Document; RoslynDebug.Assert(document != null || kind == AnalysisKind.Syntax, "We only support syntactic analysis for non-source documents"); var loadDiagnostic = await textDocument.State.GetLoadDiagnosticAsync(cancellationToken).ConfigureAwait(false); if (analyzer == FileContentLoadAnalyzer.Instance) { return(loadDiagnostic != null? SpecializedCollections.SingletonEnumerable(DiagnosticData.Create(loadDiagnostic, textDocument)) : SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } if (loadDiagnostic != null) { return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } if (analyzer is DocumentDiagnosticAnalyzer documentAnalyzer) { if (document == null) { return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } var documentDiagnostics = await AnalyzerHelper.ComputeDocumentDiagnosticAnalyzerDiagnosticsAsync( documentAnalyzer, document, kind, _compilationWithAnalyzers?.Compilation, cancellationToken).ConfigureAwait(false); return(documentDiagnostics.ConvertToLocalDiagnostics(document, span)); } // quick optimization to reduce allocations. if (_compilationWithAnalyzers == null || !analyzer.SupportAnalysisKind(kind)) { if (kind == AnalysisKind.Syntax) { Logger.Log(FunctionId.Diagnostics_SyntaxDiagnostic, (r, d, a, k) => $"Driver: {r != null}, {d.Id}, {d.Project.Id}, {a}, {k}", _compilationWithAnalyzers, textDocument, analyzer, kind); } return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } // if project is not loaded successfully then, we disable semantic errors for compiler analyzers var isCompilerAnalyzer = analyzer.IsCompilerAnalyzer(); if (kind != AnalysisKind.Syntax && isCompilerAnalyzer) { var isEnabled = await textDocument.Project.HasSuccessfullyLoadedAsync(cancellationToken).ConfigureAwait(false); Logger.Log(FunctionId.Diagnostics_SemanticDiagnostic, (a, d, e) => $"{a}, ({d.Id}, {d.Project.Id}), Enabled:{e}", analyzer, textDocument, isEnabled); if (!isEnabled) { return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } } if (document == null && textDocument is not AdditionalDocument) { // We currently support document analysis only for source documents and additional documents. return(SpecializedCollections.EmptyEnumerable <DiagnosticData>()); } var diagnostics = kind switch { AnalysisKind.Syntax => await GetSyntaxDiagnosticsAsync(analyzer, isCompilerAnalyzer, cancellationToken).ConfigureAwait(false), AnalysisKind.Semantic => await GetSemanticDiagnosticsAsync(analyzer, isCompilerAnalyzer, cancellationToken).ConfigureAwait(false), _ => throw ExceptionUtilities.UnexpectedValue(kind), }; // Remap diagnostic locations, if required. diagnostics = await RemapDiagnosticLocationsIfRequiredAsync(textDocument, diagnostics, cancellationToken).ConfigureAwait(false); #if DEBUG var diags = await diagnostics.ToDiagnosticsAsync(textDocument.Project, cancellationToken).ConfigureAwait(false); Debug.Assert(diags.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diags, _compilationWithAnalyzers.Compilation).Count()); Debug.Assert(diagnostics.Length == diags.ConvertToLocalDiagnostics(textDocument, span).Count()); #endif return(diagnostics); }
private async Task <DiagnosticAnalysisResultMap <DiagnosticAnalyzer, DiagnosticAnalysisResult> > AnalyzeOutOfProcAsync( DocumentAnalysisScope?documentAnalysisScope, Project project, CompilationWithAnalyzers compilationWithAnalyzers, RemoteHostClient client, bool forceExecuteAllAnalyzers, bool logPerformanceInfo, bool getTelemetryInfo, CancellationToken cancellationToken) { var solution = project.Solution; using var pooledObject = SharedPools.Default <Dictionary <string, DiagnosticAnalyzer> >().GetPooledObject(); var analyzerMap = pooledObject.Object; var analyzers = documentAnalysisScope?.Analyzers ?? compilationWithAnalyzers.Analyzers.Where(a => forceExecuteAllAnalyzers || !a.IsOpenFileOnly(solution.Options)); analyzerMap.AppendAnalyzerMap(analyzers); if (analyzerMap.Count == 0) { return(DiagnosticAnalysisResultMap <DiagnosticAnalyzer, DiagnosticAnalysisResult> .Empty); } // Use high priority if we are force executing all analyzers for user action OR serving an active document request. var isHighPriority = forceExecuteAllAnalyzers || documentAnalysisScope != null && _documentTrackingService?.TryGetActiveDocument() == documentAnalysisScope.TextDocument.Id; var argument = new DiagnosticArguments( isHighPriority, compilationWithAnalyzers.AnalysisOptions.ReportSuppressedDiagnostics, logPerformanceInfo, getTelemetryInfo, documentAnalysisScope?.TextDocument.Id, documentAnalysisScope?.Span, documentAnalysisScope?.Kind, project.Id, analyzerMap.Keys.ToArray()); var result = await client.TryInvokeAsync <IRemoteDiagnosticAnalyzerService, SerializableDiagnosticAnalysisResults>( solution, invocation : (service, solutionInfo, cancellationToken) => service.CalculateDiagnosticsAsync(solutionInfo, argument, cancellationToken), callbackTarget : null, cancellationToken).ConfigureAwait(false); if (!result.HasValue) { return(DiagnosticAnalysisResultMap <DiagnosticAnalyzer, DiagnosticAnalysisResult> .Empty); } // handling of cancellation and exception var version = await DiagnosticIncrementalAnalyzer.GetDiagnosticVersionAsync(project, cancellationToken).ConfigureAwait(false); var documentIds = (documentAnalysisScope != null) ? ImmutableHashSet.Create(documentAnalysisScope.TextDocument.Id) : null; return(new DiagnosticAnalysisResultMap <DiagnosticAnalyzer, DiagnosticAnalysisResult>( result.Value.Diagnostics.ToImmutableDictionary( entry => analyzerMap[entry.analyzerId], entry => DiagnosticAnalysisResult.Create( project, version, syntaxLocalMap: Hydrate(entry.diagnosticMap.Syntax, project), semanticLocalMap: Hydrate(entry.diagnosticMap.Semantic, project), nonLocalMap: Hydrate(entry.diagnosticMap.NonLocal, project), others: entry.diagnosticMap.Other, documentIds)), result.Value.Telemetry.ToImmutableDictionary(entry => analyzerMap[entry.analyzerId], entry => entry.telemetry))); }
public static ImmutableDictionary <DiagnosticAnalyzer, DiagnosticAnalysisResultBuilder> ToResultBuilderMap( this AnalysisResult analysisResult, ImmutableArray <Diagnostic> additionalPragmaSuppressionDiagnostics, Project project, VersionStamp version, Compilation compilation, IEnumerable <DiagnosticAnalyzer> analyzers, SkippedHostAnalyzersInfo skippedAnalyzersInfo, CancellationToken cancellationToken) { var builder = ImmutableDictionary.CreateBuilder <DiagnosticAnalyzer, DiagnosticAnalysisResultBuilder>(); ImmutableArray <Diagnostic> diagnostics; foreach (var analyzer in analyzers) { cancellationToken.ThrowIfCancellationRequested(); if (skippedAnalyzersInfo.SkippedAnalyzers.Contains(analyzer)) { continue; } var result = new DiagnosticAnalysisResultBuilder(project, version); var diagnosticIdsToFilter = skippedAnalyzersInfo.FilteredDiagnosticIdsForAnalyzers.GetValueOrDefault( analyzer, ImmutableArray <string> .Empty); foreach (var(tree, diagnosticsByAnalyzerMap) in analysisResult.SyntaxDiagnostics) { if (diagnosticsByAnalyzerMap.TryGetValue(analyzer, out diagnostics)) { diagnostics = diagnostics.Filter(diagnosticIdsToFilter); Debug.Assert(diagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilation).Count()); result.AddSyntaxDiagnostics(tree, diagnostics); } } foreach (var(tree, diagnosticsByAnalyzerMap) in analysisResult.SemanticDiagnostics) { if (diagnosticsByAnalyzerMap.TryGetValue(analyzer, out diagnostics)) { diagnostics = diagnostics.Filter(diagnosticIdsToFilter); Debug.Assert(diagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilation).Count()); result.AddSemanticDiagnostics(tree, diagnostics); } } foreach (var(file, diagnosticsByAnalyzerMap) in analysisResult.AdditionalFileDiagnostics) { if (diagnosticsByAnalyzerMap.TryGetValue(analyzer, out diagnostics)) { diagnostics = diagnostics.Filter(diagnosticIdsToFilter); Debug.Assert(diagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilation).Count()); if (project.GetDocumentForFile(file) is DocumentId documentId) { result.AddExternalSyntaxDiagnostics(documentId, diagnostics); } else { result.AddCompilationDiagnostics(diagnostics); } } } if (analysisResult.CompilationDiagnostics.TryGetValue(analyzer, out diagnostics)) { diagnostics = diagnostics.Filter(diagnosticIdsToFilter); Debug.Assert(diagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilation).Count()); result.AddCompilationDiagnostics(diagnostics); } // Special handling for pragma suppression diagnostics. if (analyzer is IPragmaSuppressionsAnalyzer) { foreach (var group in additionalPragmaSuppressionDiagnostics.GroupBy(d => d.Location.SourceTree !)) { diagnostics = group.AsImmutable().Filter(diagnosticIdsToFilter); Debug.Assert(diagnostics.Length == CompilationWithAnalyzers.GetEffectiveDiagnostics(diagnostics, compilation).Count()); result.AddSemanticDiagnostics(group.Key, diagnostics); } additionalPragmaSuppressionDiagnostics = ImmutableArray <Diagnostic> .Empty; } builder.Add(analyzer, result); } return(builder.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); }