Skip to content

Commit bd6ac7e

Browse files
committed
quick access - support matching on entire query if symbol contains spaces
1 parent 45b2a7e commit bd6ac7e

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

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

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

223223
const symbolLabel = trim(symbol.name);
224224
const symbolLabelWithIcon = `$(symbol-${SymbolKinds.toString(symbol.kind) || 'property'}) ${symbolLabel}`;
225+
const symbolLabelIconOffset = symbolLabelWithIcon.length - symbolLabel.length;
225226

226227
let containerLabel = symbol.containerName;
227228
if (options?.extraContainerLabel) {
@@ -240,14 +241,28 @@ export abstract class AbstractGotoSymbolQuickAccessProvider extends AbstractEdit
240241

241242
if (query.original.length > filterPos) {
242243

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

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

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);
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)