Skip to content

Commit a248e33

Browse files
committed
1 parent 77bdf51 commit a248e33

2 files changed

Lines changed: 13 additions & 6 deletions

File tree

src/vs/base/common/filters.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -463,17 +463,20 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
463463
let patternPos = patternStartPos;
464464
let wordPos = 0;
465465

466+
// Run a simple check if the characters of pattern occur
467+
// (in order) at all in word. If that isn't the case we
468+
// stop because no match will be possible
466469
while (patternPos < patternLen && wordPos < wordLen) {
467470
if (lowPattern[patternPos] === lowWord[wordPos]) {
468471
patternPos += 1;
469472
}
470473
wordPos += 1;
471474
}
472475
if (patternPos !== patternLen) {
473-
// no simple matches found -> return early
474476
return undefined;
475477
}
476478

479+
// There will be a mach, fill in tables
477480
for (patternPos = patternStartPos + 1; patternPos <= patternLen; patternPos++) {
478481

479482
let lastLowWordChar = '';
@@ -483,20 +486,22 @@ export function fuzzyScore(pattern: string, word: string): [number, number[]] {
483486
let score = -1;
484487
let lowWordChar = lowWord[wordPos - 1];
485488
if (lowPattern[patternPos - 1] === lowWordChar) {
486-
487-
if (wordPos === 1) {
489+
if (wordPos === (patternPos - patternStartPos)) {
490+
// common prefix: `foobar <-> foobaz`
488491
if (pattern[patternPos - 1] === word[wordPos - 1]) {
489492
score = 7;
490493
} else {
491494
score = 5;
492495
}
493496
} else if (lowWordChar !== word[wordPos - 1]) {
497+
// hitting upper-case: `foo <-> forOthers`
494498
if (pattern[patternPos - 1] === word[wordPos - 1]) {
495499
score = 7;
496500
} else {
497501
score = 5;
498502
}
499503
} else if (_seps[lastLowWordChar]) {
504+
// post separator: `foo <-> bar_foo`
500505
score = 5;
501506

502507
} else {

src/vs/base/test/common/filters.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,9 +397,11 @@ suite('Filters', () => {
397397
assertTopScore(fuzzyScore, 'title', 1, 'files.trimTrailingWhitespace', 'window.title');
398398
});
399399

400-
// test('Unexpected suggestion scoring, #28791', function () {
401-
// assertTopScore(fuzzyScore, '_lines', 1, '_lineStarts', '_lines');
402-
// });
400+
test('Unexpected suggestion scoring, #28791', function () {
401+
assertTopScore(fuzzyScore, '_lines', 1, '_lineStarts', '_lines');
402+
assertTopScore(fuzzyScore, '_lines', 1, '_lineS', '_lines');
403+
assertTopScore(fuzzyScore, '_lineS', 0, '_lineS', '_lines');
404+
});
403405

404406
test('nextTypoPermutation', function () {
405407

0 commit comments

Comments
 (0)