@@ -191,6 +191,19 @@ class MyCompletionItem extends vscode.CompletionItem {
191191 }
192192}
193193
194+ class CompositeCommand implements Command {
195+ public static readonly ID = '_typescript.composite' ;
196+ public readonly id = CompositeCommand . ID ;
197+
198+ public execute ( ...commands : vscode . Command [ ] ) {
199+ for ( const command of commands ) {
200+ vscode . commands . executeCommand ( command . command , ...( command . arguments || [ ] ) ) ;
201+ }
202+ }
203+ }
204+
205+ const completionAcceptedCommandId = '_typescript.onCompletionAccepted' ;
206+
194207class ApplyCompletionCodeActionCommand implements Command {
195208 public static readonly ID = '_typescript.applyCompletionCodeAction' ;
196209 public readonly id = ApplyCompletionCodeActionCommand . ID ;
@@ -273,6 +286,7 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider
273286 commandManager : CommandManager
274287 ) {
275288 commandManager . register ( new ApplyCompletionCodeActionCommand ( this . client ) ) ;
289+ commandManager . register ( new CompositeCommand ( ) ) ;
276290 }
277291
278292 public async provideCompletionItems (
@@ -387,15 +401,34 @@ class TypeScriptCompletionItemProvider implements vscode.CompletionItemProvider
387401 item . detail = detail . displayParts . length ? Previewer . plain ( detail . displayParts ) : undefined ;
388402 item . documentation = this . getDocumentation ( detail , item ) ;
389403
390- const { command, additionalTextEdits } = this . getCodeActions ( detail , filepath ) ;
391- item . command = command ;
392- item . additionalTextEdits = additionalTextEdits ;
404+ const codeAction = this . getCodeActions ( detail , filepath ) ;
405+ const commands : vscode . Command [ ] = [ {
406+ command : completionAcceptedCommandId ,
407+ title : '' ,
408+ arguments : [ item ]
409+ } ] ;
410+ if ( codeAction . command ) {
411+ commands . push ( codeAction . command ) ;
412+ }
413+ item . additionalTextEdits = codeAction . additionalTextEdits ;
393414
394415 if ( detail && item . useCodeSnippet ) {
395416 const shouldCompleteFunction = await this . isValidFunctionCompletionContext ( filepath , item . position , token ) ;
396417 if ( shouldCompleteFunction ) {
397418 item . insertText = this . snippetForFunctionCall ( item , detail ) ;
398- item . command = { title : 'triggerParameterHints' , command : 'editor.action.triggerParameterHints' } ;
419+ commands . push ( { title : 'triggerParameterHints' , command : 'editor.action.triggerParameterHints' } ) ;
420+ }
421+ }
422+
423+ if ( commands . length ) {
424+ if ( commands . length === 1 ) {
425+ item . command = commands [ 0 ] ;
426+ } else {
427+ item . command = {
428+ command : CompositeCommand . ID ,
429+ title : '' ,
430+ arguments : commands
431+ } ;
399432 }
400433 }
401434
0 commit comments