* Get full context for a node * * Returns the focal node along with its ancestors, children, * and both incoming and outgoing references. * * @param nodeId - ID of the focal node * @returns Context object with all related information
(nodeId: string)
| 31 | * @returns Context object with all related information |
| 32 | */ |
| 33 | getContext(nodeId: string): Context { |
| 34 | const focal = this.queries.getNodeById(nodeId); |
| 35 | |
| 36 | if (!focal) { |
| 37 | throw new Error(`Node not found: ${nodeId}`); |
| 38 | } |
| 39 | |
| 40 | // Get ancestors (containment hierarchy) |
| 41 | const ancestors = this.traverser.getAncestors(nodeId); |
| 42 | |
| 43 | // Get children |
| 44 | const children = this.traverser.getChildren(nodeId); |
| 45 | |
| 46 | // Get incoming references (things that reference this node) |
| 47 | const incomingEdges = this.queries.getIncomingEdges(nodeId); |
| 48 | const incomingRefs: Array<{ node: Node; edge: Edge }> = []; |
| 49 | for (const edge of incomingEdges) { |
| 50 | // Skip containment edges (already in ancestors) |
| 51 | if (edge.kind === 'contains') { |
| 52 | continue; |
| 53 | } |
| 54 | const node = this.queries.getNodeById(edge.source); |
| 55 | if (node) { |
| 56 | incomingRefs.push({ node, edge }); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | // Get outgoing references (things this node references) |
| 61 | const outgoingEdges = this.queries.getOutgoingEdges(nodeId); |
| 62 | const outgoingRefs: Array<{ node: Node; edge: Edge }> = []; |
| 63 | for (const edge of outgoingEdges) { |
| 64 | // Skip containment edges (already in children) |
| 65 | if (edge.kind === 'contains') { |
| 66 | continue; |
| 67 | } |
| 68 | const node = this.queries.getNodeById(edge.target); |
| 69 | if (node) { |
| 70 | outgoingRefs.push({ node, edge }); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | // Get type information (type_of, returns edges) |
| 75 | const types: Node[] = []; |
| 76 | const typeEdgeKinds: EdgeKind[] = ['type_of', 'returns']; |
| 77 | for (const kind of typeEdgeKinds) { |
| 78 | const typeEdges = this.queries.getOutgoingEdges(nodeId, [kind]); |
| 79 | for (const edge of typeEdges) { |
| 80 | const typeNode = this.queries.getNodeById(edge.target); |
| 81 | if (typeNode && !types.some((t) => t.id === typeNode.id)) { |
| 82 | types.push(typeNode); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | // Get relevant imports |
| 88 | const imports: Node[] = []; |
| 89 | const fileNode = ancestors.find((a) => a.kind === 'file'); |
| 90 | if (fileNode) { |
nothing calls this directly
no test coverage detected