Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
hediet committed Jul 7, 2023
1 parent 7ffb51f commit 31f1832
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/vs/editor/contrib/inlineCompletions/browser/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class AcceptNextWordOfInlineCompletion extends EditorAction {

public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
const controller = InlineCompletionsController.get(editor);
controller?.model.get()?.acceptNextWord(controller.editor);
await controller?.model.get()?.acceptNextWord(controller.editor);
}
}

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

public async run(accessor: ServicesAccessor | undefined, editor: ICodeEditor): Promise<void> {
const controller = InlineCompletionsController.get(editor);
controller?.model.get()?.acceptNextLine(controller.editor);
await controller?.model.get()?.acceptNextLine(controller.editor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,20 +306,28 @@ export class InlineCompletionsModel extends Disposable {
}

if (completion.command) {
await this._commandService
.executeCommand(completion.command.id, ...(completion.command.arguments || []))
.then(undefined, onUnexpectedExternalError);
// Make sure the completion list will not be disposed.
completion.source.addRef();
}

// Reset before invoking the command, since the command might cause a follow up trigger.
transaction(tx => {
this._source.clear(tx);
// Potentially, isActive will get set back to true by the typing or accept inline suggest event
// if automatic inline suggestions are enabled.
this._isActive.set(false, tx);
});

if (completion.command) {
await this._commandService
.executeCommand(completion.command.id, ...(completion.command.arguments || []))
.then(undefined, onUnexpectedExternalError);
completion.source.removeRef();
}
}

public acceptNextWord(editor: ICodeEditor): void {
this._acceptNext(editor, (pos, text) => {
public async acceptNextWord(editor: ICodeEditor): Promise<void> {
await this._acceptNext(editor, (pos, text) => {
const langId = this.textModel.getLanguageIdAtPosition(pos.lineNumber, pos.column);
const config = this._languageConfigurationService.getLanguageConfiguration(langId);
const wordRegExp = new RegExp(config.wordDefinition.source, config.wordDefinition.flags.replace('g', ''));
Expand Down Expand Up @@ -347,8 +355,8 @@ export class InlineCompletionsModel extends Disposable {
});
}

public acceptNextLine(editor: ICodeEditor): void {
this._acceptNext(editor, (pos, text) => {
public async acceptNextLine(editor: ICodeEditor): Promise<void> {
await this._acceptNext(editor, (pos, text) => {
const m = text.match(/\n/);
if (m && m.index !== undefined) {
return m.index + 1;
Expand All @@ -357,7 +365,7 @@ export class InlineCompletionsModel extends Disposable {
});
}

private _acceptNext(editor: ICodeEditor, getAcceptUntilIndex: (position: Position, text: string) => number): void {
private async _acceptNext(editor: ICodeEditor, getAcceptUntilIndex: (position: Position, text: string) => number): Promise<void> {
if (editor.getModel() !== this.textModel) {
throw new BugIndicatingError();
}
Expand All @@ -370,7 +378,7 @@ export class InlineCompletionsModel extends Disposable {

if (completion.snippetInfo || completion.filterText !== completion.insertText) {
// not in WYSIWYG mode, partial commit might change completion, thus it is not supported
this.accept(editor);
await this.accept(editor);
return;
}

Expand Down

0 comments on commit 31f1832

Please sign in to comment.