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

Function getClosure

graph-ui/src/provider/closure.ts:276–365  ·  view source on GitHub ↗
(
    source: ClosureSource,
    workspaceRoot: string,
    root: SymbolRef,
    options: ClosureOptions = {},
)

Source from the content-addressed store, hash-verified

274 * row order wearing a disguise.
275 */
276export async function getClosure(
277 source: ClosureSource,
278 workspaceRoot: string,
279 root: SymbolRef,
280 options: ClosureOptions = {},
281): Promise<ClosureResult> {
282 const depth = clampBound(options.depth, CLOSURE_DEFAULT_DEPTH, CLOSURE_MAX_DEPTH);
283 const cap = clampBound(options.cap, CLOSURE_DEFAULT_CAP, CLOSURE_MAX_CAP);
284 const opts: ProviderQueryOptions = {
285 ...(options.projectName === undefined ? {} : { projectName: options.projectName }),
286 ...(options.generation === undefined ? {} : { generation: options.generation }),
287 };
288
289 const rootKey = closureKeyOf(root);
290 const nodes: ClosureNode[] = [{ symbol: root, hop: 0 }];
291 const edges: ClosureEdge[] = [];
292 /** Call-site identity to the identity of the symbol it resolved to. */
293 const published = new Map<string, string>([[rootKey, rootKey]]);
294 /** Identities that are in `nodes`. */
295 const admitted = new Set<string>([rootKey]);
296 /** Call-site identities a bound turned away, counted but not returned. */
297 const refused = new Set<string>();
298 let truncated = false;
299 let frontier: SymbolRef[] = [root];
300
301 for (let level = 0; level < depth && frontier.length > 0; level++) {
302 /** Every call this layer reported, in frontier order then alphabetical. */
303 const found: { from: string; to: string; call: CallSite }[] = [];
304 for (const from of frontier) {
305 const facts = await source
306 .getFacts(workspaceRoot, from, ['callees'], opts)
307 .catch(() => ({}) as SymbolFacts);
308 const fromKey = closureKeyOf(from);
309 const layer = (facts.callees?.value ?? [])
310 .map((call) => ({ from: fromKey, to: closureCallKey(call), call }))
311 .filter((entry) => entry.to.length > 0)
312 .sort((a, b) => compareText(a.to, b.to));
313 found.push(...layer);
314 }
315
316 const next: SymbolRef[] = [];
317 for (const to of [...new Set(found.map((entry) => entry.to))].sort(compareText)) {
318 if (published.has(to)) {
319 continue;
320 }
321 if (nodes.length >= cap) {
322 // The cap turned it away. Counted in `visited`, absent from
323 // `nodes`, and no edge is drawn for it: an arrow into a symbol
324 // the answer does not hold would be a picture of something a
325 // reader cannot look at.
326 refused.add(to);
327 truncated = true;
328 continue;
329 }
330 const first = found.find((entry) => entry.to === to)!;
331 const resolved = await resolveCallee(source, workspaceRoot, first.call, opts);
332 const key = closureKeyOf(resolved);
333 published.set(to, key);

Callers 3

ProjectWindowViewFunction · 0.90
loadSelectionHierarchyFunction · 0.90
closure.test.tsFile · 0.90

Calls 8

clampBoundFunction · 0.85
closureKeyOfFunction · 0.85
closureCallKeyFunction · 0.85
resolveCalleeFunction · 0.85
compareTextFunction · 0.70
getFactsMethod · 0.65
getMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected