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) (#1444)

* Make Explorer Find widget work in 1.94 as long as proposed APIs are enabled (fix #1443)

* Adopt feedback
  • Loading branch information
gjsjohnmurray authored Oct 4, 2024
1 parent 0b00c74 commit e2b75ab
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 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,13 @@ 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;
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 = !csp ? pattern.replace(/\//g, ".") : pattern;
filter = `Name LIKE '%${pattern
// Escape % or _ characters
.replace(/(_|%|\\)/g, "\\$1")
// Change glob syntax to SQL LIKE syntax
.replace(/\*/g, "%")
.replace(/\?/g, "_")}%' ESCAPE '\\'`;
}
if (token.isCancellationRequested) {
return;
Expand Down

0 comments on commit e2b75ab

Please sign in to comment.