Skip to content

Commit 5ecb4a2

Browse files
authored
fix: make ripgrep lazy load, to fix vscode ide companion unable to start (#676)
1 parent 9c1d722 commit 5ecb4a2

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

packages/core/src/tools/ripGrep.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import fs from 'node:fs';
88
import path from 'node:path';
99
import { EOL } from 'node:os';
1010
import { spawn } from 'node:child_process';
11-
import { rgPath } from '@lvce-editor/ripgrep';
1211
import type { ToolInvocation, ToolResult } from './tools.js';
1312
import { BaseDeclarativeTool, BaseToolInvocation, Kind } from './tools.js';
1413
import { SchemaValidator } from '../utils/schemaValidator.js';
@@ -18,6 +17,14 @@ import type { Config } from '../config/config.js';
1817

1918
const DEFAULT_TOTAL_MAX_MATCHES = 20000;
2019

20+
/**
21+
* Lazy loads the ripgrep binary path to avoid loading the library until needed
22+
*/
23+
async function getRipgrepPath(): Promise<string> {
24+
const { rgPath } = await import('@lvce-editor/ripgrep');
25+
return rgPath;
26+
}
27+
2128
/**
2229
* Parameters for the GrepTool
2330
*/
@@ -292,8 +299,9 @@ class GrepToolInvocation extends BaseToolInvocation<
292299
rgArgs.push(absolutePath);
293300

294301
try {
302+
const ripgrepPath = await getRipgrepPath();
295303
const output = await new Promise<string>((resolve, reject) => {
296-
const child = spawn(rgPath, rgArgs, {
304+
const child = spawn(ripgrepPath, rgArgs, {
297305
windowsHide: true,
298306
});
299307

0 commit comments

Comments
 (0)