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

Function annotateWhen

src/ui-server/api/when.ts:58–95  ·  view source on GitHub ↗
(cg: CodeGraph, projectRoot: string, batches: readonly WhenBatch[])

Source from the content-addressed store, hash-verified

56}
57
58export async function annotateWhen(cg: CodeGraph, projectRoot: string, batches: readonly WhenBatch[]): Promise<void> {
59 const byFile = new Map<string, WireEdge[]>();
60 for (const batch of batches) {
61 const bucket = byFile.get(batch.file);
62 if (bucket) bucket.push(...batch.edges);
63 else byFile.set(batch.file, [...batch.edges]);
64 }
65 let files = 0;
66 let sites = 0;
67 const started = Date.now();
68 for (const [file, edges] of byFile) {
69 if (files >= MAX_FILES || sites >= MAX_SITES) return;
70 if (files > 0 && Date.now() - started > BUDGET_MS) return;
71 const found = findIndexedFile(cg, file);
72 if (!found || !supportsBranchGuards(found.record.language)) continue;
73 if (hasDriftedOnDisk(projectRoot, found.storedPath, found.record)) continue;
74 let abs: string;
75 try {
76 abs = resolveProjectFile(projectRoot, found.storedPath);
77 } catch {
78 continue;
79 }
80 const withLine = edges.filter((e) => typeof e.line === 'number' && e.line > 0);
81 if (withLine.length === 0) continue;
82 files++;
83 sites += withLine.length;
84 const guards = await guardsForFile(
85 abs,
86 found.record.language as Language,
87 withLine.map((e) => ({ line: e.line!, column: typeof e.col === 'number' ? e.col : null }))
88 );
89 for (const edge of withLine) {
90 const g = guards.get(siteKey({ line: edge.line!, column: typeof edge.col === 'number' ? edge.col : null }));
91 const label = g ? guardLabel(g) : '';
92 if (label) edge.when = label;
93 }
94 }
95}
96
97/**
98 * A per-request reader of the conditions ONE call site sits under, for the

Callers 1

buildNodeFunction · 0.90

Calls 11

findIndexedFileFunction · 0.90
supportsBranchGuardsFunction · 0.90
hasDriftedOnDiskFunction · 0.90
resolveProjectFileFunction · 0.90
guardsForFileFunction · 0.90
siteKeyFunction · 0.90
guardLabelFunction · 0.90
pushMethod · 0.80
mapMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected