提交 803e7c29 编写于 作者: J Johannes Rieken

don't score when the word is the empty word, #26096

上级 fe740b4b
......@@ -473,7 +473,7 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
}
if (patternLen === patternStartPos) {
return [-1, []];
return [-100, []];
}
if (patternLen > wordLen) {
......
......@@ -124,7 +124,15 @@ export class CompletionModel {
word = wordLen === 0 ? '' : leadingLineContent.slice(-wordLen);
}
if (typeof suggestion.filterText === 'string') {
if (wordLen === 0) {
// when there is nothing to score against, don't
// event try to do. Use a const rank and rely on
// the fallback-sort using the initial sort order.
// use a score of `-100` because that is out of the
// bound of values `fuzzyScore` will return
item.score = -100;
} else if (typeof suggestion.filterText === 'string') {
// when there is a `filterText` it must match the `word`.
// if it matches we check with the label to compute highlights
// and if that doesn't yield a result we have no highlights,
......
......@@ -6,7 +6,7 @@
import * as assert from 'assert';
import { ISuggestion, ISuggestResult, ISuggestSupport, SuggestionType } from 'vs/editor/common/modes';
import { ISuggestionItem } from 'vs/editor/contrib/suggest/browser/suggest';
import { ISuggestionItem, getSuggestionComparator } from 'vs/editor/contrib/suggest/browser/suggest';
import { CompletionModel } from 'vs/editor/contrib/suggest/browser/completionModel';
import { IPosition } from 'vs/editor/common/core/position';
import { TPromise } from "vs/base/common/winjs.base";
......@@ -202,4 +202,30 @@ suite('CompletionModel', function () {
};
assert.equal(model.items.length, 1);
});
test('Vscode 1.12 no longer obeys \'sortText\' in completion items (from language server), #26096', function () {
const item1 = createSuggestItem('<- groups', 2, 'property', false, { lineNumber: 1, column: 3 });
item1.suggestion.filterText = ' groups';
item1.suggestion.sortText = '00002';
const item2 = createSuggestItem('source', 0, 'property', false, { lineNumber: 1, column: 3 });
item2.suggestion.filterText = 'source';
item2.suggestion.sortText = '00001';
const items = [item1, item2].sort(getSuggestionComparator('inline'));
model = new CompletionModel(items, 3, {
leadingLineContent: ' ',
characterCountDelta: 0
});
assert.equal(model.items.length, 2);
const [first, second] = model.items;
assert.equal(first.suggestion.label, 'source');
assert.equal(second.suggestion.label, '<- groups');
});
});
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册