@@ -28,11 +28,13 @@ function registerApplyRefactorCommand(languageClient: LanguageClient, context: E
2828 }
2929 } ) ) ;
3030
31- context . subscriptions . push ( commands . registerCommand ( javaCommands . APPLY_REFACTORING_COMMAND , async ( command : string , params : any ) => {
31+ context . subscriptions . push ( commands . registerCommand ( javaCommands . APPLY_REFACTORING_COMMAND , async ( command : string , params : any , commandInfo : any ) => {
3232 if ( command === 'extractVariable'
3333 || command === 'extractVariableAllOccurrence'
3434 || command === 'extractConstant'
35- || command === 'extractMethod' ) {
35+ || command === 'extractMethod'
36+ || command === 'extractField'
37+ || command === 'convertVariableToField' ) {
3638 const currentEditor = window . activeTextEditor ;
3739 if ( ! currentEditor || ! currentEditor . options ) {
3840 return ;
@@ -42,10 +44,32 @@ function registerApplyRefactorCommand(languageClient: LanguageClient, context: E
4244 tabSize : < number > currentEditor . options . tabSize ,
4345 insertSpaces : < boolean > currentEditor . options . insertSpaces ,
4446 } ;
47+ const commandArguments : any [ ] = [ ] ;
48+ if ( command === 'extractField' || command === 'convertVariableToField' ) {
49+ if ( commandInfo . initializedScopes && Array . isArray ( commandInfo . initializedScopes ) ) {
50+ const scopes : any [ ] = commandInfo . initializedScopes ;
51+ let initializeIn : string ;
52+ if ( scopes . length === 1 ) {
53+ initializeIn = scopes [ 0 ] ;
54+ } else if ( scopes . length > 1 ) {
55+ initializeIn = await window . showQuickPick ( scopes , {
56+ placeHolder : "Initialize the field in" ,
57+ } ) ;
58+
59+ if ( ! initializeIn ) {
60+ return ;
61+ }
62+ }
63+
64+ commandArguments . push ( initializeIn ) ;
65+ }
66+ }
67+
4568 const result : RefactorWorkspaceEdit = await languageClient . sendRequest ( GetRefactorEditRequest . type , {
4669 command,
4770 context : params ,
4871 options : formattingOptions ,
72+ commandArguments,
4973 } ) ;
5074
5175 if ( ! result || ! result . edit ) {
0 commit comments