CodeGraph/docs
Section 4.8

Call Path Reachability

Finding whether a directed call chain exists between two specific symbols using iterative DFS with parent backtracking.

Source: server/src/analytics/paths/CallPathAnalyzer.ts

DFS Path-Finding with Early Exit

CallPathAnalyzer finds a call chain connecting sourceNodeId to targetNodeIdfollowing strictly "calls" edges between symbol nodes:

server/src/analytics/paths/CallPathAnalyzer.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
export class CallPathAnalyzer { analyze(sourceNodeId: string, targetNodeId: string): CallPathResult { if (sourceNodeId === targetNodeId) { return { sourceNodeId, targetNodeId, path: [sourceNodeId] }; } const visited = new Set<string>([sourceNodeId]); const stack = [sourceNodeId]; const parent = new Map<string, string>(); while (stack.length > 0) { const current = stack.pop()!; for (const edgeId of this.graph.outgoingEdges.get(current) || []) { const edge = this.graph.edges.get(edgeId); if (!edge || edge.relationshipKind !== "calls") continue; const targetNode = this.graph.nodes.get(edge.targetId); if (!targetNode || targetNode.kind !== "symbol") continue; if (!visited.has(edge.targetId)) { visited.add(edge.targetId); parent.set(edge.targetId, current); // Early exit when target is found! if (edge.targetId === targetNodeId) { return { sourceNodeId, targetNodeId, path: this.buildPath(sourceNodeId, targetNodeId, parent), }; } stack.push(edge.targetId); } } } return { sourceNodeId, targetNodeId, path: null }; } }