Skip to content

Commit bfcc591

Browse files
author
Benjamin Pasero
committed
Some emoji not matched using new Quick Pick (fix microsoft#95716)
1 parent 469db5a commit bfcc591

4 files changed

Lines changed: 27 additions & 18 deletions

File tree

src/vs/base/common/fuzzyScorer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ function scoreSeparatorAtPos(charCode: number): number {
277277

278278
//#region Alternate fuzzy scorer implementation that is e.g. used for symbols
279279

280-
export type FuzzyScore2 = [number /* score*/, IMatch[]];
280+
export type FuzzyScore2 = [number | undefined /* score */, IMatch[]];
281281

282-
const NO_SCORE2: FuzzyScore2 = [NO_MATCH, []];
282+
const NO_SCORE2: FuzzyScore2 = [undefined, []];
283283

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

@@ -299,7 +299,7 @@ function doScoreFuzzy2Multiple(target: string, query: IPreparedQueryPiece[], pat
299299

300300
for (const queryPiece of query) {
301301
const [score, matches] = doScoreFuzzy2Single(target, queryPiece, patternStart, matchOffset);
302-
if (!score) {
302+
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
305305
return NO_SCORE2;

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ suite('Fuzzy Scorer', () => {
10201020
}
10211021

10221022
function assertNoScore() {
1023-
assert.equal(multiScore, 0);
1023+
assert.equal(multiScore, undefined);
10241024
assert.equal(multiMatches.length, 0);
10251025
}
10261026

@@ -1038,4 +1038,13 @@ suite('Fuzzy Scorer', () => {
10381038
[multiScore, multiMatches] = _doScore2(target, 'More Nothing');
10391039
assertNoScore();
10401040
});
1041+
1042+
test('fuzzyScore2 (#95716)', function () {
1043+
const target = '# ❌ Wow';
1044+
1045+
const score = _doScore2(target, '❌');
1046+
assert.ok(score);
1047+
assert.ok(typeof score[0] === 'number');
1048+
assert.ok(score[1].length > 0);
1049+
});
10411050
});

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,15 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
258258
let skipContainerQuery = false;
259259
if (symbolQuery !== query) {
260260
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, { ...query, values: undefined /* disable multi-query support */ }, filterPos, symbolLabelIconOffset);
261-
if (symbolScore) {
261+
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
267-
if (!symbolScore) {
267+
if (typeof symbolScore !== 'number') {
268268
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, filterPos, symbolLabelIconOffset);
269-
if (!symbolScore) {
269+
if (typeof symbolScore !== 'number') {
270270
continue;
271271
}
272272
}
@@ -277,11 +277,11 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
277277
[containerScore, containerMatches] = scoreFuzzy2(containerLabel, containerQuery);
278278
}
279279

280-
if (!containerScore) {
280+
if (typeof containerScore !== 'number') {
281281
continue;
282282
}
283283

284-
if (symbolScore) {
284+
if (typeof symbolScore === 'number') {
285285
symbolScore += containerScore; // boost symbolScore by containerScore
286286
}
287287
}
@@ -380,13 +380,13 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
380380
}
381381

382382
private compareByScore(symbolA: IGotoSymbolQuickPickItem, symbolB: IGotoSymbolQuickPickItem): number {
383-
if (!symbolA.score && symbolB.score) {
383+
if (typeof symbolA.score !== 'number' && typeof symbolB.score === 'number') {
384384
return 1;
385-
} else if (symbolA.score && !symbolB.score) {
385+
} else if (typeof symbolA.score === 'number' && typeof symbolB.score !== 'number') {
386386
return -1;
387387
}
388388

389-
if (symbolA.score && symbolB.score) {
389+
if (typeof symbolA.score === 'number' && typeof symbolB.score === 'number') {
390390
if (symbolA.score > symbolB.score) {
391391
return -1;
392392
} else if (symbolA.score < symbolB.score) {

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,15 +145,15 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
145145
// case we want to skip the container query altogether.
146146
if (symbolQuery !== query) {
147147
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, { ...query, values: undefined /* disable multi-query support */ }, 0, symbolLabelIconOffset);
148-
if (symbolScore) {
148+
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
154-
if (!symbolScore) {
154+
if (typeof symbolScore !== 'number') {
155155
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, 0, symbolLabelIconOffset);
156-
if (!symbolScore) {
156+
if (typeof symbolScore !== 'number') {
157157
continue;
158158
}
159159
}
@@ -178,11 +178,11 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
178178
[containerScore, containerMatches] = scoreFuzzy2(containerLabel, containerQuery);
179179
}
180180

181-
if (!containerScore) {
181+
if (typeof containerScore !== 'number') {
182182
continue;
183183
}
184184

185-
if (symbolScore) {
185+
if (typeof symbolScore === 'number') {
186186
symbolScore += containerScore; // boost symbolScore by containerScore
187187
}
188188
}
@@ -258,7 +258,7 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
258258
private compareSymbols(symbolA: ISymbolQuickPickItem, symbolB: ISymbolQuickPickItem): number {
259259

260260
// By score
261-
if (symbolA.score && symbolB.score) {
261+
if (typeof symbolA.score === 'number' && typeof symbolB.score === 'number') {
262262
if (symbolA.score > symbolB.score) {
263263
return -1;
264264
}

0 commit comments

Comments
 (0)