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

Function edges

__tests__/go-local-shadows-function.test.ts:22–38  ·  view source on GitHub ↗
(files: Record<string, string>, fromName: string)

Source from the content-addressed store, hash-verified

20let cg: CodeGraph | null = null;
21
22async function edges(files: Record<string, string>, fromName: string): Promise<string[]> {
23 tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'codegraph-2580-'));
24 for (const [rel, source] of Object.entries(files)) {
25 fs.mkdirSync(path.dirname(path.join(tempDir, rel)), { recursive: true });
26 fs.writeFileSync(path.join(tempDir, rel), source);
27 }
28 cg = await CodeGraph.init(tempDir, { index: true });
29 cg.resolveReferences();
30 const from = cg.getNodesByKind('function').find((n) => n.name === fromName)!;
31 expect(from).toBeDefined();
32 return cg
33 .getOutgoingEdges(from.id)
34 .filter((e) => e.kind === 'calls')
35 .map((e) => [e, cg!.getNode(e.target)] as const)
36 .filter(([, n]) => n?.kind === 'function')
37 .map(([e, n]) => `${e.kind} ${n!.name} L${e.line}`);
38}
39
40/** `package main` with the package-level `run`, `body`, and a `main` that calls `call`. */
41function mainGo(body: string, call: string): Record<string, string> {

Calls 7

resolveReferencesMethod · 0.80
mapMethod · 0.80
getNodeMethod · 0.80
getNodesByKindMethod · 0.65
joinMethod · 0.45
initMethod · 0.45
getOutgoingEdgesMethod · 0.45

Tested by

no test coverage detected