Index one module and return the qualified names a function's call lines reach, by line.
(source: string, fn: string)
| 26 | |
| 27 | /** Index one module and return the qualified names a function's call lines reach, by line. */ |
| 28 | async function calls(source: string, fn: string): Promise<Array<[number, string]>> { |
| 29 | root = fs.mkdtempSync(path.join(os.tmpdir(), 'cg-py-subscript-')); |
| 30 | fs.writeFileSync(path.join(root, 'a.py'), source); |
| 31 | const graph = (cg = await CodeGraph.init(root, { index: true })); |
| 32 | const node = graph.getNodesByName(fn).find((n) => n.kind === 'function' || n.kind === 'method')!; |
| 33 | return graph |
| 34 | .getOutgoingEdges(node.id) |
| 35 | .filter((e) => e.kind === 'calls') |
| 36 | .map((e): [number, string] => [e.line ?? 0, graph.getNode(e.target)!.qualifiedName]) |
| 37 | .sort((a, b) => a[0] - b[0]); |
| 38 | } |
| 39 | |
| 40 | const classes = [ |
| 41 | 'class Log:', |
no test coverage detected