@@ -6,8 +6,8 @@ import * as fse from 'fs-extra';
6
6
import * as os from 'os' ;
7
7
import * as path from 'path' ;
8
8
import * as semver from 'semver' ;
9
- import { CodeActionContext , commands , CompletionItem , ConfigurationTarget , Diagnostic , env , EventEmitter , ExtensionContext , extensions , IndentAction , InputBoxOptions , languages , MarkdownString , QuickPickItemKind , RelativePattern , TextDocument , TextEditorRevealType , UIKind , Uri , ViewColumn , window , workspace , WorkspaceConfiguration } from 'vscode' ;
10
- import { CancellationToken , CodeActionParams , CodeActionRequest , Command , CompletionRequest , DidChangeConfigurationNotification , ExecuteCommandParams , ExecuteCommandRequest , LanguageClientOptions , RevealOutputChannelOn } from 'vscode-languageclient' ;
9
+ import { CodeActionContext , commands , CompletionItem , ConfigurationTarget , Diagnostic , env , EventEmitter , ExtensionContext , extensions , IndentAction , InputBoxOptions , languages , MarkdownString , QuickPickItemKind , Range , RelativePattern , SnippetString , SnippetTextEdit , TextDocument , TextEditorRevealType , UIKind , Uri , ViewColumn , window , workspace , WorkspaceConfiguration , WorkspaceEdit } from 'vscode' ;
10
+ import { CancellationToken , CodeActionParams , CodeActionRequest , CodeActionResolveRequest , Command , CompletionRequest , DidChangeConfigurationNotification , ExecuteCommandParams , ExecuteCommandRequest , LanguageClientOptions , RevealOutputChannelOn } from 'vscode-languageclient' ;
11
11
import { LanguageClient } from 'vscode-languageclient/node' ;
12
12
import { apiManager } from './apiManager' ;
13
13
import { ClientErrorHandler } from './clientErrorHandler' ;
@@ -235,6 +235,7 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
235
235
extractInterfaceSupport : true ,
236
236
advancedUpgradeGradleSupport : true ,
237
237
executeClientCommandSupport : true ,
238
+ snippetEditSupport : true ,
238
239
} ,
239
240
triggerFiles,
240
241
} ,
@@ -303,7 +304,60 @@ export async function activate(context: ExtensionContext): Promise<ExtensionAPI>
303
304
} , ( error ) => {
304
305
return client . handleFailedRequest ( CodeActionRequest . type , token , error , [ ] ) ;
305
306
} ) ;
306
- }
307
+ } ,
308
+
309
+ resolveCodeAction : async ( item , token , next ) => {
310
+ const client : LanguageClient = standardClient . getClient ( ) ;
311
+ const documentUris = [ ] ;
312
+ const snippetEdits = [ ] ;
313
+ const resolveCodeAction = async ( item , token ) => {
314
+ return client . sendRequest ( CodeActionResolveRequest . type , client . code2ProtocolConverter . asCodeActionSync ( item ) , token ) . then ( async ( result ) => {
315
+ if ( token . isCancellationRequested ) {
316
+ return item ;
317
+ }
318
+ const docChanges = result . edit !== undefined ? result . edit . documentChanges : undefined ;
319
+ if ( docChanges !== undefined ) {
320
+ for ( const docChange of docChanges ) {
321
+ if ( "textDocument" in docChange ) {
322
+ for ( const edit of docChange . edits ) {
323
+ if ( "snippet" in edit ) {
324
+ documentUris . push ( docChange . textDocument . uri ) ;
325
+ snippetEdits . push ( new SnippetTextEdit ( client . protocol2CodeConverter . asRange ( ( edit as any ) . range ) , new SnippetString ( ( edit as any ) . snippet . value ) ) ) ;
326
+ }
327
+ }
328
+ }
329
+ }
330
+ const codeAction = await client . protocol2CodeConverter . asCodeAction ( result , token ) ;
331
+ const docEdits = codeAction . edit !== undefined ? codeAction . edit . entries ( ) : [ ] ;
332
+ for ( const docEdit of docEdits ) {
333
+ const uri = docEdit [ 0 ] ;
334
+ if ( documentUris . includes ( uri . toString ( ) ) ) {
335
+ const editList = [ ] ;
336
+ for ( const edit of docEdit [ 1 ] ) {
337
+ let isSnippet = false ;
338
+ snippetEdits . forEach ( ( snippet , index ) => {
339
+ if ( edit . range . isEqual ( snippet . range ) && documentUris [ index ] === uri . toString ( ) ) {
340
+ editList . push ( snippet ) ;
341
+ isSnippet = true ;
342
+ }
343
+ } ) ;
344
+ if ( ! isSnippet ) {
345
+ editList . push ( edit ) ;
346
+ }
347
+ }
348
+ codeAction . edit . set ( uri , null ) ;
349
+ codeAction . edit . set ( uri , editList ) ;
350
+ }
351
+ }
352
+ return codeAction ;
353
+ }
354
+ return await client . protocol2CodeConverter . asCodeAction ( result , token ) ;
355
+ } , ( error ) => {
356
+ return client . handleFailedRequest ( CodeActionResolveRequest . type , token , error , item ) ;
357
+ } ) ;
358
+ } ;
359
+ return resolveCodeAction ( item , token ) ;
360
+ } ,
307
361
} ,
308
362
revealOutputChannelOn : RevealOutputChannelOn . Never ,
309
363
errorHandler : new ClientErrorHandler ( extensionName ) ,
@@ -1189,5 +1243,3 @@ function registerRestartJavaLanguageServerCommand(context: ExtensionContext) {
1189
1243
}
1190
1244
} ) ) ;
1191
1245
}
1192
-
1193
-
0 commit comments