Skip to content

Commit 1f916a7

Browse files
committed
Fix code search bug
1 parent 5dc691c commit 1f916a7

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

sdk/src/tools/code-search.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { spawn } from 'child_process'
2+
import * as fs from 'fs'
23
import * as path from 'path'
34

45
import { formatCodeSearchOutput } from '../../../common/src/util/format-code-search'
@@ -67,8 +68,16 @@ export function codeSearch({
6768
// -n shows line numbers
6869
// --json outputs in JSON format, which streams in and allows us to cut off the output if it grows too long
6970
// "--"" prevents pattern from being misparsed as a flag (e.g., pattern starting with '-')
70-
// Search paths: '.' plus blessed hidden directories (ripgrep ignores non-existent paths)
71-
const searchPaths = ['.', ...INCLUDED_HIDDEN_DIRS]
71+
// Search paths: '.' plus blessed hidden directories that actually exist
72+
// Filter out non-existent directories to avoid ripgrep stderr errors
73+
const existingHiddenDirs = INCLUDED_HIDDEN_DIRS.filter((dir) => {
74+
try {
75+
return fs.statSync(path.join(searchCwd, dir)).isDirectory()
76+
} catch {
77+
return false
78+
}
79+
})
80+
const searchPaths = ['.', ...existingHiddenDirs]
7281
const args = [
7382
'--no-config',
7483
'-n',

0 commit comments

Comments
 (0)