Skip to content

Commit 31f1832

Browse files
authored
1 parent 7ffb51f commit 31f1832

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

src/vs/editor/contrib/inlineCompletions/browser/commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class AcceptNextWordOfInlineCompletion extends EditorAction {
9797

9898
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
9999
const controller = InlineCompletionsController.get(editor);
100-
controller?.model.get()?.acceptNextWord(controller.editor);
100+
await controller?.model.get()?.acceptNextWord(controller.editor);
101101
}
102102
}
103103

@@ -122,7 +122,7 @@ export class AcceptNextLineOfInlineCompletion extends EditorAction {
122122

123123
public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
124124
const controller = InlineCompletionsController.get(editor);
125-
controller?.model.get()?.acceptNextLine(controller.editor);
125+
await controller?.model.get()?.acceptNextLine(controller.editor);
126126
}
127127
}
128128

src/vs/editor/contrib/inlineCompletions/browser/inlineCompletionsModel.ts

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)