Skip to content

Commit c02a8d0

Browse files
committed
1 parent cf1412b commit c02a8d0

2 files changed

Lines changed: 16 additions & 16 deletions

File tree

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

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ export class CompletionModel {
149149
this._filteredItems.push(item);
150150

151151
// compute score against word
152-
const score = CompletionModel._scoreByHighlight(item, word, word.toLowerCase());
152+
const score = CompletionModel._scoreByHighlight(item, word);
153153
if (score > topScore) {
154154
topScore = score;
155155
this._topScoreIdx = this._filteredItems.length - 1;
@@ -166,7 +166,7 @@ export class CompletionModel {
166166

167167
private static _base = 100;
168168

169-
private static _scoreByHighlight(item: ICompletionItem, currentWord: string, BLA): number {
169+
private static _scoreByHighlight(item: ICompletionItem, currentWord: string): number {
170170
const {highlights, suggestion} = item;
171171

172172
if (isFalsyOrEmpty(highlights)) {
@@ -176,7 +176,6 @@ export class CompletionModel {
176176
let caseSensitiveMatches = 0;
177177
let caseInsensitiveMatches = 0;
178178
let firstMatchStart = 0;
179-
let notMatching = 0;
180179

181180
const len = Math.min(CompletionModel._base, suggestion.label.length);
182181
let currentWordOffset = 0;
@@ -185,11 +184,7 @@ export class CompletionModel {
185184

186185
const highlight = highlights[idx];
187186

188-
if (pos < highlight.start) {
189-
// not covered by a highlight
190-
notMatching += 1;
191-
192-
} else if (pos === highlight.start) {
187+
if (pos === highlight.start) {
193188
// reached a highlight: find highlighted part
194189
// and count case-sensitive /case-insensitive matches
195190
const part = suggestion.label.substring(highlight.start, highlight.end);
@@ -212,20 +207,19 @@ export class CompletionModel {
212207
firstMatchStart = highlight.start;
213208
}
214209
idx += 1;
210+
215211
if (idx >= highlights.length) {
216-
notMatching += len - pos;
217212
break;
218213
}
219214
}
220215
}
221216

222-
// combine the five scoring values into one
217+
// combine the 4 scoring values into one
223218
// value using base_100. Values further left
224219
// are more important
225-
return (CompletionModel._base ** 4) * caseSensitiveMatches
226-
+ (CompletionModel._base ** 3) * caseInsensitiveMatches
227-
+ (CompletionModel._base ** 2) * (CompletionModel._base - firstMatchStart)
228-
+ (CompletionModel._base ** 1) * (CompletionModel._base - highlights.length)
229-
+ (CompletionModel._base ** 0) * (CompletionModel._base - notMatching);
220+
return (CompletionModel._base ** 3) * caseSensitiveMatches
221+
+ (CompletionModel._base ** 2) * caseInsensitiveMatches
222+
+ (CompletionModel._base ** 1) * (CompletionModel._base - firstMatchStart)
223+
+ (CompletionModel._base ** 0) * (CompletionModel._base - highlights.length);
230224
}
231225
}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ suite('CompletionModel', function () {
130130
assertTopScore('cC', 1, 'ccfoo', 'camelCase');
131131
assertTopScore('cC', 1, 'ccfoo', 'camelCase', 'foo-cC-bar');
132132

133+
// issue #17836
134+
assertTopScore('p', 0, 'parse', 'posix', 'sep', 'pafdsa', 'path', 'p');
135+
assertTopScore('pa', 0, 'parse', 'posix', 'sep', 'pafdsa', 'path', 'p');
136+
133137
// issue #14583
134138
assertTopScore('log', 3, 'HTMLOptGroupElement', 'ScrollLogicalPosition', 'SVGFEMorphologyElement', 'log');
135139
assertTopScore('e', 2, 'AbstractWorker', 'ActiveXObject', 'else');
@@ -138,7 +142,7 @@ suite('CompletionModel', function () {
138142
assertTopScore('workbench.sideb', 1, 'workbench.editor.defaultSideBySideLayout', 'workbench.sideBar.location');
139143

140144
// issue #11423
141-
assertTopScore('editor.r', 3, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
145+
assertTopScore('editor.r', 2, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
142146
assertTopScore('editor.R', 1, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
143147
assertTopScore('Editor.r', 0, 'diffEditor.renderSideBySide', 'editor.overviewRulerlanes', 'editor.renderControlCharacter', 'editor.renderWhitespace');
144148

@@ -147,8 +151,10 @@ suite('CompletionModel', function () {
147151
assertTopScore('convertModelPosition', 0, 'convertModelPositionToViewPosition', 'convertViewToModelPosition');
148152
// dupe, issue #14942
149153
assertTopScore('is', 0, 'isValidViewletId', 'import statement');
154+
150155
});
151156

157+
152158
test('proper current word when length=0, #16380', function () {
153159

154160
model = new CompletionModel([

0 commit comments

Comments
 (0)