private static async Task <CodeAction> GetFixAllCodeActionAsync(FixAllContext fixAllContext) { using (Logger.LogBlock( FunctionId.CodeFixes_FixAllOccurrencesComputation, KeyValueLogMessage.Create(LogType.UserAction, m => { m[FixAllLogger.CorrelationId] = fixAllContext.State.CorrelationId; m[FixAllLogger.FixAllScope] = fixAllContext.State.Scope.ToString(); }), fixAllContext.CancellationToken)) { CodeAction action = null; try { action = await fixAllContext.FixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(false); } catch (OperationCanceledException) { FixAllLogger.LogComputationResult(fixAllContext.State.CorrelationId, completed: false); } finally { if (action != null) { FixAllLogger.LogComputationResult(fixAllContext.State.CorrelationId, completed: true); } else { FixAllLogger.LogComputationResult(fixAllContext.State.CorrelationId, completed: false, timedOut: true); } } return(action); } }
private async Task <CodeAction> GetFixAllCodeActionAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext) { using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken)) { CodeAction action = null; try { action = await fixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(false); } catch (OperationCanceledException) { FixAllLogger.LogComputationResult(completed: false); } finally { if (action != null) { FixAllLogger.LogComputationResult(completed: true); } else { FixAllLogger.LogComputationResult(completed: false, timedOut: true); } } return(action); } }
private CodeAction GetFixAllCodeAction(FixAllProvider fixAllProvider, FixAllContext fixAllContext, string fixAllTitle, string waitDialogMessage, out bool userCancelled) { userCancelled = false; // Compute fix all occurrences code fix for the given fix all context. // Bring up a cancellable wait dialog. CodeAction codeAction = null; using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken)) { var result = _waitIndicator.Wait( fixAllTitle, waitDialogMessage, allowCancel: true, action: waitContext => { fixAllContext.CancellationToken.ThrowIfCancellationRequested(); using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(waitContext.CancellationToken, fixAllContext.CancellationToken)) { try { var fixAllContextWithCancellation = fixAllContext.WithCancellationToken(linkedCts.Token); var fixTask = fixAllProvider.GetFixAsync(fixAllContextWithCancellation); if (fixTask != null) { codeAction = fixTask.WaitAndGetResult(linkedCts.Token); } } catch (OperationCanceledException) { fixAllContext.CancellationToken.ThrowIfCancellationRequested(); } } }); userCancelled = result == WaitIndicatorResult.Canceled; var cancelled = userCancelled || codeAction == null; if (cancelled) { FixAllLogger.LogComputationResult(completed: false, timedOut: result != WaitIndicatorResult.Canceled); return(null); } } FixAllLogger.LogComputationResult(completed: true); return(codeAction); }
public async Task <IEnumerable <CodeActionOperation> > GetFixAllOperationsAsync(FixAllProvider fixAllProvider, FixAllContext fixAllContext) { // Compute fix all occurrences code fix for the given fix all context. // Bring up a cancellable wait dialog. CodeAction codeAction = null; using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesComputation, fixAllContext.CancellationToken)) { var result = _waitIndicator.Wait( EditorFeaturesResources.FixAllOccurrences, EditorFeaturesResources.ComputingFixAllOccurrences, allowCancel: true, action: waitContext => { fixAllContext.CancellationToken.ThrowIfCancellationRequested(); using (var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(waitContext.CancellationToken, fixAllContext.CancellationToken)) { try { var fixAllContextWithCancellation = fixAllContext.WithCancellationToken(linkedCts.Token); var fixTask = fixAllProvider.GetFixAsync(fixAllContextWithCancellation); if (fixTask != null) { codeAction = fixTask.WaitAndGetResult(linkedCts.Token); } } catch (OperationCanceledException) { fixAllContext.CancellationToken.ThrowIfCancellationRequested(); } } }); var cancelled = result == WaitIndicatorResult.Canceled || codeAction == null; if (cancelled) { FixAllLogger.LogComputationResult(completed: false, timedOut: result != WaitIndicatorResult.Canceled); return(null); } } FixAllLogger.LogComputationResult(completed: true); return(await GetFixAllOperationsAsync(codeAction, fixAllContext).ConfigureAwait(false)); }
private static async Task <CodeAction> GetFixAllCodeActionAsync(IFixAllContext fixAllContext) { var fixAllKind = fixAllContext.State.FixAllKind; var functionId = fixAllKind switch { FixAllKind.CodeFix => FunctionId.CodeFixes_FixAllOccurrencesComputation, FixAllKind.Refactoring => FunctionId.Refactoring_FixAllOccurrencesComputation, _ => throw ExceptionUtilities.UnexpectedValue(fixAllKind) }; using (Logger.LogBlock( functionId, KeyValueLogMessage.Create(LogType.UserAction, m => { m[FixAllLogger.CorrelationId] = fixAllContext.State.CorrelationId; m[FixAllLogger.FixAllScope] = fixAllContext.State.Scope.ToString(); }), fixAllContext.CancellationToken)) { CodeAction action = null; try { action = await fixAllContext.FixAllProvider.GetFixAsync(fixAllContext).ConfigureAwait(false); } catch (OperationCanceledException) { FixAllLogger.LogComputationResult(fixAllKind, fixAllContext.State.CorrelationId, completed: false); } finally { if (action != null) { FixAllLogger.LogComputationResult(fixAllKind, fixAllContext.State.CorrelationId, completed: true); } else { FixAllLogger.LogComputationResult(fixAllKind, fixAllContext.State.CorrelationId, completed: false, timedOut: true); } } return(action); } }