using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Threading; using System.Threading.Tasks; namespace Microsoft.CodeAnalysis.CodeFixes { internal partial class FixAllState { // Internal for testing purposes. internal class FixAllDiagnosticProvider : FixAllContext.DiagnosticProvider { private readonly ImmutableHashSet _diagnosticIds; /// /// Delegate to fetch diagnostics for any given document within the given fix all scope. /// This delegate is invoked by with the given as arguments. /// private readonly Func, CancellationToken, Task>> _getDocumentDiagnosticsAsync; /// /// Delegate to fetch diagnostics for any given project within the given fix all scope. /// This delegate is invoked by and /// with the given as arguments. /// The boolean argument to the delegate indicates whether or not to return location-based diagnostics, i.e. /// (a) False => Return only diagnostics with . /// (b) True => Return all project diagnostics, regardless of whether or not they have a location. /// private readonly Func, CancellationToken, Task>> _getProjectDiagnosticsAsync; public FixAllDiagnosticProvider( ImmutableHashSet diagnosticIds, Func, CancellationToken, Task>> getDocumentDiagnosticsAsync, Func, CancellationToken, Task>> getProjectDiagnosticsAsync) { _diagnosticIds = diagnosticIds; _getDocumentDiagnosticsAsync = getDocumentDiagnosticsAsync; _getProjectDiagnosticsAsync = getProjectDiagnosticsAsync; } public override Task> GetDocumentDiagnosticsAsync(Document document, CancellationToken cancellationToken) { return _getDocumentDiagnosticsAsync(document, _diagnosticIds, cancellationToken); } public override Task> GetAllDiagnosticsAsync(Project project, CancellationToken cancellationToken) { return _getProjectDiagnosticsAsync(project, true, _diagnosticIds, cancellationToken); } public override Task> GetProjectDiagnosticsAsync(Project project, CancellationToken cancellationToken) { return _getProjectDiagnosticsAsync(project, false, _diagnosticIds, cancellationToken); } } } }