Skip to content

Commit 696dca7

Browse files
author
Benjamin Pasero
committed
1 parent eb64e93 commit 696dca7

5 files changed

Lines changed: 18 additions & 18 deletions

File tree

src/vs/base/common/filters.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ export function anyScore(pattern: string, lowPattern: string, _patternPos: numbe
392392

393393
//#region --- fuzzyScore ---
394394

395-
export function createMatches(score: undefined | FuzzyScore, offset = 0): IMatch[] {
395+
export function createMatches(score: undefined | FuzzyScore): IMatch[] {
396396
if (typeof score === 'undefined') {
397397
return [];
398398
}
@@ -404,10 +404,10 @@ export function createMatches(score: undefined | FuzzyScore, offset = 0): IMatch
404404
for (let pos = wordStart; pos < _maxLen; pos++) {
405405
if (matches[matches.length - (pos + 1)] === '1') {
406406
const last = res[res.length - 1];
407-
if (last && last.end === pos + offset) {
408-
last.end = pos + offset + 1;
407+
if (last && last.end === pos) {
408+
last.end = pos + 1;
409409
} else {
410-
res.push({ start: pos + offset, end: pos + offset + 1 });
410+
res.push({ start: pos, end: pos + 1 });
411411
}
412412
}
413413
}

src/vs/base/common/fuzzyScorer.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,24 +281,24 @@ export type FuzzyScore2 = [number | undefined /* score */, IMatch[]];
281281

282282
const NO_SCORE2: FuzzyScore2 = [undefined, []];
283283

284-
export function scoreFuzzy2(target: string, query: IPreparedQuery | IPreparedQueryPiece, patternStart = 0, matchOffset = 0): FuzzyScore2 {
284+
export function scoreFuzzy2(target: string, query: IPreparedQuery | IPreparedQueryPiece, patternStart = 0, wordStart = 0): FuzzyScore2 {
285285

286286
// Score: multiple inputs
287287
const preparedQuery = query as IPreparedQuery;
288288
if (preparedQuery.values && preparedQuery.values.length > 1) {
289-
return doScoreFuzzy2Multiple(target, preparedQuery.values, patternStart, matchOffset);
289+
return doScoreFuzzy2Multiple(target, preparedQuery.values, patternStart, wordStart);
290290
}
291291

292292
// Score: single input
293-
return doScoreFuzzy2Single(target, query, patternStart, matchOffset);
293+
return doScoreFuzzy2Single(target, query, patternStart, wordStart);
294294
}
295295

296-
function doScoreFuzzy2Multiple(target: string, query: IPreparedQueryPiece[], patternStart: number, matchOffset: number): FuzzyScore2 {
296+
function doScoreFuzzy2Multiple(target: string, query: IPreparedQueryPiece[], patternStart: number, wordStart: number): FuzzyScore2 {
297297
let totalScore = 0;
298298
const totalMatches: IMatch[] = [];
299299

300300
for (const queryPiece of query) {
301-
const [score, matches] = doScoreFuzzy2Single(target, queryPiece, patternStart, matchOffset);
301+
const [score, matches] = doScoreFuzzy2Single(target, queryPiece, patternStart, wordStart);
302302
if (typeof score !== 'number') {
303303
// if a single query value does not match, return with
304304
// no score entirely, we require all queries to match
@@ -314,13 +314,13 @@ function doScoreFuzzy2Multiple(target: string, query: IPreparedQueryPiece[], pat
314314
return [totalScore, normalizeMatches(totalMatches)];
315315
}
316316

317-
function doScoreFuzzy2Single(target: string, query: IPreparedQueryPiece, patternStart: number, matchOffset: number): FuzzyScore2 {
318-
const score = fuzzyScore(query.original, query.originalLowercase, patternStart, target, target.toLowerCase(), 0, true);
317+
function doScoreFuzzy2Single(target: string, query: IPreparedQueryPiece, patternStart: number, wordStart: number): FuzzyScore2 {
318+
const score = fuzzyScore(query.original, query.originalLowercase, patternStart, target, target.toLowerCase(), wordStart, true);
319319
if (!score) {
320320
return NO_SCORE2;
321321
}
322322

323-
return [score[0], createFuzzyMatches(score, matchOffset)];
323+
return [score[0], createFuzzyMatches(score)];
324324
}
325325

326326
//#endregion

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,14 +990,14 @@ suite('Fuzzy Scorer', () => {
990990
const target = 'HeLlo-World';
991991

992992
for (const offset of [0, 3]) {
993-
let [score, matches] = _doScore2(target, 'HeLlo-World', offset);
993+
let [score, matches] = _doScore2(offset === 0 ? target : `123${target}`, 'HeLlo-World', offset);
994994

995995
assert.ok(score);
996996
assert.equal(matches.length, 1);
997997
assert.equal(matches[0].start, 0 + offset);
998998
assert.equal(matches[0].end, target.length + offset);
999999

1000-
[score, matches] = _doScore2(target, 'HW', offset);
1000+
[score, matches] = _doScore2(offset === 0 ? target : `123${target}`, 'HW', offset);
10011001

10021002
assert.ok(score);
10031003
assert.equal(matches.length, 2);

src/vs/editor/contrib/quickAccess/gotoSymbolQuickAccess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,15 +257,15 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
257257
// case we want to skip the container query altogether.
258258
let skipContainerQuery = false;
259259
if (symbolQuery !== query) {
260-
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, { ...query, values: undefined /* disable multi-query support */ }, filterPos, symbolLabelIconOffset);
260+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, { ...query, values: undefined /* disable multi-query support */ }, filterPos, symbolLabelIconOffset);
261261
if (typeof symbolScore === 'number') {
262262
skipContainerQuery = true; // since we consumed the query, skip any container matching
263263
}
264264
}
265265

266266
// Otherwise: score on the symbol query and match on the container later
267267
if (typeof symbolScore !== 'number') {
268-
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, filterPos, symbolLabelIconOffset);
268+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, symbolQuery, filterPos, symbolLabelIconOffset);
269269
if (typeof symbolScore !== 'number') {
270270
continue;
271271
}

src/vs/workbench/contrib/search/browser/symbolsQuickAccess.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,15 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
144144
// can be a match on a markdown symbol "change log"). In that
145145
// case we want to skip the container query altogether.
146146
if (symbolQuery !== query) {
147-
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, { ...query, values: undefined /* disable multi-query support */ }, 0, symbolLabelIconOffset);
147+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, { ...query, values: undefined /* disable multi-query support */ }, 0, symbolLabelIconOffset);
148148
if (typeof symbolScore === 'number') {
149149
skipContainerQuery = true; // since we consumed the query, skip any container matching
150150
}
151151
}
152152

153153
// Otherwise: score on the symbol query and match on the container later
154154
if (typeof symbolScore !== 'number') {
155-
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, 0, symbolLabelIconOffset);
155+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabelWithIcon, symbolQuery, 0, symbolLabelIconOffset);
156156
if (typeof symbolScore !== 'number') {
157157
continue;
158158
}

0 commit comments

Comments
 (0)