* Build the "trail" for a symbol: its direct callees (what it calls) and * callers (what calls it), each with file:line — so codegraph_node doubles as * the structural Grep→Read→expand primitive: a spot PLUS where to go next. * Capped to stay cheap. Walk the graph by calling codegraph_node
(cg: CodeGraph, node: Node)
| 8521 | * a signal (read that one hop) rather than a dead end. |
| 8522 | */ |
| 8523 | private formatTrail(cg: CodeGraph, node: Node): string { |
| 8524 | const TRAIL_CAP = 12; |
| 8525 | /** Call-site lines shown per caller, so one busy caller can't crowd the trail. */ |
| 8526 | const TRAIL_CALL_SITES = 3; |
| 8527 | const fmt = (row: CallSiteRow, where: string) => { |
| 8528 | const base = `${row.node.name} (${where})`; |
| 8529 | const synth = this.synthEdgeNote(row.edges[0]!); |
| 8530 | return synth ? `${base} [${synth}]` : base; |
| 8531 | }; |
| 8532 | // A callee reads at its declaration, where following it leads. A caller |
| 8533 | // reads at the lines its calls sit on, every one a line to edit when this |
| 8534 | // symbol changes (#2909), and a symbol that calls itself is among its own |
| 8535 | // callers, once. |
| 8536 | const callees = cg.getCallSites(node.id, 'callees').filter((row) => !row.recursive); |
| 8537 | const callers = cg.getCallSites(node.id, 'callers'); |
| 8538 | if (callees.length === 0 && callers.length === 0) return ''; |
| 8539 | const callee = (row: CallSiteRow) => fmt(row, `${row.node.filePath}:${row.node.startLine}`); |
| 8540 | const caller = (row: CallSiteRow) => { |
| 8541 | const sites = callSiteLines(row.edges); |
| 8542 | const at = sites.length > 0 ? formatCallSiteLines(sites, TRAIL_CALL_SITES) : String(row.node.startLine); |
| 8543 | return fmt(row, `${row.node.filePath}:${at}${row.recursive ? ', calls itself' : ''}`); |
| 8544 | }; |
| 8545 | const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**']; |
| 8546 | if (callees.length > 0) { |
| 8547 | lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(callee).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`); |
| 8548 | } |
| 8549 | if (callers.length > 0) { |
| 8550 | lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(caller).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`); |
| 8551 | } |
| 8552 | return lines.join('\n'); |
| 8553 | } |
| 8554 | |
| 8555 | /** |
| 8556 | * Handle codegraph_status |
no test coverage detected