MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / fileIrsFor

Function fileIrsFor

graph-ui/src/pseudocode/imports-source.ts:264–293  ·  view source on GitHub ↗

Fetch the same fact families for every callable in the file, or no file reading at all.

(
    source: ImportsSource,
    root: string,
    request: FileImportsRequest,
)

Source from the content-addressed store, hash-verified

262
263/** Fetch the same fact families for every callable in the file, or no file reading at all. */
264async function fileIrsFor(
265 source: ImportsSource,
266 root: string,
267 request: FileImportsRequest,
268): Promise<SemanticIR[] | undefined> {
269 if (request.source === undefined
270 || source.resolveSymbolAt === undefined
271 || source.getFacts === undefined
272 || source.getSnippet === undefined) {
273 return undefined;
274 }
275 const refs = await Promise.all(callableDeclarationLines(request.source).map(async (line) => {
276 const answer = await source.resolveSymbolAt!(root, request.filePath, line, request.opts).catch(() => undefined);
277 return answer?.kind === 'ok' ? answer.symbol : undefined;
278 }));
279 // A partial collection would make a negative statement about the file
280 // unsound. Keep no `fileIrs` rather than silently judging the subset.
281 if (refs.some((ref) => ref === undefined)) {
282 return undefined;
283 }
284 const unique = [...new Map(refs
285 .filter((ref): ref is NonNullable<typeof ref> => ref !== undefined)
286 .map((ref) => [ref.qualifiedName ?? `${ref.name}:${ref.range.start.line}`, ref])).values()];
287 const provider = source as ImportsSource & IrFactSource;
288 const built = await Promise.all(unique.map((ref) => buildIr(provider, root, ref, request.opts).catch(() => undefined)));
289 if (built.some((entry) => entry === undefined)) {
290 return undefined;
291 }
292 return built.map((entry) => entry!.ir);
293}
294
295/** Was der Aufrufer beisteuert: den Text, falls er ihn hat. */
296export interface FileImportsRequest {

Callers 1

fileImportsForFunction · 0.85

Calls 2

buildIrFunction · 0.90
callableDeclarationLinesFunction · 0.85

Tested by

no test coverage detected