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

Method readFile

src/mcp/tools.ts:8423–8438  ·  view source on GitHub ↗
(filePath: string)

Source from the content-addressed store, hash-verified

8421 // a changed file's indexed line numbers can point at other code (#1474).
8422 const read = new Map<string, { content: string; lines: string[] } | null>();
8423 const readFile = (filePath: string) => {
8424 const held = read.get(filePath);
8425 if (held !== undefined) return held;
8426 let entry: { content: string; lines: string[] } | null = null;
8427 try {
8428 const abs = validatePathWithinRoot(projectRoot, filePath);
8429 if (abs && existsSync(abs)) {
8430 const content = readFileSync(abs, 'utf-8');
8431 if (!this.isFileStaleOnDisk(cg, filePath, content)) entry = { content, lines: content.split(/\r?\n/) };
8432 }
8433 } catch {
8434 entry = null;
8435 }
8436 read.set(filePath, entry);
8437 return entry;
8438 };
8439
8440 const isTest = this.testCodeReading(cg);
8441 const rel = (p: string) => p.replace(/\\/g, '/');

Callers

nothing calls this directly

Calls 4

isFileStaleOnDiskMethod · 0.95
validatePathWithinRootFunction · 0.90
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected