* 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)
| 8694 | * a signal (read that one hop) rather than a dead end. |
| 8695 | */ |
| 8696 | private formatTrail(cg: CodeGraph, node: Node): string { |
| 8697 | const TRAIL_CAP = 12; |
| 8698 | /** Call-site lines shown per caller, so one busy caller can't crowd the trail. */ |
| 8699 | const TRAIL_CALL_SITES = 3; |
| 8700 | const fmt = (row: CallSiteRow, where: string) => { |
| 8701 | const base = `${row.node.name} (${where})`; |
| 8702 | const synth = this.synthEdgeNote(row.edges[0]!); |
| 8703 | return synth ? `${base} [${synth}]` : base; |
| 8704 | }; |
| 8705 | // A callee reads at its declaration, where following it leads. A caller |
| 8706 | // reads at the lines its calls sit on, every one a line to edit when this |
| 8707 | // symbol changes (#2909), and a symbol that calls itself is among its own |
| 8708 | // callers, once. |
| 8709 | const callees = cg.getCallSites(node.id, 'callees').filter((row) => !row.recursive); |
| 8710 | const callers = cg.getCallSites(node.id, 'callers'); |
| 8711 | if (callees.length === 0 && callers.length === 0) return ''; |
| 8712 | const callee = (row: CallSiteRow) => fmt(row, `${row.node.filePath}:${row.node.startLine}`); |
| 8713 | const caller = (row: CallSiteRow) => { |
| 8714 | const sites = callSiteLines(row.edges); |
| 8715 | const at = sites.length > 0 ? formatCallSiteLines(sites, TRAIL_CALL_SITES) : String(row.node.startLine); |
| 8716 | return fmt(row, `${row.node.filePath}:${at}${row.recursive ? ', calls itself' : ''}`); |
| 8717 | }; |
| 8718 | const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**']; |
| 8719 | if (callees.length > 0) { |
| 8720 | lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(callee).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`); |
| 8721 | } |
| 8722 | if (callers.length > 0) { |
| 8723 | lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(caller).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`); |
| 8724 | } |
| 8725 | return lines.join('\n'); |
| 8726 | } |
| 8727 | |
| 8728 | /** |
| 8729 | * Handle codegraph_status |
no test coverage detected