Skip to content

Commit c854814

Browse files
authoredOct 31, 2024··
fix(ripgrep): replace ripgrep by workspace.findFiles (#920)
1 parent ac3064b commit c854814

File tree

1 file changed

+1
-48
lines changed

1 file changed

+1
-48
lines changed
 

‎src/util/findFiles.ts

+1-48
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,9 @@
1-
import { spawn } from 'child_process'
2-
import ospath from 'path'
31
import vscode, { Uri } from 'vscode'
4-
import { getWorkspaceFolders } from './workspace'
52

63
/**
74
* 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.
95
* @param glob A glob pattern that defines the files to search for.
106
*/
117
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)
569
}

0 commit comments

Comments
 (0)
Please sign in to comment.