public void Replace(Uri documentUri, IEnumerable <DiagnosticsEntry> entries, DiagnosticSource source) { lock (_lock) { if (!_diagnostics.TryGetValue(documentUri, out var documentDiagnostics)) { documentDiagnostics = new DocumentDiagnostics(); _diagnostics[documentUri] = documentDiagnostics; } documentDiagnostics.SetDiagnostics(source, entries.ToArray()); _lastChangeTime = DateTime.Now; } }
public async Task <ImmutableArray <DocumentDiagnostics> > GetDiagnostics(ImmutableArray <string> documentPaths) { if (!documentPaths.Any()) { return(ImmutableArray <DocumentDiagnostics> .Empty); } var results = ImmutableList <DocumentDiagnostics> .Empty; var documents = (await Task.WhenAll( documentPaths .Select(docPath => _workspace.GetDocumentsFromFullProjectModelAsync(docPath))) ).SelectMany(s => s); var diagnosticTasks = new List <Task>(); var throttler = new SemaphoreSlim(_options.RoslynExtensionsOptions.DiagnosticWorkersThreadCount); foreach (var document in documents) { if (document?.Project?.Name == null) { continue; } var projectName = document.Project.Name; await throttler.WaitAsync(); diagnosticTasks.Add( Task.Run(async() => { try { var diagnostics = await GetDiagnosticsForDocument(document, projectName); var documentDiagnostics = new DocumentDiagnostics(document.Id, document.FilePath, document.Project.Id, document.Project.Name, diagnostics); ImmutableInterlocked.Update(ref results, currentResults => currentResults.Add(documentDiagnostics)); } finally { throttler.Release(); } } ) ); } await Task.WhenAll(diagnosticTasks); return(results.ToImmutableArray()); }
private DocumentWithFixProvidersAndMatchingDiagnostics(CodeFixProvider provider, DocumentDiagnostics documentDiagnostics) { CodeFixProvider = provider; _documentDiagnostics = documentDiagnostics; FixAllProvider = provider.GetFixAllProvider(); }