Skip to content

Commit c8f220f

Browse files
committed
Improve symbols quick pick to support wild cards
The change introduce a new property into IPreparedQuery called raw to hold the raw query entered by the user. This is used for LS request while the existing original field is used for fuzzy scoring which is modified to remove the wild card characters such as *,?.
1 parent b5a1bb3 commit c8f220f

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

src/vs/base/common/fuzzyScorer.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,10 +790,14 @@ function fallbackCompare<T>(itemA: T, itemB: T, query: IPreparedQuery, accessor:
790790
export interface IPreparedQueryPiece {
791791

792792
/**
793-
* The original query as provided as input.
793+
* The original query as provided as input after removing wildcard characters.
794794
*/
795795
original: string;
796796
originalLowercase: string;
797+
/**
798+
* The original query which is unmodified.
799+
*/
800+
raw: string;
797801

798802
/**
799803
* Original normalized to platform separators:
@@ -848,16 +852,20 @@ export function prepareQuery(original: string): IPreparedQuery {
848852
original = '';
849853
}
850854

855+
const raw = original;
856+
original = original.replace('*', '').replace('?', '');
851857
const originalLowercase = original.toLowerCase();
852858
const { pathNormalized, normalized, normalizedLowercase } = normalizeQuery(original);
853859
const containsPathSeparator = pathNormalized.indexOf(sep) >= 0;
854860
const expectExactMatch = queryExpectsExactMatch(original);
855861

856862
let values: IPreparedQueryPiece[] | undefined = undefined;
857863

858-
const originalSplit = original.split(MULTIPLE_QUERY_VALUES_SEPARATOR);
864+
const originalSplit = raw.split(MULTIPLE_QUERY_VALUES_SEPARATOR);
859865
if (originalSplit.length > 1) {
860-
for (const originalPiece of originalSplit) {
866+
for (const piece of originalSplit) {
867+
const rawPiece = piece;
868+
const originalPiece = rawPiece.replace('*', '').replace('?', '');
861869
const expectExactMatchPiece = queryExpectsExactMatch(originalPiece);
862870
const {
863871
pathNormalized: pathNormalizedPiece,
@@ -876,13 +884,13 @@ export function prepareQuery(original: string): IPreparedQuery {
876884
pathNormalized: pathNormalizedPiece,
877885
normalized: normalizedPiece,
878886
normalizedLowercase: normalizedLowercasePiece,
879-
expectContiguousMatch: expectExactMatchPiece
887+
expectContiguousMatch: expectExactMatchPiece,
888+
raw: rawPiece
880889
});
881890
}
882891
}
883892
}
884-
885-
return { original, originalLowercase, pathNormalized, normalized, normalizedLowercase, values, containsPathSeparator, expectContiguousMatch: expectExactMatch };
893+
return { original, originalLowercase, raw, pathNormalized, normalized, normalizedLowercase, values, containsPathSeparator, expectContiguousMatch: expectExactMatch };
886894
}
887895

888896
function normalizeQuery(original: string): { pathNormalized: string; normalized: string; normalizedLowercase: string } {

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,13 +1109,16 @@ suite('Fuzzy Scorer', () => {
11091109

11101110
// with spaces
11111111
let query = prepareQuery('He*llo World');
1112-
assert.strictEqual(query.original, 'He*llo World');
1112+
assert.strictEqual(query.raw, 'He*llo World');
1113+
assert.strictEqual(query.original, 'Hello World');
11131114
assert.strictEqual(query.normalized, 'HelloWorld');
11141115
assert.strictEqual(query.normalizedLowercase, 'HelloWorld'.toLowerCase());
11151116
assert.strictEqual(query.values?.length, 2);
1116-
assert.strictEqual(query.values?.[0].original, 'He*llo');
1117+
assert.strictEqual(query.values?.[0].raw, 'He*llo');
1118+
assert.strictEqual(query.values?.[0].original, 'Hello');
11171119
assert.strictEqual(query.values?.[0].normalized, 'Hello');
11181120
assert.strictEqual(query.values?.[0].normalizedLowercase, 'Hello'.toLowerCase());
1121+
assert.strictEqual(query.values?.[1].raw, 'World');
11191122
assert.strictEqual(query.values?.[1].original, 'World');
11201123
assert.strictEqual(query.values?.[1].normalized, 'World');
11211124
assert.strictEqual(query.values?.[1].normalizedLowercase, 'World'.toLowerCase());
@@ -1127,15 +1130,18 @@ suite('Fuzzy Scorer', () => {
11271130

11281131
// with spaces that are empty
11291132
query = prepareQuery(' Hello World ');
1133+
assert.strictEqual(query.raw, ' Hello World ');
11301134
assert.strictEqual(query.original, ' Hello World ');
11311135
assert.strictEqual(query.originalLowercase, ' Hello World '.toLowerCase());
11321136
assert.strictEqual(query.normalized, 'HelloWorld');
11331137
assert.strictEqual(query.normalizedLowercase, 'HelloWorld'.toLowerCase());
11341138
assert.strictEqual(query.values?.length, 2);
1139+
assert.strictEqual(query.values?.[0].raw, 'Hello');
11351140
assert.strictEqual(query.values?.[0].original, 'Hello');
11361141
assert.strictEqual(query.values?.[0].originalLowercase, 'Hello'.toLowerCase());
11371142
assert.strictEqual(query.values?.[0].normalized, 'Hello');
11381143
assert.strictEqual(query.values?.[0].normalizedLowercase, 'Hello'.toLowerCase());
1144+
assert.strictEqual(query.values?.[1].raw, 'World');
11391145
assert.strictEqual(query.values?.[1].original, 'World');
11401146
assert.strictEqual(query.values?.[1].originalLowercase, 'World'.toLowerCase());
11411147
assert.strictEqual(query.values?.[1].normalized, 'World');

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export class SymbolsQuickAccessProvider extends PickerQuickAccessProvider<ISymbo
110110
}
111111

112112
// Run the workspace symbol query
113-
const workspaceSymbols = await getWorkspaceSymbols(symbolQuery.original, token);
113+
const workspaceSymbols = await getWorkspaceSymbols(symbolQuery.raw, token);
114114
if (token.isCancellationRequested) {
115115
return [];
116116
}

0 commit comments

Comments
 (0)