@@ -5,14 +5,15 @@ import { CodeActionParams, LanguageClient } from 'vscode-languageclient';
55import { Commands } from './commands' ;
66import { applyWorkspaceEdit } from './extension' ;
77import { ListOverridableMethodsRequest , AddOverridableMethodsRequest , CheckHashCodeEqualsStatusRequest , GenerateHashCodeEqualsRequest ,
8- OrganizeImportsRequest , ImportCandidate , ImportSelection , GenerateToStringRequest , CheckToStringStatusRequest , VariableField } from './protocol' ;
8+ OrganizeImportsRequest , ImportCandidate , ImportSelection , GenerateToStringRequest , CheckToStringStatusRequest , VariableField , ResolveUnimplementedAccessorsRequest , GenerateAccessorsRequest } from './protocol' ;
99
1010export function registerCommands ( languageClient : LanguageClient , context : ExtensionContext ) {
1111 registerOverrideMethodsCommand ( languageClient , context ) ;
1212 registerHashCodeEqualsCommand ( languageClient , context ) ;
1313 registerOrganizeImportsCommand ( languageClient , context ) ;
1414 registerChooseImportCommand ( context ) ;
1515 registerGenerateToStringCommand ( languageClient , context ) ;
16+ registerGenerateAccessorsCommand ( languageClient , context ) ;
1617}
1718
1819function registerOverrideMethodsCommand ( languageClient : LanguageClient , context : ExtensionContext ) : void {
@@ -202,3 +203,40 @@ function registerGenerateToStringCommand(languageClient: LanguageClient, context
202203 applyWorkspaceEdit ( workspaceEdit , languageClient ) ;
203204 } ) ) ;
204205}
206+
207+ function registerGenerateAccessorsCommand ( languageClient : LanguageClient , context : ExtensionContext ) : void {
208+ context . subscriptions . push ( commands . registerCommand ( Commands . GENERATE_ACCESSORS_PROMPT , async ( params : CodeActionParams ) => {
209+ const accessors = await languageClient . sendRequest ( ResolveUnimplementedAccessorsRequest . type , params ) ;
210+ if ( ! accessors || ! accessors . length ) {
211+ return ;
212+ }
213+
214+ const accessorItems = accessors . map ( ( accessor ) => {
215+ const description = [ ] ;
216+ if ( accessor . generateGetter ) {
217+ description . push ( 'getter' ) ;
218+ }
219+ if ( accessor . generateSetter ) {
220+ description . push ( 'setter' ) ;
221+ }
222+ return {
223+ label : accessor . fieldName ,
224+ description : ( accessor . isStatic ?'static ' :'' ) + description . join ( ', ' ) ,
225+ originalField : accessor ,
226+ } ;
227+ } ) ;
228+ const selectedAccessors = await window . showQuickPick ( accessorItems , {
229+ canPickMany : true ,
230+ placeHolder : 'Select the fields to generate getters and setters.'
231+ } ) ;
232+ if ( ! selectedAccessors . length ) {
233+ return ;
234+ }
235+
236+ const workspaceEdit = await languageClient . sendRequest ( GenerateAccessorsRequest . type , {
237+ context : params ,
238+ accessors : selectedAccessors . map ( ( item ) => item . originalField ) ,
239+ } ) ;
240+ applyWorkspaceEdit ( workspaceEdit , languageClient ) ;
241+ } ) ) ;
242+ }
0 commit comments