Skip to content

Commit a693ffd

Browse files
committed
PR feedback
1 parent 55ad013 commit a693ffd

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/__mocks__/services/ripgrep/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ export const regexSearchFiles = jest
4343
* @param maxLength - Optional maximum length (can be undefined)
4444
* @returns The original line or empty string if undefined
4545
*/
46-
export const truncateLine = jest.fn().mockImplementation((line: string, maxLength?: number): string => {
46+
export const truncateLine = jest.fn().mockImplementation((line?: string, maxLength?: number): string => {
4747
return line || ""
4848
})

src/services/glob/list-files.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,13 @@ async function execRipgrep(rgPath: string, args: string[], limit: number): Promi
341341
let output = ""
342342
let results: string[] = []
343343

344+
// Set timeout to avoid hanging
345+
const timeoutId = setTimeout(() => {
346+
rgProcess.kill()
347+
console.warn("ripgrep timed out, returning partial results")
348+
resolve(results.slice(0, limit))
349+
}, 10_000)
350+
344351
// Process stdout data as it comes in
345352
rgProcess.stdout.on("data", (data) => {
346353
output += data.toString()
@@ -349,6 +356,7 @@ async function execRipgrep(rgPath: string, args: string[], limit: number): Promi
349356
// Kill the process if we've reached the limit
350357
if (results.length >= limit) {
351358
rgProcess.kill()
359+
clearTimeout(timeoutId) // Clear the timeout when we kill the process due to reaching the limit
352360
}
353361
})
354362

@@ -357,13 +365,6 @@ async function execRipgrep(rgPath: string, args: string[], limit: number): Promi
357365
console.error(`ripgrep stderr: ${data}`)
358366
})
359367

360-
// Set timeout to avoid hanging
361-
const timeoutId = setTimeout(() => {
362-
rgProcess.kill()
363-
console.warn("ripgrep timed out, returning partial results")
364-
resolve(results.slice(0, limit))
365-
}, 10_000)
366-
367368
// Handle process completion
368369
rgProcess.on("close", (code) => {
369370
// Clear the timeout to avoid memory leaks

0 commit comments

Comments
 (0)