Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add regex to quickSuggestions #235876

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 21 additions & 6 deletions src/vs/editor/common/config/editorOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3491,12 +3491,14 @@ export interface IQuickSuggestionsOptions {
other?: boolean | QuickSuggestionsValue;
comments?: boolean | QuickSuggestionsValue;
strings?: boolean | QuickSuggestionsValue;
regex?: boolean | QuickSuggestionsValue;
}

export interface InternalQuickSuggestionsOptions {
readonly other: QuickSuggestionsValue;
readonly comments: QuickSuggestionsValue;
readonly strings: QuickSuggestionsValue;
readonly regex: QuickSuggestionsValue;
}

class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggestions, boolean | IQuickSuggestionsOptions, InternalQuickSuggestionsOptions> {
Expand All @@ -3507,7 +3509,8 @@ class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggesti
const defaults: InternalQuickSuggestionsOptions = {
other: 'on',
comments: 'off',
strings: 'off'
strings: 'off',
regex: 'off'
};
const types: IJSONSchema[] = [
{ type: 'boolean' },
Expand All @@ -3534,11 +3537,16 @@ class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggesti
other: {
anyOf: types,
default: defaults.other,
description: nls.localize('quickSuggestions.other', "Enable quick suggestions outside of strings and comments.")
description: nls.localize('quickSuggestions.other', "Enable quick suggestions outside of strings, comments and regular expressions.")
},
regex: {
anyOf: types,
default: defaults.regex,
description: nls.localize('quickSuggestions.regex', "Enable quick suggestions inside regular expressions.")
},
},
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, regular expressions 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#`')
});
this.defaultValue = defaults;
}
Expand All @@ -3547,18 +3555,19 @@ class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggesti
if (typeof input === 'boolean') {
// boolean -> all on/off
const value = input ? 'on' : 'off';
return { comments: value, strings: value, other: value };
return { comments: value, strings: value, regex: value, other: value };
}
if (!input || typeof input !== 'object') {
// invalid object
return this.defaultValue;
}

const { other, comments, strings } = (<IQuickSuggestionsOptions>input);
const { other, comments, strings, regex } = (<IQuickSuggestionsOptions>input);
const allowedValues: QuickSuggestionsValue[] = ['on', 'inline', 'off'];
let validatedOther: QuickSuggestionsValue;
let validatedComments: QuickSuggestionsValue;
let validatedStrings: QuickSuggestionsValue;
let validatedRegex: QuickSuggestionsValue;

if (typeof other === 'boolean') {
validatedOther = other ? 'on' : 'off';
Expand All @@ -3575,10 +3584,16 @@ class EditorQuickSuggestions extends BaseEditorOption<EditorOption.quickSuggesti
} else {
validatedStrings = stringSet(strings, this.defaultValue.strings, allowedValues);
}
if (typeof regex === 'boolean') {
validatedRegex = regex ? 'on' : 'off';
} else {
validatedRegex = stringSet(regex, this.defaultValue.regex, allowedValues);
}
return {
other: validatedOther,
comments: validatedComments,
strings: validatedStrings
strings: validatedStrings,
regex: validatedRegex
};
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/vs/editor/contrib/suggest/browser/suggest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -453,17 +453,18 @@ export interface ISuggestItemPreselector {
export abstract class QuickSuggestionsOptions {

static isAllOff(config: InternalQuickSuggestionsOptions): boolean {
return config.other === 'off' && config.comments === 'off' && config.strings === 'off';
return config.other === 'off' && config.comments === 'off' && config.strings === 'off' && config.regex === 'off';
}

static isAllOn(config: InternalQuickSuggestionsOptions): boolean {
return config.other === 'on' && config.comments === 'on' && config.strings === 'on';
return config.other === 'on' && config.comments === 'on' && config.strings === 'on' && config.regex === 'on';
}

static valueFor(config: InternalQuickSuggestionsOptions, tokenType: StandardTokenType): QuickSuggestionsValue {
switch (tokenType) {
case StandardTokenType.Comment: return config.comments;
case StandardTokenType.String: return config.strings;
case StandardTokenType.RegEx: return config.regex;
default: return config.other;
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/vs/monaco.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4411,12 +4411,14 @@ declare namespace monaco.editor {
other?: boolean | QuickSuggestionsValue;
comments?: boolean | QuickSuggestionsValue;
strings?: boolean | QuickSuggestionsValue;
regex?: boolean | QuickSuggestionsValue;
}

export interface InternalQuickSuggestionsOptions {
readonly other: QuickSuggestionsValue;
readonly comments: QuickSuggestionsValue;
readonly strings: QuickSuggestionsValue;
readonly regex: QuickSuggestionsValue;
}

export type LineNumbersType = 'on' | 'off' | 'relative' | 'interval' | ((lineNumber: number) => string);
Expand Down