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

Function extract

__tests__/pascal-conditional-blocks.test.ts:39–52  ·  view source on GitHub ↗

Every routine's calls as `Caller->Callee`, sorted, and each routine's lines as `Name:start-end`.

(code: string, file: string)

Source from the content-addressed store, hash-verified

37
38/** Every routine's calls as `Caller->Callee`, sorted, and each routine's lines as `Name:start-end`. */
39function extract(code: string, file: string): { calls: string[]; routines: string[] } {
40 const result = extractFromSource(file, code);
41 const byId = new Map(result.nodes.map((n) => [n.id, n]));
42 return {
43 calls: result.unresolvedReferences
44 .filter((r) => r.referenceKind === 'calls')
45 .map((r) => `${byId.get(r.fromNodeId)?.name}->${r.referenceName}`)
46 .sort(),
47 routines: result.nodes
48 .filter((n) => (n.kind === 'method' || n.kind === 'function') && n.startLine !== n.endLine)
49 .sort((a, b) => a.startLine - b.startLine)
50 .map((n) => `${n.name}:${n.startLine}-${n.endLine}`),
51 };
52}
53
54// mORMot2's shape: on x86 a `case` whose `else` the shared code ends, elsewhere a `begin` that it ends, with
55// conditionals of its own in that branch.

Calls 3

extractFromSourceFunction · 0.90
mapMethod · 0.80
getMethod · 0.65

Tested by

no test coverage detected