* 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)
| 4021 | * a signal (read that one hop) rather than a dead end. |
| 4022 | */ |
| 4023 | private formatTrail(cg: CodeGraph, node: Node): string { |
| 4024 | const TRAIL_CAP = 12; |
| 4025 | const fmt = (e: { node: Node; edge: Edge }) => { |
| 4026 | const base = `${e.node.name} (${e.node.filePath}:${e.node.startLine})`; |
| 4027 | const synth = this.synthEdgeNote(e.edge); |
| 4028 | return synth ? `${base} [${synth.compact}]` : base; |
| 4029 | }; |
| 4030 | const collect = (edges: Array<{ node: Node; edge: Edge }>): Array<{ node: Node; edge: Edge }> => { |
| 4031 | const seen = new Set<string>([node.id]); |
| 4032 | const out: Array<{ node: Node; edge: Edge }> = []; |
| 4033 | for (const e of edges) { |
| 4034 | if (seen.has(e.node.id)) continue; |
| 4035 | seen.add(e.node.id); |
| 4036 | out.push(e); |
| 4037 | } |
| 4038 | return out; |
| 4039 | }; |
| 4040 | const callees = collect(cg.getCallees(node.id)); |
| 4041 | const callers = collect(cg.getCallers(node.id)); |
| 4042 | if (callees.length === 0 && callers.length === 0) return ''; |
| 4043 | const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**']; |
| 4044 | if (callees.length > 0) { |
| 4045 | lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`); |
| 4046 | } |
| 4047 | if (callers.length > 0) { |
| 4048 | lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`); |
| 4049 | } |
| 4050 | return lines.join('\n'); |
| 4051 | } |
| 4052 | |
| 4053 | /** |
| 4054 | * Handle codegraph_status |
no test coverage detected