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); }
protected override void InnerInvoke( IProgressTracker progressTracker, CancellationToken cancellationToken) { this.AssertIsForeground(); using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesSession, FixAllLogger.CreateCorrelationLogMessage(_fixAllState.CorrelationId), cancellationToken)) { base.InnerInvoke(progressTracker, cancellationToken); } }
protected override async Task InnerInvokeAsync( IProgressTracker progressTracker, CancellationToken cancellationToken) { await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesSession, FixAllLogger.CreateCorrelationLogMessage(FixAllState.CorrelationId), cancellationToken)) { await base.InnerInvokeAsync(progressTracker, cancellationToken).ConfigureAwait(false); } }
private async Task <ImmutableArray <(Diagnostic diagnostic, CodeAction action)> > 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()); }
protected override async Task InnerInvokeAsync( IProgressTracker progressTracker, CancellationToken cancellationToken) { await this.ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken); var fixAllKind = FixAllState.FixAllKind; var functionId = fixAllKind switch { FixAllKind.CodeFix => FunctionId.CodeFixes_FixAllOccurrencesSession, FixAllKind.Refactoring => FunctionId.Refactoring_FixAllOccurrencesSession, _ => throw ExceptionUtilities.UnexpectedValue(fixAllKind) }; using (Logger.LogBlock(functionId, FixAllLogger.CreateCorrelationLogMessage(FixAllState.CorrelationId), cancellationToken)) { await base.InnerInvokeAsync(progressTracker, cancellationToken).ConfigureAwait(false); } } }