Skip to content

Commit

Permalink
Make Explorer Find widget work in 1.94 as long as proposed APIs are e…
Browse files Browse the repository at this point in the history
…nabled (fix #1443)
  • Loading branch information
gjsjohnmurray committed Oct 4, 2024
1 parent 0b00c74 commit 544af86
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/providers/FileSystemProvider/FileSearchProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export class FileSearchProvider implements vscode.FileSearchProvider {
): Promise<vscode.Uri[]> {
let counter = 0;
let pattern = query.pattern.charAt(0) == "/" ? query.pattern.slice(1) : query.pattern;

// Drop a leading **/ from the glob pattern if it exists (added by Find widget of Explorer tree, which since 1.94 uses FileSearchProvider)
if (pattern.startsWith("**/")) {
pattern = pattern.slice(3);
}
const params = new URLSearchParams(options.folder.query);
const csp = params.has("csp") && ["", "1"].includes(params.get("csp"));
if (params.has("project") && params.get("project").length) {
Expand All @@ -44,13 +49,17 @@ export class FileSearchProvider implements vscode.FileSearchProvider {
// When this is called without a query.pattern, every file is supposed to be returned, so do not provide a filter
let filter = "";
if (pattern.length) {
pattern = !csp ? query.pattern.replace(/\//g, ".") : query.pattern;
let escapeClause = "";
pattern = !csp ? pattern.replace(/\//g, ".") : pattern;
if (pattern.includes("_") || pattern.includes("%")) {
// Need to escape any % or _ characters
filter = `Name LIKE '%${pattern.replace(/(_|%|\\)/g, "\\$1")}%' ESCAPE '\\'`;
} else {
filter = `Name LIKE '%${pattern}%'`;
pattern = pattern.replace(/(_|%|\\)/g, "\\$1");
escapeClause = " ESCAPE '\\'";
}
// Change glob syntax to SQL LIKE syntax
pattern = pattern.replace(/\*/g, "%");
pattern = pattern.replace(/\?/g, "_");
filter = `Name LIKE '%${pattern}%'${escapeClause}`;
}
if (token.isCancellationRequested) {
return;
Expand Down

0 comments on commit 544af86

Please sign in to comment.