mirror of
https://github.com/microsoft/vscode.git
synced 2026-07-07 15:26:49 +01:00
Add offWhenInlineCompletions value for editor.quickSuggestions setting
Adds a new 'offWhenInlineCompletions' value to the quickSuggestions
setting that disables quick suggestions when an inline completion
provider is registered for the current model. When no inline completion
provider exists, suggestions behave as if set to 'on'.
Also adds experiment: { mode: 'auto' } to the quickSuggestions setting.
Co-authored-by: jrieken <1794099+jrieken@users.noreply.github.com>
This commit is contained in:
@@ -3712,7 +3712,7 @@ class PlaceholderOption extends BaseEditorOption<EditorOption.placeholder, strin
|
||||
|
||||
//#region quickSuggestions
|
||||
|
||||
export type QuickSuggestionsValue = 'on' | 'inline' | 'off';
|
||||
export type QuickSuggestionsValue = 'on' | 'inline' | 'off' | 'offWhenInlineCompletions';
|
||||
|
||||
/**
|
||||
* Configuration options for quick suggestions
|
||||
@@ -3743,8 +3743,8 @@ class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggesti
|
||||
{ type: 'boolean' },
|
||||
{
|
||||
type: 'string',
|
||||
enum: ['on', 'inline', 'off'],
|
||||
enumDescriptions: [nls.localize('on', "Quick suggestions show inside the suggest widget"), nls.localize('inline', "Quick suggestions show as ghost text"), nls.localize('off', "Quick suggestions are disabled")]
|
||||
enum: ['on', 'inline', 'off', 'offWhenInlineCompletions'],
|
||||
enumDescriptions: [nls.localize('on', "Quick suggestions show inside the suggest widget"), nls.localize('inline', "Quick suggestions show as ghost text"), nls.localize('off', "Quick suggestions are disabled"), nls.localize('offWhenInlineCompletions', "Quick suggestions are disabled when an inline completion provider is available")]
|
||||
}
|
||||
];
|
||||
super(EditorOption.quickSuggestions, 'quickSuggestions', defaults, {
|
||||
@@ -3768,7 +3768,10 @@ class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggesti
|
||||
},
|
||||
},
|
||||
default: defaults,
|
||||
markdownDescription: nls.localize('quickSuggestions', "Controls whether suggestions should automatically show up while typing. This can be controlled for typing in comments, strings, and other code. Quick suggestion can be configured to show as ghost text or with the suggest widget. Also be aware of the {0}-setting which controls if suggestions are triggered by special characters.", '`#editor.suggestOnTriggerCharacters#`')
|
||||
markdownDescription: nls.localize('quickSuggestions', "Controls whether suggestions should automatically show up while typing. This can be controlled for typing in comments, strings, and other code. Quick suggestion can be configured to show as ghost text or with the suggest widget. Also be aware of the {0}-setting which controls if suggestions are triggered by special characters.", '`#editor.suggestOnTriggerCharacters#`'),
|
||||
experiment: {
|
||||
mode: 'auto'
|
||||
}
|
||||
});
|
||||
this.defaultValue = defaults;
|
||||
}
|
||||
@@ -3785,7 +3788,7 @@ class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggesti
|
||||
}
|
||||
|
||||
const { other, comments, strings } = (<IQuickSuggestionsOptions>input);
|
||||
const allowedValues: QuickSuggestionsValue[] = ['on', 'inline', 'off'];
|
||||
const allowedValues: QuickSuggestionsValue[] = ['on', 'inline', 'off', 'offWhenInlineCompletions'];
|
||||
let validatedOther: QuickSuggestionsValue;
|
||||
let validatedComments: QuickSuggestionsValue;
|
||||
let validatedStrings: QuickSuggestionsValue;
|
||||
|
||||
@@ -415,7 +415,10 @@ export class SuggestModel implements IDisposable {
|
||||
const lineTokens = model.tokenization.getLineTokens(pos.lineNumber);
|
||||
const tokenType = lineTokens.getStandardTokenType(lineTokens.findTokenIndexAtOffset(Math.max(pos.column - 1 - 1, 0)));
|
||||
if (QuickSuggestionsOptions.valueFor(config, tokenType) !== 'on') {
|
||||
return;
|
||||
if (QuickSuggestionsOptions.valueFor(config, tokenType) !== 'offWhenInlineCompletions'
|
||||
|| this._languageFeaturesService.inlineCompletionsProvider.has(model)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ import { Selection } from '../../../../common/core/selection.js';
|
||||
import { Handler } from '../../../../common/editorCommon.js';
|
||||
import { ITextModel } from '../../../../common/model.js';
|
||||
import { TextModel } from '../../../../common/model/textModel.js';
|
||||
import { CompletionItemKind, CompletionItemProvider, CompletionList, CompletionTriggerKind, EncodedTokenizationResult, IState, TokenizationRegistry } from '../../../../common/languages.js';
|
||||
import { CompletionItemKind, CompletionItemProvider, CompletionList, CompletionTriggerKind, EncodedTokenizationResult, InlineCompletionsProvider, IState, TokenizationRegistry } from '../../../../common/languages.js';
|
||||
import { MetadataConsts } from '../../../../common/encodedTokenAttributes.js';
|
||||
import { ILanguageConfigurationService } from '../../../../common/languages/languageConfigurationRegistry.js';
|
||||
import { NullState } from '../../../../common/languages/nullTokenize.js';
|
||||
@@ -1228,4 +1228,55 @@ suite('SuggestModel - TriggerAndCancelOracle', function () {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
test('offWhenInlineCompletions - suppresses quick suggest when inline provider exists', function () {
|
||||
|
||||
disposables.add(registry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
|
||||
// Register a dummy inline completions provider
|
||||
const inlineProvider: InlineCompletionsProvider = {
|
||||
provideInlineCompletions: () => ({ items: [] }),
|
||||
disposeInlineCompletions: () => { }
|
||||
};
|
||||
disposables.add(languageFeaturesService.inlineCompletionsProvider.register({ scheme: 'test' }, inlineProvider));
|
||||
|
||||
return withOracle((suggestOracle, editor) => {
|
||||
editor.updateOptions({ quickSuggestions: { comments: 'off', strings: 'off', other: 'offWhenInlineCompletions' } });
|
||||
|
||||
return new Promise<void>((resolve, reject) => {
|
||||
const unexpectedSuggestSub = suggestOracle.onDidSuggest(() => {
|
||||
unexpectedSuggestSub.dispose();
|
||||
reject(new Error('Quick suggestions should not have been triggered'));
|
||||
});
|
||||
|
||||
editor.setPosition({ lineNumber: 1, column: 4 });
|
||||
editor.trigger('keyboard', Handler.Type, { text: 'd' });
|
||||
|
||||
// Wait for the quick suggest delay to pass without triggering
|
||||
setTimeout(() => {
|
||||
unexpectedSuggestSub.dispose();
|
||||
resolve();
|
||||
}, 200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
test('offWhenInlineCompletions - allows quick suggest when no inline provider exists', function () {
|
||||
|
||||
disposables.add(registry.register({ scheme: 'test' }, alwaysSomethingSupport));
|
||||
|
||||
// No inline completions provider registered for 'test' scheme
|
||||
|
||||
return withOracle((suggestOracle, editor) => {
|
||||
editor.updateOptions({ quickSuggestions: { comments: 'off', strings: 'off', other: 'offWhenInlineCompletions' } });
|
||||
|
||||
return assertEvent(suggestOracle.onDidSuggest, () => {
|
||||
editor.setPosition({ lineNumber: 1, column: 4 });
|
||||
editor.trigger('keyboard', Handler.Type, { text: 'd' });
|
||||
}, suggestEvent => {
|
||||
assert.strictEqual(suggestEvent.triggerOptions.auto, true);
|
||||
assert.strictEqual(suggestEvent.completionModel.items.length, 1);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+1
-1
@@ -4587,7 +4587,7 @@ declare namespace monaco.editor {
|
||||
cycle?: boolean;
|
||||
}
|
||||
|
||||
export type QuickSuggestionsValue = 'on' | 'inline' | 'off';
|
||||
export type QuickSuggestionsValue = 'on' | 'inline' | 'off' | 'offWhenInlineCompletions';
|
||||
|
||||
/**
|
||||
* Configuration options for quick suggestions
|
||||
|
||||
Reference in New Issue
Block a user