Skip to content

Commit eab7774

Browse files
authored
Merge pull request microsoft#152292 from etriebe/etriebe/add_firstmatchcanbeweak_option
Add an option to expose the allowMidWordMatch as a setting
2 parents 8bc7e3d + 1af1639 commit eab7774

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,10 @@ export interface IEditorOptions {
640640
* Controls strikethrough deprecated variables.
641641
*/
642642
showDeprecated?: boolean;
643+
/**
644+
* Controls whether suggestions allow matches in the middle of the word instead of only at the beginning
645+
*/
646+
matchOnWordStartOnly?: boolean;
643647
/**
644648
* Control the behavior and rendering of the inline hints.
645649
*/
@@ -3924,6 +3928,10 @@ export interface ISuggestOptions {
39243928
* Show deprecated-suggestions.
39253929
*/
39263930
showDeprecated?: boolean;
3931+
/**
3932+
* Controls whether suggestions allow matches in the middle of the word instead of only at the beginning
3933+
*/
3934+
matchOnWordStartOnly?: boolean;
39273935
/**
39283936
* Show field-suggestions.
39293937
*/
@@ -4045,6 +4053,7 @@ class EditorSuggest extends BaseEditorOption<EditorOption.suggest, ISuggestOptio
40454053
showFunctions: true,
40464054
showConstructors: true,
40474055
showDeprecated: true,
4056+
matchOnWordStartOnly: true,
40484057
showFields: true,
40494058
showVariables: true,
40504059
showClasses: true,
@@ -4151,6 +4160,11 @@ class EditorSuggest extends BaseEditorOption<EditorOption.suggest, ISuggestOptio
41514160
default: true,
41524161
markdownDescription: nls.localize('editor.suggest.showDeprecated', "When enabled IntelliSense shows `deprecated`-suggestions.")
41534162
},
4163+
'editor.suggest.matchOnWordStartOnly': {
4164+
type: 'boolean',
4165+
default: false,
4166+
markdownDescription: nls.localize('editor.suggest.matchOnWordStartOnly', "When enabled IntelliSense filtering requires that the first character matches on a word start, e.g `c` on `Console` or `WebContext` but _not_ on `description`. When disabled IntelliSense will show more results but still sorts them by match quality.")
4167+
},
41544168
'editor.suggest.showFields': {
41554169
type: 'boolean',
41564170
default: true,
@@ -4300,6 +4314,7 @@ class EditorSuggest extends BaseEditorOption<EditorOption.suggest, ISuggestOptio
43004314
showFunctions: boolean(input.showFunctions, this.defaultValue.showFunctions),
43014315
showConstructors: boolean(input.showConstructors, this.defaultValue.showConstructors),
43024316
showDeprecated: boolean(input.showDeprecated, this.defaultValue.showDeprecated),
4317+
matchOnWordStartOnly: boolean(input.matchOnWordStartOnly, this.defaultValue.matchOnWordStartOnly),
43034318
showFields: boolean(input.showFields, this.defaultValue.showFields),
43044319
showVariables: boolean(input.showVariables, this.defaultValue.showVariables),
43054320
showClasses: boolean(input.showClasses, this.defaultValue.showClasses),

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { CompletionModel } from './completionModel';
2828
import { CompletionDurations, CompletionItem, CompletionOptions, getSnippetSuggestSupport, getSuggestionComparator, provideSuggestionItems, QuickSuggestionsOptions, SnippetSortOrder } from './suggest';
2929
import { IWordAtPosition } from 'vs/editor/common/core/wordHelper';
3030
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
31+
import { FuzzyScoreOptions } from 'vs/base/common/filters';
3132

3233
export interface ICancelEvent {
3334
readonly retrigger: boolean;
@@ -525,14 +526,18 @@ export class SuggestModel implements IDisposable {
525526
}
526527

527528
const ctx = new LineContext(model, this._editor.getPosition(), auto, context.shy, context.noSelect);
529+
const fuzzySearchOptions = {
530+
...FuzzyScoreOptions.default,
531+
firstMatchCanBeWeak: !this._editor.getOption(EditorOption.suggest).matchOnWordStartOnly
532+
};
528533
this._completionModel = new CompletionModel(items, this._context!.column, {
529534
leadingLineContent: ctx.leadingLineContent,
530535
characterCountDelta: ctx.column - this._context!.column
531536
},
532537
wordDistance,
533538
this._editor.getOption(EditorOption.suggest),
534539
this._editor.getOption(EditorOption.snippetSuggestions),
535-
undefined,
540+
fuzzySearchOptions,
536541
clipboardText
537542
);
538543

src/vs/monaco.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3425,6 +3425,10 @@ declare namespace monaco.editor {
34253425
* Controls strikethrough deprecated variables.
34263426
*/
34273427
showDeprecated?: boolean;
3428+
/**
3429+
* Controls whether suggestions allow matches in the middle of the word instead of only at the beginning
3430+
*/
3431+
matchOnWordStartOnly?: boolean;
34283432
/**
34293433
* Control the behavior and rendering of the inline hints.
34303434
*/
@@ -4212,6 +4216,10 @@ declare namespace monaco.editor {
42124216
* Show deprecated-suggestions.
42134217
*/
42144218
showDeprecated?: boolean;
4219+
/**
4220+
* Controls whether suggestions allow matches in the middle of the word instead of only at the beginning
4221+
*/
4222+
matchOnWordStartOnly?: boolean;
42154223
/**
42164224
* Show field-suggestions.
42174225
*/

0 commit comments

Comments
 (0)