MCPcopy
hub / github.com/codeaashu/claude-code / filterGitIgnoredLocations

Function filterGitIgnoredLocations

src/tools/LSPTool/LSPTool.ts:556–611  ·  view source on GitHub ↗

* Filters out locations whose file paths are gitignored. * Uses `git check-ignore` with batched path arguments for efficiency.

(
  locations: T[],
  cwd: string,
)

Source from the content-addressed store, hash-verified

554 * Uses `git check-ignore` with batched path arguments for efficiency.
555 */
556async function filterGitIgnoredLocations<T extends Location>(
557 locations: T[],
558 cwd: string,
559): Promise<T[]> {
560 if (locations.length === 0) {
561 return locations
562 }
563
564 // Collect unique file paths from URIs
565 const uriToPath = new Map<string, string>()
566 for (const loc of locations) {
567 if (loc.uri && !uriToPath.has(loc.uri)) {
568 uriToPath.set(loc.uri, uriToFilePath(loc.uri))
569 }
570 }
571
572 const uniquePaths = uniq(uriToPath.values())
573 if (uniquePaths.length === 0) {
574 return locations
575 }
576
577 // Batch check paths with git check-ignore
578 // Exit code 0 = at least one path is ignored, 1 = none ignored, 128 = not a git repo
579 const ignoredPaths = new Set<string>()
580 const BATCH_SIZE = 50
581 for (let i = 0; i < uniquePaths.length; i += BATCH_SIZE) {
582 const batch = uniquePaths.slice(i, i + BATCH_SIZE)
583 const result = await execFileNoThrowWithCwd(
584 'git',
585 ['check-ignore', ...batch],
586 {
587 cwd,
588 preserveOutputOnError: false,
589 timeout: 5_000,
590 },
591 )
592
593 if (result.code === 0 && result.stdout) {
594 for (const line of result.stdout.split('\n')) {
595 const trimmed = line.trim()
596 if (trimmed) {
597 ignoredPaths.add(trimmed)
598 }
599 }
600 }
601 }
602
603 if (ignoredPaths.size === 0) {
604 return locations
605 }
606
607 return locations.filter(loc => {
608 const filePath = uriToPath.get(loc.uri)
609 return !filePath || !ignoredPaths.has(filePath)
610 })
611}
612
613/**

Callers 1

callFunction · 0.85

Calls 8

uriToFilePathFunction · 0.85
uniqFunction · 0.85
execFileNoThrowWithCwdFunction · 0.85
valuesMethod · 0.80
getMethod · 0.65
hasMethod · 0.45
setMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected