private async Task <CodeAction?> GetFixAsync( ImmutableDictionary <Document, ImmutableArray <Diagnostic> > documentsAndDiagnosticsToFixMap, FixAllContext fixAllContext) { var cancellationToken = fixAllContext.CancellationToken; if (documentsAndDiagnosticsToFixMap?.Any() == true) { var progressTracker = fixAllContext.GetProgressTracker(); progressTracker.Description = FixAllContextHelper.GetDefaultFixAllTitle(fixAllContext); var fixAllState = fixAllContext.State; FixAllLogger.LogDiagnosticsStats(fixAllState.CorrelationId, documentsAndDiagnosticsToFixMap); var diagnosticsAndCodeActions = await GetDiagnosticsAndCodeActionsAsync(documentsAndDiagnosticsToFixMap, fixAllContext).ConfigureAwait(false); if (diagnosticsAndCodeActions.Length > 0) { var functionId = FunctionId.CodeFixes_FixAllOccurrencesComputation_Document_Merge; using (Logger.LogBlock(functionId, FixAllLogger.CreateCorrelationLogMessage(fixAllState.CorrelationId), cancellationToken)) { FixAllLogger.LogFixesToMergeStats(functionId, fixAllState.CorrelationId, diagnosticsAndCodeActions.Length); return(await TryGetMergedFixAsync( diagnosticsAndCodeActions, fixAllState, cancellationToken).ConfigureAwait(false)); } } } return(null); }
> GetDiagnosticsAndCodeActionsAsync( ImmutableDictionary < Document, ImmutableArray <Diagnostic> > documentsAndDiagnosticsToFixMap, FixAllContext fixAllContext ) { var cancellationToken = fixAllContext.CancellationToken; var fixAllState = fixAllContext.State; var fixesBag = new ConcurrentBag <(Diagnostic diagnostic, CodeAction action)>(); using ( Logger.LogBlock( FunctionId.CodeFixes_FixAllOccurrencesComputation_Document_Fixes, FixAllLogger.CreateCorrelationLogMessage(fixAllState.CorrelationId), cancellationToken ) ) { cancellationToken.ThrowIfCancellationRequested(); var progressTracker = fixAllContext.GetProgressTracker(); using var _1 = ArrayBuilder <Task> .GetInstance(out var tasks); using var _2 = ArrayBuilder <Document> .GetInstance(out var documentsToFix); // Determine the set of documents to actually fix. We can also use this to update the progress bar with // the amount of remaining work to perform. We'll update the progress bar as we compute each fix in // AddDocumentFixesAsync. foreach (var(document, diagnosticsToFix) in documentsAndDiagnosticsToFixMap) { if (!diagnosticsToFix.IsDefaultOrEmpty) { documentsToFix.Add(document); } } progressTracker.AddItems(documentsToFix.Count); foreach (var document in documentsToFix) { var diagnosticsToFix = documentsAndDiagnosticsToFixMap[document]; tasks.Add( AddDocumentFixesAsync( document, diagnosticsToFix, fixesBag, fixAllState, progressTracker, cancellationToken ) ); } await Task.WhenAll(tasks).ConfigureAwait(false); } return(fixesBag.ToImmutableArray()); }
public override async Task <CodeAction?> GetFixAsync(FixAllContext fixAllContext) { var diagnostics = fixAllContext.Scope switch { FixAllScope.Document when fixAllContext.Document is not null => await fixAllContext.GetDocumentDiagnosticsAsync(fixAllContext.Document).ConfigureAwait(false), FixAllScope.Project => await fixAllContext.GetAllDiagnosticsAsync(fixAllContext.Project).ConfigureAwait(false), FixAllScope.Solution => await GetSolutionDiagnosticsAsync(fixAllContext).ConfigureAwait(false), _ => default }; if (diagnostics.IsDefaultOrEmpty) { return(null); } var title = FixAllContextHelper.GetDefaultFixAllTitle(fixAllContext); return(CodeAction.Create( title, cancellationToken => FixAllByDocumentAsync( fixAllContext.Project.Solution, diagnostics, fixAllContext.GetProgressTracker(), #if CODE_STYLE options: _ => default,