| 1185 | * projects, falls back to a filesystem walk that parses .gitignore itself. |
| 1186 | */ |
| 1187 | export 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, |