MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / scanDirectory

Function scanDirectory

src/extraction/index.ts:1187–1211  ·  view source on GitHub ↗
(
  rootDir: string,
  onProgress?: (current: number, file: string) => void
)

Source from the content-addressed store, hash-verified

1185 * projects, falls back to a filesystem walk that parses .gitignore itself.
1186 */
1187export function scanDirectory(
1188 rootDir: string,
1189 onProgress?: (current: number, file: string) => void
1190): string[] {
1191 // Custom extension → language overrides from the project's codegraph.json.
1192 const overrides = loadExtensionOverrides(rootDir);
1193
1194 // Fast path: use git to get all visible files (respects .gitignore everywhere)
1195 const gitFiles = getGitVisibleFiles(rootDir);
1196 if (gitFiles) {
1197 const files: string[] = [];
1198 let count = 0;
1199 for (const filePath of gitFiles) {
1200 if (isSourceFile(filePath, overrides)) {
1201 files.push(filePath);
1202 count++;
1203 onProgress?.(count, filePath);
1204 }
1205 }
1206 return files;
1207 }
1208
1209 // Fallback: walk filesystem for non-git projects
1210 return scanDirectoryWalk(rootDir, onProgress);
1211}
1212
1213/**
1214 * Async variant of scanDirectory that yields to the event loop periodically,

Callers 7

security.test.tsFile · 0.90
scanFunction · 0.90
extraction.test.tsFile · 0.90
getChangedFilesMethod · 0.85

Calls 5

loadExtensionOverridesFunction · 0.90
isSourceFileFunction · 0.90
getGitVisibleFilesFunction · 0.85
onProgressFunction · 0.85
scanDirectoryWalkFunction · 0.85

Tested by 1

scanFunction · 0.72