Skip to content

Commit 91e82ed

Browse files
committed
wire up editor.suggest.filterGraceful microsoft#52789
1 parent 32d9f16 commit 91e82ed

3 files changed

Lines changed: 18 additions & 11 deletions

File tree

‎src/vs/editor/contrib/suggest/completionModel.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { fuzzyScore, fuzzyScoreGracefulAggressive, anyScore } from 'vs/base/comm
99
import { isDisposable } from 'vs/base/common/lifecycle';
1010
import { ISuggestResult, ISuggestSupport } from 'vs/editor/common/modes';
1111
import { ISuggestionItem, SnippetConfig } from './suggest';
12+
import { ISuggestOptions } from 'vs/editor/common/config/editorOptions';
1213

1314
export interface ICompletionItem extends ISuggestionItem {
1415
matches?: number[];
@@ -46,8 +47,9 @@ const enum Refilter {
4647

4748
export class CompletionModel {
4849

49-
private readonly _column: number;
5050
private readonly _items: ICompletionItem[];
51+
private readonly _column: number;
52+
private readonly _options: ISuggestOptions;
5153
private readonly _snippetCompareFn = CompletionModel._compareCompletionItems;
5254

5355
private _lineContext: LineContext;
@@ -56,9 +58,10 @@ export class CompletionModel {
5658
private _isIncomplete: Set<ISuggestSupport>;
5759
private _stats: ICompletionStats;
5860

59-
constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, snippetConfig?: SnippetConfig) {
61+
constructor(items: ISuggestionItem[], column: number, lineContext: LineContext, options: ISuggestOptions = { filterGraceful: true }, snippetConfig?: SnippetConfig) {
6062
this._items = items;
6163
this._column = column;
64+
this._options = options;
6265
this._refilterKind = Refilter.All;
6366
this._lineContext = lineContext;
6467

@@ -146,8 +149,9 @@ export class CompletionModel {
146149
const target: typeof source = [];
147150

148151
// picks a score function based on the number of
149-
// items that we have to score/filter
150-
const scoreFn = source.length > 2000 ? fuzzyScore : fuzzyScoreGracefulAggressive;
152+
// items that we have to score/filter and based on the
153+
// user-configuration
154+
const scoreFn = (!this._options.filterGraceful || source.length > 2000) ? fuzzyScore : fuzzyScoreGracefulAggressive;
151155

152156
for (let i = 0; i < source.length; i++) {
153157

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,10 @@ export class SuggestModel implements IDisposable {
381381
this._completionModel = new CompletionModel(items, this._context.column, {
382382
leadingLineContent: ctx.leadingLineContent,
383383
characterCountDelta: this._context ? ctx.column - this._context.column : 0
384-
}, this._editor.getConfiguration().contribInfo.snippetSuggestions);
384+
},
385+
this._editor.getConfiguration().contribInfo.suggest,
386+
this._editor.getConfiguration().contribInfo.snippetSuggestions
387+
);
385388
this._onNewContext(ctx);
386389

387390
}).then(null, onUnexpectedError);

‎src/vs/editor/contrib/suggest/test/completionModel.test.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ suite('CompletionModel', function () {
167167
], 1, {
168168
leadingLineContent: 's',
169169
characterCountDelta: 0
170-
}, 'top');
170+
}, undefined, 'top');
171171

172172
assert.equal(model.items.length, 2);
173173
const [a, b] = model.items;
@@ -186,7 +186,7 @@ suite('CompletionModel', function () {
186186
], 1, {
187187
leadingLineContent: 's',
188188
characterCountDelta: 0
189-
}, 'bottom');
189+
}, undefined, 'bottom');
190190

191191
assert.equal(model.items.length, 2);
192192
const [a, b] = model.items;
@@ -204,7 +204,7 @@ suite('CompletionModel', function () {
204204
], 1, {
205205
leadingLineContent: 's',
206206
characterCountDelta: 0
207-
}, 'inline');
207+
}, undefined, 'inline');
208208

209209
assert.equal(model.items.length, 2);
210210
const [a, b] = model.items;
@@ -267,7 +267,7 @@ suite('CompletionModel', function () {
267267
], 1, {
268268
leadingLineContent: '',
269269
characterCountDelta: 0
270-
}, 'inline');
270+
}, undefined, 'inline');
271271

272272
assert.equal(model.items.length, 5);
273273

@@ -294,7 +294,7 @@ suite('CompletionModel', function () {
294294
], 1, {
295295
leadingLineContent: '',
296296
characterCountDelta: 0
297-
}, 'inline');
297+
}, undefined, 'inline');
298298

299299
// query gets longer, narrow down the narrow-down'ed-set from before
300300
model.lineContext = { leadingLineContent: 'rlut', characterCountDelta: 4 };
@@ -316,7 +316,7 @@ suite('CompletionModel', function () {
316316
], 1, {
317317
leadingLineContent: '',
318318
characterCountDelta: 0
319-
}, 'inline');
319+
}, undefined, 'inline');
320320

321321
model.lineContext = { leadingLineContent: 'form', characterCountDelta: 4 };
322322
assert.equal(model.items.length, 5);

0 commit comments

Comments
 (0)