Skip to content

Commit 50f0247

Browse files
committed
Dont debounce inline completion request after accepting an inline completion
1 parent c2e0bcb commit 50f0247

File tree

4 files changed

+20
-7
lines changed

4 files changed

+20
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class TriggerInlineEditAction extends EditorCommand {
113113

114114
public override async runEditorCommand(accessor: ServicesAccessor | null, editor: ICodeEditor, args: { triggerKind?: 'automatic' | 'explicit' }): Promise<void> {
115115
const controller = InlineCompletionsController.get(editor);
116-
await controller?.model.get()?.trigger(undefined, true);
116+
await controller?.model.get()?.trigger(undefined, { onlyFetchInlineEdits: true });
117117
}
118118
}
119119

src/vs/editor/contrib/inlineCompletions/browser/controller/inlineCompletionsController.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,13 @@ export class InlineCompletionsController extends Disposable {
175175
'acceptSelectedSuggestion',
176176
]);
177177
if (commands.has(e.commandId) && editor.hasTextFocus() && this._enabled.get()) {
178+
let noDelay = false;
179+
if (e.commandId === inlineSuggestCommitId) {
180+
noDelay = true;
181+
}
178182
this._editorObs.forceUpdate(tx => {
179183
/** @description onDidExecuteCommand */
180-
this.model.get()?.trigger(tx);
184+
this.model.get()?.trigger(tx, { noDelay });
181185
});
182186
}
183187
}));

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export class InlineCompletionsModel extends Disposable {
4444
private readonly _isActive = observableValue<boolean>(this, false);
4545
private readonly _onlyRequestInlineEditsSignal = observableSignal(this);
4646
private readonly _forceUpdateExplicitlySignal = observableSignal(this);
47+
private readonly _noDelaySignal = observableSignal(this);
4748

4849
// We use a semantic id to keep the same inline completion selected even if the provider reorders the completions.
4950
private readonly _selectedInlineCompletionId = observableValue<string | undefined>(this, undefined);
@@ -167,6 +168,7 @@ export class InlineCompletionsModel extends Disposable {
167168
preserveCurrentCompletion: false,
168169
inlineCompletionTriggerKind: InlineCompletionTriggerKind.Automatic,
169170
onlyRequestInlineEdits: false,
171+
shouldDebounce: true,
170172
}),
171173
handleChange: (ctx, changeSummary) => {
172174
/** @description fetch inline completions */
@@ -178,10 +180,13 @@ export class InlineCompletionsModel extends Disposable {
178180
changeSummary.dontRefetch = true;
179181
} else if (ctx.didChange(this._onlyRequestInlineEditsSignal)) {
180182
changeSummary.onlyRequestInlineEdits = true;
183+
} else if (ctx.didChange(this._noDelaySignal)) {
184+
changeSummary.shouldDebounce = false;
181185
}
182186
return true;
183187
},
184188
}, (reader, changeSummary) => {
189+
this._noDelaySignal.read(reader);
185190
this.dontRefetchSignal.read(reader);
186191
this._onlyRequestInlineEditsSignal.read(reader);
187192
this._forceUpdateExplicitlySignal.read(reader);
@@ -220,14 +225,17 @@ export class InlineCompletionsModel extends Disposable {
220225
const itemToPreserveCandidate = this.selectedInlineCompletion.get() ?? this._inlineCompletionItems.get()?.inlineEdit;
221226
const itemToPreserve = changeSummary.preserveCurrentCompletion || itemToPreserveCandidate?.forwardStable
222227
? itemToPreserveCandidate : undefined;
223-
return this._source.fetch(cursorPosition, context, itemToPreserve);
228+
return this._source.fetch(cursorPosition, context, itemToPreserve, changeSummary.shouldDebounce);
224229
});
225230

226-
public async trigger(tx?: ITransaction, onlyFetchInlineEdits: boolean = false): Promise<void> {
231+
public async trigger(tx?: ITransaction, options?: { onlyFetchInlineEdits?: boolean; noDelay?: boolean }): Promise<void> {
227232
subtransaction(tx, tx => {
228-
if (onlyFetchInlineEdits) {
233+
if (options?.onlyFetchInlineEdits) {
229234
this._onlyRequestInlineEditsSignal.trigger(tx);
230235
}
236+
if (options?.noDelay) {
237+
this._noDelaySignal.trigger(tx);
238+
}
231239
this._isActive.set(true, tx);
232240
});
233241
await this._fetchInlineCompletionsPromise.get();

src/vs/editor/contrib/inlineCompletions/browser/model/inlineCompletionsSource.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ export class InlineCompletionsSource extends Disposable {
7878

7979
public readonly loading = observableValue(this, false);
8080

81-
public fetch(position: Position, context: InlineCompletionContext, activeInlineCompletion: InlineCompletionWithUpdatedRange | undefined): Promise<boolean> {
81+
public fetch(position: Position, context: InlineCompletionContext, activeInlineCompletion: InlineCompletionWithUpdatedRange | undefined, withDebounce: boolean): Promise<boolean> {
8282
const request = new UpdateRequest(position, context, this._textModel.getVersionId());
8383

8484
const target = context.selectedSuggestionInfo ? this.suggestWidgetInlineCompletions : this.inlineCompletions;
@@ -97,7 +97,8 @@ export class InlineCompletionsSource extends Disposable {
9797
const source = new CancellationTokenSource();
9898

9999
const promise = (async () => {
100-
const shouldDebounce = updateOngoing || context.triggerKind === InlineCompletionTriggerKind.Automatic;
100+
// Debounce in any case if update is ongoing
101+
const shouldDebounce = updateOngoing || (withDebounce && context.triggerKind === InlineCompletionTriggerKind.Automatic);
101102
if (shouldDebounce) {
102103
// This debounces the operation
103104
await wait(this._debounceValue.get(this._textModel), source.token);

0 commit comments

Comments
 (0)