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()); }
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()); }
private void PopulateInitialData( Workspace workspace, IDiagnosticService diagnosticService ) { var diagnostics = diagnosticService.GetPushDiagnosticBuckets( workspace, projectId: null, documentId: null, InternalDiagnosticsOptions.NormalDiagnosticMode, cancellationToken: CancellationToken.None ); foreach (var bucket in diagnostics) { // We only need to issue an event to VS that these docs have diagnostics associated with them. So // we create a dummy notification for this. It doesn't matter that it is 'DiagnosticsRemoved' as // this doesn't actually change any data. All that will happen now is that VS will call back into // us for these IDs and we'll fetch the diagnostics at that point. OnDataAddedOrChanged( DiagnosticsUpdatedArgs.DiagnosticsRemoved( bucket.Id, bucket.Workspace, solution: null, bucket.ProjectId, bucket.DocumentId ) ); } }