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

Method readFile

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

Source from the content-addressed store, hash-verified

8172 // a changed file's indexed line numbers can point at other code (#1474).
8173 const read = new Map<string, { content: string; lines: string[] } | null>();
8174 const readFile = (filePath: string) => {
8175 const held = read.get(filePath);
8176 if (held !== undefined) return held;
8177 let entry: { content: string; lines: string[] } | null = null;
8178 try {
8179 const abs = validatePathWithinRoot(projectRoot, filePath);
8180 if (abs && existsSync(abs)) {
8181 const content = readFileSync(abs, 'utf-8');
8182 if (!this.isFileStaleOnDisk(cg, filePath, content)) entry = { content, lines: content.split(/\r?\n/) };
8183 }
8184 } catch {
8185 entry = null;
8186 }
8187 read.set(filePath, entry);
8188 return entry;
8189 };
8190
8191 const isTest = this.testCodeReading(cg);
8192 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