MCPcopy Create free account
hub / github.com/PatrickSys/codebase-context / scanFiles

Method scanFiles

src/core/indexer.ts:1091–1154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1089 }
1090
1091 private async scanFiles(): Promise<string[]> {
1092 const files: string[] = [];
1093 const seen = new Set<string>();
1094
1095 // Read .gitignore if respecting it
1096 let ig: ReturnType<typeof ignore.default> | null = null;
1097 if (this.config.respectGitignore) {
1098 try {
1099 const gitignorePath = path.join(this.rootPath, '.gitignore');
1100 const gitignoreContent = await fs.readFile(gitignorePath, 'utf-8');
1101 ig = ignore.default().add(gitignoreContent);
1102 } catch (_error) {
1103 // No .gitignore or couldn't read it
1104 }
1105 }
1106
1107 // Scan with glob
1108 const includePatterns = this.getIncludePatterns();
1109 const excludePatterns = this.config.exclude || [];
1110
1111 for (const pattern of includePatterns) {
1112 const matches = await glob(pattern, {
1113 cwd: this.rootPath,
1114 absolute: true,
1115 ignore: excludePatterns,
1116 nodir: true
1117 });
1118
1119 for (const file of matches) {
1120 const normalizedFile = file.replace(/\\/g, '/');
1121 if (seen.has(normalizedFile)) {
1122 continue;
1123 }
1124 seen.add(normalizedFile);
1125
1126 const relativePath = path.relative(this.rootPath, file);
1127
1128 // Check gitignore
1129 if (ig && ig.ignores(relativePath)) {
1130 continue;
1131 }
1132
1133 // Check if it's a code file
1134 if (!isCodeFile(file, this.supportedCodeExtensions) || isBinaryFile(file)) {
1135 continue;
1136 }
1137
1138 // Check file size
1139 try {
1140 const stats = await fs.stat(file);
1141 if (stats.size > (this.config.parsing?.maxFileSize || 1048576)) {
1142 console.warn(`Skipping large file: ${file} (${stats.size} bytes)`);
1143 continue;
1144 }
1145 } catch (_error) {
1146 continue;
1147 }
1148

Callers 1

indexMethod · 0.95

Calls 5

getIncludePatternsMethod · 0.95
isCodeFileFunction · 0.85
isBinaryFileFunction · 0.85
hasMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected