Skip to content

Commit 387588c

Browse files
authored
Implements editor.inlineSuggest.experimental.triggerCommandOnProviderChange = true (microsoft#252986)
1 parent cdb66ca commit 387588c

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

src/vs/editor/common/config/editorOptions.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4341,6 +4341,11 @@ export interface IInlineSuggestOptions {
43414341
* @internal
43424342
*/
43434343
suppressInlineSuggestions?: string;
4344+
4345+
/**
4346+
* @internal
4347+
*/
4348+
triggerCommandOnProviderChange?: boolean;
43444349
};
43454350
}
43464351

@@ -4374,6 +4379,7 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
43744379
},
43754380
experimental: {
43764381
suppressInlineSuggestions: '',
4382+
triggerCommandOnProviderChange: true,
43774383
},
43784384
};
43794385

@@ -4412,6 +4418,12 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
44124418
tags: ['experimental', 'onExp'],
44134419
description: nls.localize('inlineSuggest.suppressInlineSuggestions', "Suppresses inline completions for specified extension IDs -- comma separated.")
44144420
},
4421+
'editor.inlineSuggest.experimental.triggerCommandOnProviderChange': {
4422+
type: 'boolean',
4423+
default: defaults.experimental.triggerCommandOnProviderChange,
4424+
tags: ['experimental', 'onExp'],
4425+
description: nls.localize('inlineSuggest.triggerCommandOnProviderChange', "Controls whether to trigger a command when the inline suggestion provider changes.")
4426+
},
44154427
'editor.inlineSuggest.fontFamily': {
44164428
type: 'string',
44174429
default: defaults.fontFamily,
@@ -4466,6 +4478,7 @@ class InlineEditorSuggest extends BaseEditorOption<EditorOption.inlineSuggest, I
44664478
},
44674479
experimental: {
44684480
suppressInlineSuggestions: EditorStringOption.string(input.experimental?.suppressInlineSuggestions, this.defaultValue.experimental.suppressInlineSuggestions),
4481+
triggerCommandOnProviderChange: boolean(input.experimental?.triggerCommandOnProviderChange, this.defaultValue.experimental.triggerCommandOnProviderChange),
44694482
},
44704483
};
44714484
}

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export class InlineCompletionsModel extends Disposable {
7474
private readonly _suppressedInlineCompletionGroupIds;
7575
private readonly _inlineEditsEnabled;
7676
private readonly _inlineEditsShowCollapsedEnabled;
77+
private readonly _triggerCommandOnProviderChange;
7778

7879
constructor(
7980
public readonly textModel: ITextModel,
@@ -109,6 +110,8 @@ export class InlineCompletionsModel extends Disposable {
109110
this._suppressedInlineCompletionGroupIds = this._editorObs.getOption(EditorOption.inlineSuggest).map(v => new Set(v.experimental.suppressInlineSuggestions.split(',')));
110111
this._inlineEditsEnabled = this._editorObs.getOption(EditorOption.inlineSuggest).map(v => !!v.edits.enabled);
111112
this._inlineEditsShowCollapsedEnabled = this._editorObs.getOption(EditorOption.inlineSuggest).map(s => s.edits.showCollapsed);
113+
this._triggerCommandOnProviderChange = this._editorObs.getOption(EditorOption.inlineSuggest).map(s => s.experimental.triggerCommandOnProviderChange);
114+
112115
this._lastShownInlineCompletionInfo = undefined;
113116
this._lastAcceptedInlineCompletionInfo = undefined;
114117
this._didUndoInlineEdits = derivedHandleChanges({
@@ -596,6 +599,19 @@ export class InlineCompletionsModel extends Disposable {
596599
return;
597600
}
598601

602+
// Only update the active editor
603+
const activeEditor = this._codeEditorService.getFocusedCodeEditor() || this._codeEditorService.getActiveCodeEditor();
604+
if (activeEditor !== this._editor) {
605+
return;
606+
}
607+
608+
if (this._triggerCommandOnProviderChange.get()) {
609+
// TODO@hediet remove this and always do the else branch.
610+
this.trigger(undefined, { onlyFetchInlineEdits: true });
611+
return;
612+
}
613+
614+
599615
// If there is an active suggestion from a different provider, we ignore the update
600616
const activeState = this.state.get();
601617
if (activeState && (activeState.inlineCompletion || activeState.edits) && activeState.inlineCompletion?.source.provider !== provider) {

0 commit comments

Comments
 (0)