-
Notifications
You must be signed in to change notification settings - Fork 51
fix: bundle ripgrep and fall back to it when VS Code's copy is not found #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1817aa6
bc984af
2c32fad
7a5d665
4b29feb
838fb91
db9f134
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "zoo-code": patch | ||
| --- | ||
|
|
||
| Bundle a ripgrep binary with the extension and fall back to it when ripgrep cannot be located in the VS Code installation. Fixes "Could not find ripgrep binary" errors that break search_files / list_files on VS Code Insiders' newer staged-install layout. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,9 +80,33 @@ export function truncateLine(line: string, maxLength: number = MAX_LINE_LENGTH): | |
| return line.length > maxLength ? line.substring(0, maxLength) + " [truncated...]" : line | ||
| } | ||
| /** | ||
| * Get the path to the ripgrep binary within the VSCode installation | ||
| * Path to the ripgrep binary bundled inside the extension itself. | ||
| * | ||
| * esbuild copies the platform `rg`/`rg.exe` into `dist/bin/<platform>-<arch>/` | ||
| * at build time (see the `copyRipgrep` plugin in esbuild.mjs). At runtime this | ||
| * module is bundled into `dist/extension.js`, so `__dirname` is the extension's | ||
| * `dist/` directory. | ||
| * | ||
| * The `<platform>-<arch>` segment is required: the published VSIX is universal | ||
| * but carries only the build host's binary. Without it, a macOS user would | ||
| * resolve a Linux-built `dist/bin/rg` (the binary name `rg` is shared by Linux | ||
| * and macOS) and execute an incompatible binary. With it, the fallback resolves | ||
| * only on a host matching the bundled binary. | ||
| */ | ||
| export const bundledRgPath = path.join(__dirname, "bin", `${process.platform}-${process.arch}`, binName) | ||
|
|
||
| /** | ||
| * Get the path to the ripgrep binary. | ||
| * | ||
| * Prefers the copy shipped inside the VS Code installation; falls back to the | ||
| * binary bundled with this extension when the VS Code copy cannot be located | ||
| * (e.g. VS Code Insiders' staged-install layout, see microsoft/vscode#252063). | ||
| */ | ||
| export async function getBinPath(vscodeAppRoot: string): Promise<string | undefined> { | ||
| /** | ||
| * Resolve `<pkgFolder>/<binName>` under the VS Code application root, | ||
| * returning the absolute path when the ripgrep binary exists there. | ||
| */ | ||
| const checkPath = async (pkgFolder: string) => { | ||
| const fullPath = path.join(vscodeAppRoot, pkgFolder, binName) | ||
| return (await fileExistsAtPath(fullPath)) ? fullPath : undefined | ||
|
|
@@ -92,7 +116,8 @@ export async function getBinPath(vscodeAppRoot: string): Promise<string | undefi | |
| (await checkPath("node_modules/@vscode/ripgrep/bin/")) || | ||
| (await checkPath("node_modules/vscode-ripgrep/bin")) || | ||
| (await checkPath("node_modules.asar.unpacked/vscode-ripgrep/bin/")) || | ||
| (await checkPath("node_modules.asar.unpacked/@vscode/ripgrep/bin/")) | ||
| (await checkPath("node_modules.asar.unpacked/@vscode/ripgrep/bin/")) || | ||
| ((await fileExistsAtPath(bundledRgPath)) ? bundledRgPath : undefined) | ||
|
Comment on lines
116
to
+120
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in 838fb91. The bundled binary is now copied to and resolved from |
||
| ) | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in 838fb91.
copyRipgrepnow writes the binary underdist/bin/${process.platform}-${process.arch}/, andgetBinPathresolves the matching<platform>-<arch>segment at runtime. A binary built for one OS can no longer be picked up by the fallback on another — even though the VSIX is universal andrgshares a filename across Linux and macOS.