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

Method indexFileWithContent

src/extraction/index.ts:3277–3338  ·  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

3275 * Used by the parallel batch reader to avoid redundant file I/O.
3276 */
3277 async indexFileWithContent(
3278 relativePath: string,
3279 content: string,
3280 stats: fs.Stats
3281 ): Promise<ExtractionResult> {
3282 // Prevent `../` traversal; follow in-root symlinks like the directory walk (#935).
3283 const fullPath = validatePathWithinRoot(this.rootDir, relativePath, { allowSymlinkEscape: true });
3284 if (!fullPath) {
3285 logWarn('Path traversal blocked in indexFileWithContent', { relativePath });
3286 return {
3287 nodes: [],
3288 edges: [],
3289 unresolvedReferences: [],
3290 errors: [{ message: 'Path traversal blocked', filePath: relativePath, severity: 'error', code: 'path_traversal' }],
3291 durationMs: 0,
3292 };
3293 }
3294
3295 const language = detectLanguage(relativePath, content, loadExtensionOverrides(this.rootDir), this.rootDir);
3296
3297 // Check file size
3298 if (stats.size > MAX_SOURCE_FILE_SIZE_BYTES) {
3299 const result: ExtractionResult = {
3300 nodes: [],
3301 edges: [],
3302 unresolvedReferences: [],
3303 errors: [
3304 {
3305 message: `File exceeds max size (${stats.size} > ${MAX_SOURCE_FILE_SIZE_BYTES})`,
3306 filePath: relativePath,
3307 severity: 'warning',
3308 code: 'size_exceeded',
3309 },
3310 ],
3311 durationMs: 0,
3312 };
3313 await this.storeExtractionResult(relativePath, content, language, stats, result, createYielder());
3314 return result;
3315 }
3316
3317 // Detect language (honoring the project's codegraph.json extension overrides)
3318 if (!isLanguageSupported(language)) {
3319 return {
3320 nodes: [],
3321 edges: [],
3322 unresolvedReferences: [],
3323 errors: [],
3324 durationMs: 0,
3325 };
3326 }
3327
3328 // Extract from source. Use cached framework names if indexAll has run,
3329 // otherwise detect on the spot so single-file re-index paths still emit
3330 // route nodes / middleware / etc.
3331 const frameworkNames = this.frameworksForFile(relativePath, this.ensureDetectedFrameworks());
3332 const result = extractFromSource(relativePath, content, language, frameworkNames);
3333
3334 // 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