public Solution GetChangedSolution(CancellationToken cancellationToken) { Solution newSolution = null; var extensionManager = this.Workspace.Services.GetService <IExtensionManager>(); extensionManager.PerformAction(Provider, () => { newSolution = CodeAction.GetChangedSolutionInternalAsync(cancellationToken).WaitAndGetResult(cancellationToken); }); return(newSolution); }
public Solution GetChangedSolution(CancellationToken cancellationToken) { Solution newSolution = null; var extensionManager = this.Workspace.Services.GetService <IExtensionManager>(); extensionManager.PerformAction(Provider, () => { // We don't need to post process changes here as the inner code action created for Fix multiple code fix already executes. newSolution = CodeAction.GetChangedSolutionInternalAsync(postProcessChanges: false, cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken); }); return(newSolution); }
private async Task <IEnumerable <CodeActionOperation> > GetFixAllOperationsAsync(CodeAction codeAction, FixAllContext fixAllContext) { // We have computed the fix all occurrences code fix. // Now fetch the new solution with applied fix and bring up the Preview changes dialog. var cancellationToken = fixAllContext.CancellationToken; var workspace = fixAllContext.Project.Solution.Workspace; cancellationToken.ThrowIfCancellationRequested(); var operations = await codeAction.GetOperationsAsync(cancellationToken).ConfigureAwait(false); if (operations == null) { return(null); } cancellationToken.ThrowIfCancellationRequested(); var newSolution = await codeAction.GetChangedSolutionInternalAsync(cancellationToken).ConfigureAwait(false); cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, cancellationToken)) { var previewService = workspace.Services.GetService <IPreviewDialogService>(); var glyph = fixAllContext.Project.Language == LanguageNames.CSharp ? Glyph.CSharpProject : Glyph.BasicProject; var changedSolution = previewService.PreviewChanges( string.Format(EditorFeaturesResources.PreviewChangesOf, EditorFeaturesResources.FixAllOccurrences), "vs.codefix.fixall", codeAction.Title, EditorFeaturesResources.FixAllOccurrences, glyph, newSolution, fixAllContext.Project.Solution); if (changedSolution == null) { // User clicked cancel. FixAllLogger.LogPreviewChangesResult(applied: false); return(null); } FixAllLogger.LogPreviewChangesResult(applied: true, allChangesApplied: changedSolution == newSolution); newSolution = changedSolution; } // Get a code action, with apply changes operation replaced with the newSolution. return(GetNewFixAllOperations(operations, newSolution, cancellationToken)); }
private static async Task <ImmutableArray <CodeActionOperation> > GetFixAllOperationsAsync( CodeAction codeAction, bool showPreviewChangesDialog, FixAllState fixAllState, CancellationToken cancellationToken ) { // We have computed the fix all occurrences code fix. // Now fetch the new solution with applied fix and bring up the Preview changes dialog. var workspace = fixAllState.Project.Solution.Workspace; cancellationToken.ThrowIfCancellationRequested(); var operations = await codeAction .GetOperationsAsync(cancellationToken) .ConfigureAwait(false); if (operations == null) { return(ImmutableArray <CodeActionOperation> .Empty); } cancellationToken.ThrowIfCancellationRequested(); var newSolution = await codeAction .GetChangedSolutionInternalAsync(cancellationToken : cancellationToken) .ConfigureAwait(false); if (showPreviewChangesDialog) { newSolution = PreviewChanges( fixAllState.Project.Solution, newSolution, FeaturesResources.Fix_all_occurrences, codeAction.Title, fixAllState.Project.Language, workspace, fixAllState.CorrelationId, cancellationToken ); if (newSolution == null) { return(ImmutableArray <CodeActionOperation> .Empty); } } // Get a code action, with apply changes operation replaced with the newSolution. return(GetNewFixAllOperations(operations, newSolution, cancellationToken)); }
private async Task <IEnumerable <CodeActionOperation> > GetFixAllOperationsAsync(CodeAction codeAction, FixAllContext fixAllContext, string fixAllPreviewChangesTitle, bool showPreviewChangesDialog) { // We have computed the fix all occurrences code fix. // Now fetch the new solution with applied fix and bring up the Preview changes dialog. var cancellationToken = fixAllContext.CancellationToken; var workspace = fixAllContext.Project.Solution.Workspace; cancellationToken.ThrowIfCancellationRequested(); var operations = await codeAction.GetOperationsAsync(cancellationToken).ConfigureAwait(false); if (operations == null) { return(null); } cancellationToken.ThrowIfCancellationRequested(); var newSolution = await codeAction.GetChangedSolutionInternalAsync(cancellationToken : cancellationToken).ConfigureAwait(false); if (showPreviewChangesDialog) { newSolution = PreviewChanges( fixAllContext.Project.Solution, newSolution, fixAllPreviewChangesTitle, codeAction.Title, fixAllContext.Project.Language, workspace, cancellationToken); if (newSolution == null) { return(null); } } // Get a code action, with apply changes operation replaced with the newSolution. return(GetNewFixAllOperations(operations, newSolution, cancellationToken)); }