Skip to content

Commit dd4e85b

Browse files
author
Benjamin Pasero
authored
Recovery: 94742 (microsoft#94887)
* fix microsoft#94742 * improve
1 parent 36a9f5d commit dd4e85b

3 files changed

Lines changed: 42 additions & 11 deletions

File tree

src/vs/base/common/fuzzyScorer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ export type FuzzyScore2 = [number /* score*/, IMatch[]];
268268

269269
const NO_SCORE2: FuzzyScore2 = [NO_MATCH, []];
270270

271-
export function scoreFuzzy2(target: string, query: IPreparedQuery, patternStart = 0, matchOffset = 0): FuzzyScore2 {
271+
export function scoreFuzzy2(target: string, query: IPreparedQuery, patternStart = 0, matchOffset = 0, skipMultiMatching = false): FuzzyScore2 {
272272

273-
// Score: multiple inputs
274-
if (query.values && query.values.length > 1) {
273+
// Score: multiple inputs (unless disabled)
274+
if (!skipMultiMatching && query.values && query.values.length > 1) {
275275
return doScoreFuzzy2Multiple(target, query.values, patternStart, matchOffset);
276276
}
277277

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
220220

221221
const symbolLabel = trim(symbol.name);
222222
const symbolLabelWithIcon = `$(symbol-${SymbolKinds.toString(symbol.kind) || 'property'}) ${symbolLabel}`;
223+
const symbolLabelIconOffset = symbolLabelWithIcon.length - symbolLabel.length;
223224

224225
let containerLabel = symbol.containerName;
225226
if (options?.extraContainerLabel) {
@@ -238,14 +239,28 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
238239

239240
if (query.original.length > filterPos) {
240241

241-
// Score by symbol
242-
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, filterPos, symbolLabelWithIcon.length - symbolLabel.length /* Readjust matches to account for codicons in label */);
242+
// First: try to score on the entire query, it is possible that
243+
// the symbol matches perfectly (e.g. searching for "change log"
244+
// can be a match on a markdown symbol "change log"). In that
245+
// case we want to skip the container query altogether.
246+
let skipContainerQuery = false;
247+
if (symbolQuery !== query) {
248+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, query, filterPos, symbolLabelIconOffset, true /* skip multi matching */);
249+
if (symbolScore) {
250+
skipContainerQuery = true; // since we consumed the query, skip any container matching
251+
}
252+
}
253+
254+
// Otherwise: score on the symbol query and match on the container later
243255
if (!symbolScore) {
244-
continue;
256+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, filterPos, symbolLabelIconOffset);
257+
if (!symbolScore) {
258+
continue;
259+
}
245260
}
246261

247262
// Score by container if specified
248-
if (containerQuery) {
263+
if (!skipContainerQuery && containerQuery) {
249264
if (containerLabel && containerQuery.original.length > 0) {
250265
[containerScore, containerMatches] = scoreFuzzy2(containerLabel, containerQuery);
251266
}

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

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,31 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
130130

131131
const symbolLabel = symbol.name;
132132
const symbolLabelWithIcon = `$(symbol-${SymbolKinds.toString(symbol.kind) || 'property'}) ${symbolLabel}`;
133-
133+
const symbolLabelIconOffset = symbolLabelWithIcon.length - symbolLabel.length;
134134

135135
// Score by symbol label if searching
136136
let symbolScore: number | undefined = undefined;
137137
let symbolMatches: IMatch[] | undefined = undefined;
138+
let skipContainerQuery = false;
138139
if (symbolQuery.original.length > 0) {
139-
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, 0, symbolLabelWithIcon.length - symbolLabel.length /* Readjust matches to account for codicons in label */);
140+
141+
// First: try to score on the entire query, it is possible that
142+
// the symbol matches perfectly (e.g. searching for "change log"
143+
// can be a match on a markdown symbol "change log"). In that
144+
// case we want to skip the container query altogether.
145+
if (symbolQuery !== query) {
146+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, query, 0, symbolLabelIconOffset, true /* skip multi matching */);
147+
if (symbolScore) {
148+
skipContainerQuery = true; // since we consumed the query, skip any container matching
149+
}
150+
}
151+
152+
// Otherwise: score on the symbol query and match on the container later
140153
if (!symbolScore) {
141-
continue;
154+
[symbolScore, symbolMatches] = scoreFuzzy2(symbolLabel, symbolQuery, 0, symbolLabelIconOffset);
155+
if (!symbolScore) {
156+
continue;
157+
}
142158
}
143159
}
144160

@@ -156,7 +172,7 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
156172
// Score by container if specified and searching
157173
let containerScore: number | undefined = undefined;
158174
let containerMatches: IMatch[] | undefined = undefined;
159-
if (containerQuery && containerQuery.original.length > 0) {
175+
if (!skipContainerQuery && containerQuery && containerQuery.original.length > 0) {
160176
if (containerLabel) {
161177
[containerScore, containerMatches] = scoreFuzzy2(containerLabel, containerQuery);
162178
}

0 commit comments

Comments
 (0)