* 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)
| 6349 | * a signal (read that one hop) rather than a dead end. |
| 6350 | */ |
| 6351 | private formatTrail(cg: CodeGraph, node: Node): string { |
| 6352 | const TRAIL_CAP = 12; |
| 6353 | const fmt = (e: { node: Node; edge: Edge }) => { |
| 6354 | const base = `${e.node.name} (${e.node.filePath}:${e.node.startLine})`; |
| 6355 | const synth = this.synthEdgeNote(e.edge); |
| 6356 | return synth ? `${base} [${synth.compact}]` : base; |
| 6357 | }; |
| 6358 | const collect = (edges: Array<{ node: Node; edge: Edge }>): Array<{ node: Node; edge: Edge }> => { |
| 6359 | const seen = new Set<string>([node.id]); |
| 6360 | const out: Array<{ node: Node; edge: Edge }> = []; |
| 6361 | for (const e of edges) { |
| 6362 | if (seen.has(e.node.id)) continue; |
| 6363 | seen.add(e.node.id); |
| 6364 | out.push(e); |
| 6365 | } |
| 6366 | return out; |
| 6367 | }; |
| 6368 | const callees = collect(cg.getCallees(node.id)); |
| 6369 | const callers = collect(cg.getCallers(node.id)); |
| 6370 | if (callees.length === 0 && callers.length === 0) return ''; |
| 6371 | const lines: string[] = ['', '**Trail — codegraph_node any of these to follow it (no Read needed)**']; |
| 6372 | if (callees.length > 0) { |
| 6373 | lines.push(`**Calls →** ${callees.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callees.length > TRAIL_CAP ? `, +${callees.length - TRAIL_CAP} more` : ''}`); |
| 6374 | } |
| 6375 | if (callers.length > 0) { |
| 6376 | lines.push(`**Called by ←** ${callers.slice(0, TRAIL_CAP).map(fmt).join(', ')}${callers.length > TRAIL_CAP ? `, +${callers.length - TRAIL_CAP} more` : ''}`); |
| 6377 | } |
| 6378 | return lines.join('\n'); |
| 6379 | } |
| 6380 | |
| 6381 | /** |
| 6382 | * Handle codegraph_status |
no test coverage detected