|
1 |
| -import { spawn } from 'child_process' |
2 |
| -import ospath from 'path' |
3 | 1 | import vscode, { Uri } from 'vscode'
|
4 |
| -import { getWorkspaceFolders } from './workspace' |
5 | 2 |
|
6 | 3 | /**
|
7 | 4 | * Find files across all workspace folders in the workspace using a glob expression.
|
8 |
| - * Use `@vscode/ripgrep` to find files when there is a platform shell present. |
9 | 5 | * @param glob A glob pattern that defines the files to search for.
|
10 | 6 | */
|
11 | 7 | export async function findFiles (glob: string): Promise<Uri[]> {
|
12 |
| - if ('browser' in process && (process as any).browser === true) { |
13 |
| - return vscode.workspace.findFiles(glob) |
14 |
| - } |
15 |
| - const searchedUris : Uri[] = [] |
16 |
| - for (const workspaceFolder of getWorkspaceFolders()) { |
17 |
| - const rootUri = workspaceFolder.uri |
18 |
| - const paths = await ripgrep(glob, rootUri.fsPath) |
19 |
| - searchedUris.push(...paths.map((path) => Uri.joinPath(rootUri, path))) |
20 |
| - } |
21 |
| - return searchedUris |
22 |
| -} |
23 |
| - |
24 |
| -async function ripgrep (glob: string, rootFolder: string): Promise<string[]> { |
25 |
| - const rgPath = ospath.join(vscode.env.appRoot, `node_modules/@vscode/ripgrep/bin/rg${process.platform === 'win32' ? '.exe' : ''}`) |
26 |
| - return new Promise((resolve, reject) => { |
27 |
| - const rg = spawn(rgPath, ['--hidden', '--follow', '--files', '-g', glob], { cwd: rootFolder }) |
28 |
| - let stdout : string = '' |
29 |
| - let stderr = '' |
30 |
| - |
31 |
| - rg.stdout.on('data', (data) => { |
32 |
| - stdout += data.toString() |
33 |
| - }) |
34 |
| - |
35 |
| - rg.stderr.on('data', (data) => { |
36 |
| - stderr += data.toString() |
37 |
| - }) |
38 |
| - |
39 |
| - rg.on('close', (code) => { |
40 |
| - if (code === 0) { |
41 |
| - const result = stdout.split('\n') |
42 |
| - .map((path) => path.trim()) |
43 |
| - .filter((path) => !!path) // ensure empty strings are deleted from answer |
44 |
| - resolve(result) |
45 |
| - } else if (code === 1) { |
46 |
| - resolve([]) |
47 |
| - } else { |
48 |
| - reject(new Error(`code ${code}: ${stderr}`)) |
49 |
| - } |
50 |
| - }) |
51 |
| - |
52 |
| - rg.on('error', (err) => { |
53 |
| - reject(err) |
54 |
| - }) |
55 |
| - }) |
| 8 | + return vscode.workspace.findFiles(glob) |
56 | 9 | }
|
0 commit comments