private void PopulateInitialData(Workspace workspace, IDiagnosticService diagnosticService) { foreach (var bucket in diagnosticService.GetDiagnosticBuckets(workspace, projectId: null, documentId: null, cancellationToken: CancellationToken.None)) { // 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)); } }
public static ImmutableArray <DiagnosticData> GetDiagnostics(this IDiagnosticService service, Document document, bool includeSuppressedDiagnostics, CancellationToken cancellationToken) { var project = document.Project; var workspace = project.Solution.Workspace; using var _ = ArrayBuilder <DiagnosticData> .GetInstance(out var result); foreach (var bucket in service.GetDiagnosticBuckets(workspace, project.Id, document.Id, cancellationToken)) { Contract.ThrowIfFalse(workspace.Equals(bucket.Workspace)); Contract.ThrowIfFalse(document.Id.Equals(bucket.DocumentId)); var diagnostics = service.GetDiagnostics(bucket, includeSuppressedDiagnostics, cancellationToken); result.AddRange(diagnostics); } return(result.ToImmutable()); }