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

Function loadFile

src/ui-server/api/flow.ts:355–399  ·  view source on GitHub ↗
(
  cg: CodeGraph,
  projectRoot: string,
  cache: Map<string, FileCache>,
  filePath: string
)

Source from the content-addressed store, hash-verified

353}
354
355function loadFile(
356 cg: CodeGraph,
357 projectRoot: string,
358 cache: Map<string, FileCache>,
359 filePath: string
360): FileCache | null {
361 const posix = toRequestPath(filePath);
362 const hit = cache.get(posix);
363 if (hit) return hit;
364
365 const found = findIndexedFile(cg, posix);
366 if (!found) return null;
367
368 let entry: FileCache;
369 if (hasDriftedOnDisk(projectRoot, found.storedPath, found.record)) {
370 entry = {
371 lines: null,
372 language: found.record.language,
373 drift: true,
374 reason:
375 'This file changed on disk after the last index sync, so the recorded call ' +
376 'line no longer reliably points at this call. The window returns after the next sync.',
377 };
378 } else {
379 try {
380 // The chokepoint, before anything is opened — see `source.ts`.
381 const absolute = resolveProjectFile(projectRoot, found.storedPath);
382 entry = {
383 lines: splitLines(fs.readFileSync(absolute, 'utf-8')),
384 language: found.record.language,
385 abs: absolute,
386 drift: false,
387 };
388 } catch {
389 entry = {
390 lines: null,
391 language: found.record.language,
392 drift: false,
393 reason: 'This file is in the index but could not be read.',
394 };
395 }
396 }
397 cache.set(posix, entry);
398 return entry;
399}
400
401/**
402 * The ±{@link SOURCE_WINDOW} lines a card shows.

Callers 2

windowForFunction · 0.85
whenAtFunction · 0.85

Calls 7

toRequestPathFunction · 0.90
findIndexedFileFunction · 0.90
hasDriftedOnDiskFunction · 0.90
resolveProjectFileFunction · 0.90
splitLinesFunction · 0.90
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected