internal static Solution PreviewChanges( Solution currentSolution, Solution newSolution, string fixAllPreviewChangesTitle, string fixAllTopLevelHeader, string languageOpt, Workspace workspace, int?correlationId = null, CancellationToken cancellationToken = default) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock( FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, KeyValueLogMessage.Create(LogType.UserAction, m => { // only set when correlation id is given // we might not have this info for suppression if (correlationId.HasValue) { m[FixAllLogger.CorrelationId] = correlationId; } }), cancellationToken)) { var previewService = workspace.Services.GetService <IPreviewDialogService>(); var glyph = languageOpt == null ? Glyph.Assembly : languageOpt == LanguageNames.CSharp ? Glyph.CSharpProject : Glyph.BasicProject; // Until IPreviewDialogService is implemented, just execute all changes without user ability to pick and choose if (previewService == null) { return(newSolution); } var changedSolution = previewService.PreviewChanges( string.Format(EditorFeaturesResources.Preview_Changes_0, fixAllPreviewChangesTitle), "vs.codefix.fixall", fixAllTopLevelHeader, fixAllPreviewChangesTitle, glyph, newSolution, currentSolution); if (changedSolution == null) { // User clicked cancel. FixAllLogger.LogPreviewChangesResult(correlationId, applied: false); return(null); } FixAllLogger.LogPreviewChangesResult(correlationId, applied: true, allChangesApplied: changedSolution == newSolution); return(changedSolution); } }
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)); }
internal static Solution PreviewChanges( Solution currentSolution, Solution newSolution, string fixAllPreviewChangesTitle, string fixAllTopLevelHeader, string languageOpt, Workspace workspace, CancellationToken cancellationToken = default(CancellationToken)) { cancellationToken.ThrowIfCancellationRequested(); using (Logger.LogBlock(FunctionId.CodeFixes_FixAllOccurrencesPreviewChanges, cancellationToken)) { var previewService = workspace.Services.GetService <IPreviewDialogService>(); var glyph = languageOpt == null ? Glyph.Assembly : languageOpt == LanguageNames.CSharp ? Glyph.CSharpProject : Glyph.BasicProject; var changedSolution = previewService.PreviewChanges( string.Format(EditorFeaturesResources.PreviewChangesOf, fixAllPreviewChangesTitle), "vs.codefix.fixall", fixAllTopLevelHeader, fixAllPreviewChangesTitle, glyph, newSolution, currentSolution); if (changedSolution == null) { // User clicked cancel. FixAllLogger.LogPreviewChangesResult(applied: false); return(null); } FixAllLogger.LogPreviewChangesResult(applied: true, allChangesApplied: changedSolution == newSolution); return(changedSolution); } }