From c8c67306472b6167e7530f804cb2c6c8ce06ffe7 Mon Sep 17 00:00:00 2001 From: Morgan Chang Date: Fri, 7 Aug 2026 16:18:59 -0400 Subject: [PATCH 1/2] implement confirmation for move instance method errors before applying edits Signed-off-by: Morgan Chang --- src/protocol.ts | 5 ++++- src/refactorAction.ts | 31 ++++++++++++++++++++++++++++--- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/protocol.ts b/src/protocol.ts index c31b5a590..8bd59fb39 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -350,9 +350,11 @@ export interface RenamePosition { } export interface RefactorWorkspaceEdit { - edit: WorkspaceEdit; + edit?: WorkspaceEdit; command?: Command; errorMessage?: string; + canContinue?: boolean; + confirmationToken?: string; } export interface GetRefactorEditParams { @@ -411,6 +413,7 @@ export interface MoveParams { params: CodeActionParams; destination?: any; updateReferences?: boolean; + confirmationToken?: string; } export interface MoveDestinationsResponse { diff --git a/src/refactorAction.ts b/src/refactorAction.ts index f8b37fb54..826dfcf6f 100644 --- a/src/refactorAction.ts +++ b/src/refactorAction.ts @@ -6,7 +6,7 @@ import { commands, ExtensionContext, Position, QuickPickItem, TextDocument, Uri, import { FormattingOptions, WorkspaceEdit, RenameFile, DeleteFile, TextDocumentEdit, CodeActionParams, SymbolInformation } from 'vscode-languageclient'; import { LanguageClient } from 'vscode-languageclient/node'; import { Commands as javaCommands } from './commands'; -import { GetRefactorEditRequest, MoveRequest, RefactorWorkspaceEdit, RenamePosition, GetMoveDestinationsRequest, SearchSymbols, SelectionInfo, InferSelectionRequest, GetChangeSignatureInfoRequest, ChangeSignatureInfo } from './protocol'; +import { GetRefactorEditRequest, MoveRequest, RefactorWorkspaceEdit, RenamePosition, GetMoveDestinationsRequest, SearchSymbols, SelectionInfo, InferSelectionRequest, GetChangeSignatureInfoRequest, ChangeSignatureInfo, MoveParams } from './protocol'; import { ChangeSignaturePanel } from './refactoring/changeSignaturePanel'; import { getExtractInterfaceArguments, revealExtractedInterface } from './refactoring/extractInterface'; @@ -252,6 +252,32 @@ async function applyRefactorEdit(languageClient: LanguageClient, refactorEdit: R } } +async function requestMoveWithConfirmation(languageClient: LanguageClient, moveParams: MoveParams): Promise { + let refactorEdit: RefactorWorkspaceEdit = await languageClient.sendRequest(MoveRequest.type, moveParams); + if (!refactorEdit?.canContinue || !refactorEdit.confirmationToken) { + await applyRefactorEdit(languageClient, refactorEdit); + return refactorEdit; + } + + const continueAction = 'Continue'; + const detail = 'Review the details below before continuing:\n\n' + refactorEdit.errorMessage; + const selection = await window.showWarningMessage( + 'This refactoring may change program behavior. Continue anyway?', + { modal: true, detail }, + continueAction, + ); + if (selection !== continueAction) { + return undefined; + } + + refactorEdit = await languageClient.sendRequest(MoveRequest.type, { + ...moveParams, + confirmationToken: refactorEdit.confirmationToken, + }); + await applyRefactorEdit(languageClient, refactorEdit); + return refactorEdit; +} + async function moveFile(languageClient: LanguageClient, fileUris: Uri[]) { if (!hasCommonParent(fileUris)) { window.showErrorMessage("Moving files from different directories are not supported. Please make sure they are from the same directory."); @@ -417,13 +443,12 @@ async function moveInstanceMethod(languageClient: LanguageClient, params: CodeAc return; } - const refactorEdit: RefactorWorkspaceEdit = await languageClient.sendRequest(MoveRequest.type, { + await requestMoveWithConfirmation(languageClient, { moveKind: 'moveInstanceMethod', sourceUris: [ params.textDocument.uri ], params, destination: selected.destination, }); - await applyRefactorEdit(languageClient, refactorEdit); } async function moveStaticMember(languageClient: LanguageClient, params: CodeActionParams, commandInfo: any) { From 7f7622199cfd25116a92446ed9f7583bb73e65fd Mon Sep 17 00:00:00 2001 From: Morgan Chang Date: Thu, 13 Aug 2026 14:52:27 -0400 Subject: [PATCH 2/2] advertise support for move refactoring confirmation Signed-off-by: Morgan Chang --- src/extension.ts | 1 + src/protocol.ts | 1 - src/refactorAction.ts | 2 +- 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/extension.ts b/src/extension.ts index 8679e85e9..77d5866dc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -255,6 +255,7 @@ export async function activate(context: ExtensionContext): Promise advancedExtractRefactoringSupport: true, inferSelectionSupport: ["extractMethod", "extractVariable", "extractField"], moveRefactoringSupport: true, + moveRefactoringConfirmationSupport: true, clientHoverProvider: true, clientDocumentSymbolProvider: true, gradleChecksumWrapperPromptSupport: true, diff --git a/src/protocol.ts b/src/protocol.ts index 8bd59fb39..6e9f61b9d 100644 --- a/src/protocol.ts +++ b/src/protocol.ts @@ -353,7 +353,6 @@ export interface RefactorWorkspaceEdit { edit?: WorkspaceEdit; command?: Command; errorMessage?: string; - canContinue?: boolean; confirmationToken?: string; } diff --git a/src/refactorAction.ts b/src/refactorAction.ts index 826dfcf6f..b675f6408 100644 --- a/src/refactorAction.ts +++ b/src/refactorAction.ts @@ -254,7 +254,7 @@ async function applyRefactorEdit(languageClient: LanguageClient, refactorEdit: R async function requestMoveWithConfirmation(languageClient: LanguageClient, moveParams: MoveParams): Promise { let refactorEdit: RefactorWorkspaceEdit = await languageClient.sendRequest(MoveRequest.type, moveParams); - if (!refactorEdit?.canContinue || !refactorEdit.confirmationToken) { + if (!refactorEdit?.confirmationToken) { await applyRefactorEdit(languageClient, refactorEdit); return refactorEdit; }