public static ImmutableArray <DiagnosticData> GetDiagnostics( this IDiagnosticService service, Document document, bool includeSuppressedDiagnostics, bool forPullDiagnostics, Option2 <DiagnosticMode> diagnosticMode, CancellationToken cancellationToken) { var project = document.Project; var workspace = project.Solution.Workspace; using var _ = ArrayBuilder <DiagnosticData> .GetInstance(out var result); var buckets = forPullDiagnostics ? service.GetPullDiagnosticBuckets(workspace, project.Id, document.Id, diagnosticMode, cancellationToken) : service.GetPushDiagnosticBuckets(workspace, project.Id, document.Id, diagnosticMode, cancellationToken); foreach (var bucket in buckets) { Contract.ThrowIfFalse(workspace.Equals(bucket.Workspace)); Contract.ThrowIfFalse(document.Id.Equals(bucket.DocumentId)); var diagnostics = forPullDiagnostics ? service.GetPullDiagnostics(bucket, includeSuppressedDiagnostics, diagnosticMode, cancellationToken) : service.GetPushDiagnostics(bucket, includeSuppressedDiagnostics, diagnosticMode, cancellationToken); result.AddRange(diagnostics); } return(result.ToImmutable()); }
public static async ValueTask <ImmutableArray <DiagnosticData> > GetDiagnosticsAsync( this IDiagnosticService service, Workspace workspace, Project?project, Document?document, bool includeSuppressedDiagnostics, bool forPullDiagnostics, Option2 <DiagnosticMode> diagnosticMode, CancellationToken cancellationToken) { Contract.ThrowIfTrue(document != null && document.Project != project); Contract.ThrowIfTrue(project != null && project.Solution.Workspace != workspace); using var _ = ArrayBuilder <DiagnosticData> .GetInstance(out var result); var buckets = forPullDiagnostics ? service.GetPullDiagnosticBuckets(workspace, project?.Id, document?.Id, diagnosticMode, cancellationToken) : service.GetPushDiagnosticBuckets(workspace, project?.Id, document?.Id, diagnosticMode, cancellationToken); foreach (var bucket in buckets) { Contract.ThrowIfFalse(workspace.Equals(bucket.Workspace)); Contract.ThrowIfFalse(document?.Id == bucket.DocumentId); var diagnostics = forPullDiagnostics ? await service.GetPullDiagnosticsAsync(bucket, includeSuppressedDiagnostics, diagnosticMode, cancellationToken).ConfigureAwait(false) : await service.GetPushDiagnosticsAsync(bucket, includeSuppressedDiagnostics, diagnosticMode, cancellationToken).ConfigureAwait(false); result.AddRange(diagnostics); } return(result.ToImmutable()); }