@@ -306,20 +306,28 @@ export class InlineCompletionsModel extends Disposable {
306306 }
307307
308308 if ( completion . command ) {
309- await this . _commandService
310- . executeCommand ( completion . command . id , ...( completion . command . arguments || [ ] ) )
311- . then ( undefined , onUnexpectedExternalError ) ;
309+ // Make sure the completion list will not be disposed.
310+ completion . source . addRef ( ) ;
312311 }
312+
313+ // Reset before invoking the command, since the command might cause a follow up trigger.
313314 transaction ( tx => {
314315 this . _source . clear ( tx ) ;
315316 // Potentially, isActive will get set back to true by the typing or accept inline suggest event
316317 // if automatic inline suggestions are enabled.
317318 this . _isActive . set ( false , tx ) ;
318319 } ) ;
320+
321+ if ( completion . command ) {
322+ await this . _commandService
323+ . executeCommand ( completion . command . id , ...( completion . command . arguments || [ ] ) )
324+ . then ( undefined , onUnexpectedExternalError ) ;
325+ completion . source . removeRef ( ) ;
326+ }
319327 }
320328
321- public acceptNextWord ( editor : ICodeEditor ) : void {
322- this . _acceptNext ( editor , ( pos , text ) => {
329+ public async acceptNextWord ( editor : ICodeEditor ) : Promise < void > {
330+ await this . _acceptNext ( editor , ( pos , text ) => {
323331 const langId = this . textModel . getLanguageIdAtPosition ( pos . lineNumber , pos . column ) ;
324332 const config = this . _languageConfigurationService . getLanguageConfiguration ( langId ) ;
325333 const wordRegExp = new RegExp ( config . wordDefinition . source , config . wordDefinition . flags . replace ( 'g' , '' ) ) ;
@@ -347,8 +355,8 @@ export class InlineCompletionsModel extends Disposable {
347355 } ) ;
348356 }
349357
350- public acceptNextLine ( editor : ICodeEditor ) : void {
351- this . _acceptNext ( editor , ( pos , text ) => {
358+ public async acceptNextLine ( editor : ICodeEditor ) : Promise < void > {
359+ await this . _acceptNext ( editor , ( pos , text ) => {
352360 const m = text . match ( / \n / ) ;
353361 if ( m && m . index !== undefined ) {
354362 return m . index + 1 ;
@@ -357,7 +365,7 @@ export class InlineCompletionsModel extends Disposable {
357365 } ) ;
358366 }
359367
360- private _acceptNext ( editor : ICodeEditor , getAcceptUntilIndex : ( position : Position , text : string ) => number ) : void {
368+ private async _acceptNext ( editor : ICodeEditor , getAcceptUntilIndex : ( position : Position , text : string ) => number ) : Promise < void > {
361369 if ( editor . getModel ( ) !== this . textModel ) {
362370 throw new BugIndicatingError ( ) ;
363371 }
@@ -370,7 +378,7 @@ export class InlineCompletionsModel extends Disposable {
370378
371379 if ( completion . snippetInfo || completion . filterText !== completion . insertText ) {
372380 // not in WYSIWYG mode, partial commit might change completion, thus it is not supported
373- this . accept ( editor ) ;
381+ await this . accept ( editor ) ;
374382 return ;
375383 }
376384
0 commit comments