MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / getImpactRecursive

Method getImpactRecursive

src/graph/traversal.ts:635–725  ·  view source on GitHub ↗
(
    nodeId: string,
    maxDepth: number,
    currentDepth: number,
    nodes: Map<string, Node>,
    edges: Edge[],
    visited: Map<string, number>,
    expanded: Set<string>,
    budget: { maxNodes: number; maxEdges: number; truncated: boolean }
  )

Source from the content-addressed store, hash-verified

633 }
634
635 private getImpactRecursive(
636 nodeId: string,
637 maxDepth: number,
638 currentDepth: number,
639 nodes: Map<string, Node>,
640 edges: Edge[],
641 visited: Map<string, number>,
642 expanded: Set<string>,
643 budget: { maxNodes: number; maxEdges: number; truncated: boolean }
644 ): void {
645 // Mark visited before the depth check so a node collected at the depth
646 // boundary still lands in `visited`. Otherwise it could sit in `nodes` but
647 // not `visited`, and the two loops below — which used different sets to
648 // gate re-processing — would disagree about it (#1089).
649 if (!this.enterAtDepth(visited, nodeId, currentDepth)) return;
650 if (currentDepth >= maxDepth) {
651 return;
652 }
653 // A node re-expanded from a nearer depth re-reads the same edges; record
654 // them on its first expansion only.
655 const firstExpansion = !expanded.has(nodeId);
656 expanded.add(nodeId);
657
658 // For container nodes (classes, interfaces, structs, etc.), also traverse
659 // into their children so that callers of contained methods appear in impact
660 const focalNode = this.queries.getNodeById(nodeId);
661 if (focalNode) {
662 const containerKinds = new Set(['class', 'interface', 'struct', 'union', 'trait', 'protocol', 'module', 'enum']);
663 if (containerKinds.has(focalNode.kind)) {
664 const remaining = budget.maxEdges - edges.length;
665 // No SQL LIMIT here either: the slice applies the budget (#3248).
666 const fetched = this.queries.getOutgoingEdges(nodeId, ['contains']);
667 if (fetched.length > remaining) budget.truncated = true;
668 const containsEdges = fetched.slice(0, remaining);
669 if (containsEdges.length > 0) {
670 const children = this.queries.getNodesByIds(containsEdges.map((e) => e.target));
671 for (const edge of containsEdges) {
672 const childNode = children.get(edge.target);
673 if (childNode && this.nearerThanBefore(visited, childNode.id, currentDepth)) {
674 if (!nodes.has(childNode.id)) {
675 if (nodes.size >= budget.maxNodes || edges.length >= budget.maxEdges) {
676 budget.truncated = true;
677 continue;
678 }
679 nodes.set(childNode.id, childNode);
680 edges.push(edge);
681 }
682 // Recurse into children at the same depth (they're part of the same symbol)
683 this.getImpactRecursive(childNode.id, maxDepth, currentDepth, nodes, edges, visited, expanded, budget);
684 }
685 }
686 }
687 }
688 }
689
690 // Get all incoming edges (things that depend on this node). Exclude
691 // `contains`: a container "contains" its members but does not *depend* on
692 // them, so following it upward would climb to the parent class and then

Callers 1

getImpactRadiusMethod · 0.95

Calls 12

enterAtDepthMethod · 0.95
nearerThanBeforeMethod · 0.95
hasMethod · 0.80
mapMethod · 0.80
pushMethod · 0.80
getNodeByIdMethod · 0.65
getMethod · 0.65
addMethod · 0.45
getOutgoingEdgesMethod · 0.45
getNodesByIdsMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected