* 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)
| 3913 | * a signal (read that one hop) rather than a dead end. |
| 3914 | */ |
| 3915 | private formatTrail(cg: CodeGraph, node: Node): string { |
| 3916 | const TRAIL_CAP = 12; |
| 3917 | const fmt = (e: { node: Node; edge: Edge }) => { |
| 3918 | const base = `${e.node.name} (${e.node.filePath}:${e.node.startLine})`; |
| 3919 | const synth = this.synthEdgeNote(e.edge); |
| 3920 | return synth ? `${base} [${synth.compact}]` : base; |
| 3921 | }; |
| 3922 | const collect = (edges: Array<{ node: Node; edge: Edge }>): Array<{ node: Node; edge: Edge }> => { |
| 3923 | const seen = new Set<string>([node.id]); |
| 3924 | const out: Array<{ node: Node; edge: Edge }> = []; |
| 3925 | for (const e of edges) { |
| 3926 | if (seen.has(e.node.id)) continue; |
| 3927 | seen.add(e.node.id); |
| 3928 | out.push(e); |
| 3929 | } |
| 3930 | return out; |
| 3931 | }; |
| 3932 | const callees = collect(cg.getCallees(node.id)); |
| 3933 | const callers = collect(cg.getCallers(node.id)); |
| 3934 | if (callees.length === 0 && callers.length === 0) return ''; |
| 3935 | const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**']; |
| 3936 | if (callees.length > 0) { |
| 3937 | lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`); |
| 3938 | } |
| 3939 | if (callers.length > 0) { |
| 3940 | lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`); |
| 3941 | } |
| 3942 | return lines.join('\n'); |
| 3943 | } |
| 3944 | |
| 3945 | /** |
| 3946 | * Handle codegraph_status |
no test coverage detected