Skip to content

Commit 2650c2e

Browse files
authored
Merge pull request microsoft#126413 from microsoft/inline-suggest-prevent-auto-suggest
Do not auto-trigger suggest when typing exactly the inline suggestion
2 parents 20a512d + 45c13db commit 2650c2e

File tree

3 files changed

+36
-3
lines changed

3 files changed

+36
-3
lines changed

src/vs/editor/contrib/inlineCompletions/ghostTextController.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { ContextKeyExpr, IContextKeyService, RawContextKey } from 'vs/platform/c
1919
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
2020

2121
export class GhostTextController extends Disposable {
22-
public static readonly inlineSuggestionVisible = new RawContextKey<boolean>('inlineSuggestionVisible ', false, nls.localize('inlineSuggestionVisible', "Whether an inline suggestion is visible"));
22+
public static readonly inlineSuggestionVisible = new RawContextKey<boolean>('inlineSuggestionVisible', false, nls.localize('inlineSuggestionVisible', "Whether an inline suggestion is visible"));
2323
public static readonly inlineSuggestionHasIndentation = new RawContextKey<boolean>('inlineSuggestionHasIndentation', false, nls.localize('inlineSuggestionHasIndentation', "Whether the inline suggestion starts with whitespace"));
2424

2525
static ID = 'editor.contrib.ghostTextController';
@@ -50,6 +50,9 @@ export class GhostTextController extends Disposable {
5050
if (e.hasChanged(EditorOption.suggest)) {
5151
this.updateModelController();
5252
}
53+
if (e.hasChanged(EditorOption.inlineSuggest)) {
54+
this.updateModelController();
55+
}
5356
}));
5457
this.updateModelController();
5558
}

src/vs/editor/contrib/suggest/suggestModel.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ import { isLowSurrogate, isHighSurrogate, getLeadingWhitespace } from 'vs/base/c
2424
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
2525
import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry';
2626
import { ILogService } from 'vs/platform/log/common/log';
27+
import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey';
28+
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
2729

2830
export interface ICancelEvent {
2931
readonly retrigger: boolean;
@@ -95,6 +97,20 @@ export const enum State {
9597
Auto = 2
9698
}
9799

100+
function shouldPreventQuickSuggest(contextKeyService: IContextKeyService, configurationService: IConfigurationService): boolean {
101+
return (
102+
Boolean(contextKeyService.getContextKeyValue<boolean>('inlineSuggestionVisible'))
103+
&& !Boolean(configurationService.getValue<boolean>('editor.inlineSuggest.allowQuickSuggestions'))
104+
);
105+
}
106+
107+
function shouldPreventSuggestOnTriggerCharacters(contextKeyService: IContextKeyService, configurationService: IConfigurationService): boolean {
108+
return (
109+
Boolean(contextKeyService.getContextKeyValue<boolean>('inlineSuggestionVisible'))
110+
&& !Boolean(configurationService.getValue<boolean>('editor.inlineSuggest.allowSuggestOnTriggerCharacters'))
111+
);
112+
}
113+
98114
export class SuggestModel implements IDisposable {
99115

100116
private readonly _toDispose = new DisposableStore();
@@ -123,6 +139,8 @@ export class SuggestModel implements IDisposable {
123139
@IClipboardService private readonly _clipboardService: IClipboardService,
124140
@ITelemetryService private readonly _telemetryService: ITelemetryService,
125141
@ILogService private readonly _logService: ILogService,
142+
@IContextKeyService private readonly _contextKeyService: IContextKeyService,
143+
@IConfigurationService private readonly _configurationService: IConfigurationService,
126144
) {
127145
this._currentSelection = this._editor.getSelection() || new Selection(1, 1, 1, 1);
128146

@@ -213,6 +231,10 @@ export class SuggestModel implements IDisposable {
213231

214232
const checkTriggerCharacter = (text?: string) => {
215233

234+
if (shouldPreventSuggestOnTriggerCharacters(this._contextKeyService, this._configurationService)) {
235+
return;
236+
}
237+
216238
if (!text) {
217239
// came here from the compositionEnd-event
218240
const position = this._editor.getPosition()!;
@@ -351,6 +373,11 @@ export class SuggestModel implements IDisposable {
351373
}
352374
}
353375

376+
if (shouldPreventQuickSuggest(this._contextKeyService, this._configurationService)) {
377+
// do not trigger quick suggestions if inline suggestions are shown
378+
return;
379+
}
380+
354381
// we made it till here -> trigger now
355382
this.trigger({ auto: true, shy: false });
356383

src/vs/editor/contrib/suggest/test/suggestModel.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,12 @@ import { IEditorWorkerService } from 'vs/editor/common/services/editorWorkerServ
3131
import { ISuggestMemoryService } from 'vs/editor/contrib/suggest/suggestMemory';
3232
import { ITextModel } from 'vs/editor/common/model';
3333
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding';
34-
import { MockKeybindingService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
34+
import { MockKeybindingService, MockContextKeyService } from 'vs/platform/keybinding/test/common/mockKeybindingService';
3535
import { createTextModel } from 'vs/editor/test/common/editorTestUtils';
3636
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService';
3737
import { mock } from 'vs/base/test/common/mock';
3838
import { NullLogService } from 'vs/platform/log/common/log';
39+
import { TestConfigurationService } from 'vs/platform/configuration/test/common/testConfigurationService';
3940

4041

4142
function createMockEditor(model: TextModel): ITestCodeEditor {
@@ -204,7 +205,9 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
204205
}
205206
},
206207
NullTelemetryService,
207-
new NullLogService()
208+
new NullLogService(),
209+
new MockContextKeyService(),
210+
new TestConfigurationService()
208211
);
209212
disposables.push(oracle, editor);
210213

0 commit comments

Comments
 (0)