MCPcopy Index your code
hub / github.com/codeaashu/claude-code / loadRipgrepIgnorePatterns

Function loadRipgrepIgnorePatterns

src/hooks/fileSuggestions.ts:202–238  ·  view source on GitHub ↗

* Load ripgrep-specific ignore patterns from .ignore or .rgignore files * Returns an ignore instance if patterns were found, null otherwise * Results are cached per repoRoot:cwd combination

(
  repoRoot: string,
  cwd: string,
)

Source from the content-addressed store, hash-verified

200 * Results are cached per repoRoot:cwd combination
201 */
202async function loadRipgrepIgnorePatterns(
203 repoRoot: string,
204 cwd: string,
205): Promise<ReturnType<typeof ignore> | null> {
206 const cacheKey = `${repoRoot}:${cwd}`
207
208 // Return cached result if available
209 if (ignorePatternsCacheKey === cacheKey) {
210 return ignorePatternsCache
211 }
212
213 const fs = getFsImplementation()
214 const ignoreFiles = ['.ignore', '.rgignore']
215 const directories = [...new Set([repoRoot, cwd])]
216
217 const ig = ignore()
218 let hasPatterns = false
219
220 const paths = directories.flatMap(dir =>
221 ignoreFiles.map(f => path.join(dir, f)),
222 )
223 const contents = await Promise.all(
224 paths.map(p => fs.readFile(p, { encoding: 'utf8' }).catch(() => null)),
225 )
226 for (const [i, content] of contents.entries()) {
227 if (content === null) continue
228 ig.add(content)
229 hasPatterns = true
230 logForDebugging(`[FileIndex] loaded ignore patterns from ${paths[i]}`)
231 }
232
233 const result = hasPatterns ? ig : null
234 ignorePatternsCache = result
235 ignorePatternsCacheKey = cacheKey
236
237 return result
238}
239
240/**
241 * Get files using git ls-files (much faster than ripgrep for git repos)

Callers 1

getFilesUsingGitFunction · 0.85

Calls 5

getFsImplementationFunction · 0.85
logForDebuggingFunction · 0.85
readFileMethod · 0.80
entriesMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected