@@ -6,7 +6,8 @@ import { commands, ExtensionContext, Position, QuickPickItem, TextDocument, Uri,
66import { FormattingOptions , WorkspaceEdit , RenameFile , DeleteFile , TextDocumentEdit , CodeActionParams , SymbolInformation } from 'vscode-languageclient' ;
77import { LanguageClient } from 'vscode-languageclient/node' ;
88import { Commands as javaCommands } from './commands' ;
9- import { GetRefactorEditRequest , MoveRequest , RefactorWorkspaceEdit , RenamePosition , GetMoveDestinationsRequest , SearchSymbols , SelectionInfo , InferSelectionRequest , GetChangeSignatureInfoRequest , ChangeSignatureInfo , MoveParams } from './protocol' ;
9+ import { GetRefactorEditRequest , MoveRequest , RefactorWorkspaceEdit , RenamePosition , GetMoveDestinationsRequest , SearchSymbols , SelectionInfo , InferSelectionRequest , GetChangeSignatureInfoRequest , ChangeSignatureInfo , MoveParams , GetRefactorEditParams } from './protocol' ;
10+ import { requestWithConfirmation } from './refactoring/confirmation' ;
1011import { ChangeSignaturePanel } from './refactoring/changeSignaturePanel' ;
1112import { getExtractInterfaceArguments , revealExtractedInterface } from './refactoring/extractInterface' ;
1213
@@ -46,6 +47,9 @@ function registerApplyRefactorCommand(languageClient: LanguageClient, context: E
4647 || command === 'convertVariableToField'
4748 || command === 'invertVariable'
4849 || command === 'introduceParameter'
50+ || command === 'inlineMethod'
51+ || command === 'inlineConstant'
52+ || command === 'inlineLocalVariable'
4953 || command === 'convertAnonymousClassToNestedCommand' ) {
5054 const currentEditor = window . activeTextEditor ;
5155 if ( ! currentEditor || ! currentEditor . options ) {
@@ -121,16 +125,18 @@ function registerApplyRefactorCommand(languageClient: LanguageClient, context: E
121125 return ;
122126 }
123127
124- const result : RefactorWorkspaceEdit = await languageClient . sendRequest ( GetRefactorEditRequest . type , {
128+ const refactorParams : GetRefactorEditParams = {
125129 command,
126130 context : params ,
127131 options : formattingOptions ,
128132 commandArguments,
129- } ) ;
133+ } ;
134+ const result = await requestWithConfirmation ( refactorParams ,
135+ requestParams => languageClient . sendRequest ( GetRefactorEditRequest . type , requestParams ) ) ;
130136
131137 await applyRefactorEdit ( languageClient , result ) ;
132138
133- if ( command === 'extractInterface' ) {
139+ if ( command === 'extractInterface' && result ) {
134140 await revealExtractedInterface ( result ) ;
135141 }
136142 } else if ( command === 'moveFile' ) {
@@ -253,27 +259,8 @@ async function applyRefactorEdit(languageClient: LanguageClient, refactorEdit: R
253259}
254260
255261async function requestMoveWithConfirmation ( languageClient : LanguageClient , moveParams : MoveParams ) : Promise < RefactorWorkspaceEdit | undefined > {
256- let refactorEdit : RefactorWorkspaceEdit = await languageClient . sendRequest ( MoveRequest . type , moveParams ) ;
257- if ( ! refactorEdit ?. confirmationToken ) {
258- await applyRefactorEdit ( languageClient , refactorEdit ) ;
259- return refactorEdit ;
260- }
261-
262- const continueAction = 'Continue' ;
263- const detail = 'Review the details below before continuing:\n\n' + refactorEdit . errorMessage ;
264- const selection = await window . showWarningMessage (
265- 'This refactoring may change program behavior. Continue anyway?' ,
266- { modal : true , detail } ,
267- continueAction ,
268- ) ;
269- if ( selection !== continueAction ) {
270- return undefined ;
271- }
272-
273- refactorEdit = await languageClient . sendRequest ( MoveRequest . type , {
274- ...moveParams ,
275- confirmationToken : refactorEdit . confirmationToken ,
276- } ) ;
262+ const refactorEdit = await requestWithConfirmation ( moveParams ,
263+ requestParams => languageClient . sendRequest ( MoveRequest . type , requestParams ) ) ;
277264 await applyRefactorEdit ( languageClient , refactorEdit ) ;
278265 return refactorEdit ;
279266}
0 commit comments