@@ -306,20 +306,28 @@ export class InlineCompletionsModel extends Disposable {
306
306
}
307
307
308
308
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 ( ) ;
312
311
}
312
+
313
+ // Reset before invoking the command, since the command might cause a follow up trigger.
313
314
transaction ( tx => {
314
315
this . _source . clear ( tx ) ;
315
316
// Potentially, isActive will get set back to true by the typing or accept inline suggest event
316
317
// if automatic inline suggestions are enabled.
317
318
this . _isActive . set ( false , tx ) ;
318
319
} ) ;
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
+ }
319
327
}
320
328
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 ) => {
323
331
const langId = this . textModel . getLanguageIdAtPosition ( pos . lineNumber , pos . column ) ;
324
332
const config = this . _languageConfigurationService . getLanguageConfiguration ( langId ) ;
325
333
const wordRegExp = new RegExp ( config . wordDefinition . source , config . wordDefinition . flags . replace ( 'g' , '' ) ) ;
@@ -347,8 +355,8 @@ export class InlineCompletionsModel extends Disposable {
347
355
} ) ;
348
356
}
349
357
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 ) => {
352
360
const m = text . match ( / \n / ) ;
353
361
if ( m && m . index !== undefined ) {
354
362
return m . index + 1 ;
@@ -357,7 +365,7 @@ export class InlineCompletionsModel extends Disposable {
357
365
} ) ;
358
366
}
359
367
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 > {
361
369
if ( editor . getModel ( ) !== this . textModel ) {
362
370
throw new BugIndicatingError ( ) ;
363
371
}
@@ -370,7 +378,7 @@ export class InlineCompletionsModel extends Disposable {
370
378
371
379
if ( completion . snippetInfo || completion . filterText !== completion . insertText ) {
372
380
// not in WYSIWYG mode, partial commit might change completion, thus it is not supported
373
- this . accept ( editor ) ;
381
+ await this . accept ( editor ) ;
374
382
return ;
375
383
}
376
384
0 commit comments