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

Method indexFileWithContent

src/extraction/index.ts:3314–3375  ·  view source on GitHub ↗

* Index a single file with pre-read content and stats. * Used by the parallel batch reader to avoid redundant file I/O.

(
    relativePath: string,
    content: string,
    stats: fs.Stats
  )

Source from the content-addressed store, hash-verified

3312 * Used by the parallel batch reader to avoid redundant file I/O.
3313 */
3314 async indexFileWithContent(
3315 relativePath: string,
3316 content: string,
3317 stats: fs.Stats
3318 ): Promise<ExtractionResult> {
3319 // Prevent `../` traversal; follow in-root symlinks like the directory walk (#935).
3320 const fullPath = validatePathWithinRoot(this.rootDir, relativePath, { allowSymlinkEscape: true });
3321 if (!fullPath) {
3322 logWarn('Path traversal blocked in indexFileWithContent', { relativePath });
3323 return {
3324 nodes: [],
3325 edges: [],
3326 unresolvedReferences: [],
3327 errors: [{ message: 'Path traversal blocked', filePath: relativePath, severity: 'error', code: 'path_traversal' }],
3328 durationMs: 0,
3329 };
3330 }
3331
3332 const language = detectLanguage(relativePath, content, loadExtensionOverrides(this.rootDir), this.rootDir);
3333
3334 // Check file size
3335 if (stats.size > MAX_SOURCE_FILE_SIZE_BYTES) {
3336 const result: ExtractionResult = {
3337 nodes: [],
3338 edges: [],
3339 unresolvedReferences: [],
3340 errors: [
3341 {
3342 message: `File exceeds max size (${stats.size} > ${MAX_SOURCE_FILE_SIZE_BYTES})`,
3343 filePath: relativePath,
3344 severity: 'warning',
3345 code: 'size_exceeded',
3346 },
3347 ],
3348 durationMs: 0,
3349 };
3350 await this.storeExtractionResult(relativePath, content, language, stats, result, createYielder());
3351 return result;
3352 }
3353
3354 // Detect language (honoring the project's codegraph.json extension overrides)
3355 if (!isLanguageSupported(language)) {
3356 return {
3357 nodes: [],
3358 edges: [],
3359 unresolvedReferences: [],
3360 errors: [],
3361 durationMs: 0,
3362 };
3363 }
3364
3365 // Extract from source. Use cached framework names if indexAll has run,
3366 // otherwise detect on the spot so single-file re-index paths still emit
3367 // route nodes / middleware / etc.
3368 const frameworkNames = this.frameworksForFile(relativePath, this.ensureDetectedFrameworks());
3369 const result = extractFromSource(relativePath, content, language, frameworkNames);
3370
3371 // Store in database

Callers 1

indexFileMethod · 0.95

Calls 10

storeExtractionResultMethod · 0.95
frameworksForFileMethod · 0.95
validatePathWithinRootFunction · 0.90
logWarnFunction · 0.90
detectLanguageFunction · 0.90
loadExtensionOverridesFunction · 0.90
createYielderFunction · 0.90
isLanguageSupportedFunction · 0.90
extractFromSourceFunction · 0.90

Tested by

no test coverage detected