pub struct CodeGraph {
pub graph: StableGraph<GirNode, GirEdge>,
/* private fields */
}Expand description
The central code knowledge graph.
Wraps a petgraph StableGraph with indexes for fast lookups by ID, name, and file.
Fields§
§graph: StableGraph<GirNode, GirEdge>Implementations§
Source§impl CodeGraph
impl CodeGraph
pub fn new() -> Self
pub fn add_node(&mut self, node: GirNode) -> NodeIndex
pub fn add_edge( &mut self, source: SymbolId, target: SymbolId, edge: GirEdge, ) -> bool
Sourcepub fn merge(&mut self, output: ParseOutput)
pub fn merge(&mut self, output: ParseOutput)
Merge a ParseOutput into the graph.
Sourcepub fn remove_file(&mut self, path: &Path)
pub fn remove_file(&mut self, path: &Path)
Remove all nodes belonging to a file (for incremental re-indexing).
petgraph’s StableGraph::remove_node() also removes all edges
incident to the node, so no dangling edges are left behind.
Sourcepub fn validate(&self) -> Vec<String>
pub fn validate(&self) -> Vec<String>
Validate graph invariants. Returns a list of issues found.
Checks that all indexes point to valid nodes and that no stale entries exist. Useful for debugging and post-load verification.
pub fn node_count(&self) -> usize
pub fn edge_count(&self) -> usize
pub fn get_node(&self, id: SymbolId) -> Option<&GirNode>
pub fn get_node_index(&self, id: SymbolId) -> Option<NodeIndex>
pub fn find_by_name(&self, name: &str) -> Vec<&GirNode>
pub fn find_by_file(&self, path: &Path) -> Vec<&GirNode>
pub fn find_by_kind(&self, kind: NodeKind) -> Vec<&GirNode>
Sourcepub fn outgoing(&self, id: SymbolId, edge_kind: EdgeKind) -> Vec<&GirNode>
pub fn outgoing(&self, id: SymbolId, edge_kind: EdgeKind) -> Vec<&GirNode>
Get all nodes connected by outgoing edges of a specific kind.
Sourcepub fn incoming(&self, id: SymbolId, edge_kind: EdgeKind) -> Vec<&GirNode>
pub fn incoming(&self, id: SymbolId, edge_kind: EdgeKind) -> Vec<&GirNode>
Get all nodes connected by incoming edges of a specific kind.
Sourcepub fn children(&self, id: SymbolId) -> Vec<&GirNode>
pub fn children(&self, id: SymbolId) -> Vec<&GirNode>
Get children (contained symbols) of a node.
Sourcepub fn is_phantom(&self, id: SymbolId) -> bool
pub fn is_phantom(&self, id: SymbolId) -> bool
Check if a node is a “phantom” call target — i.e. created by the parser to represent a call expression, not an actual symbol definition. Phantom nodes have no parent (no incoming Contains edge) and are not top-level File/Folder/Module nodes.
Sourcepub fn is_interface_impl(&self, id: SymbolId) -> bool
pub fn is_interface_impl(&self, id: SymbolId) -> bool
Check if a callable node is an interface/trait implementation method. Works across all languages: checks whether the method’s parent type has any Implements or Inherits edges, meaning its methods may be called via dynamic dispatch and shouldn’t be flagged as dead.
Sourcepub fn is_method_on_used_type(&self, id: SymbolId) -> bool
pub fn is_method_on_used_type(&self, id: SymbolId) -> bool
Structural check: is this a method on a type that is actively used?
Methods called via self.method() / this.method() are filtered at
parse time to avoid noise, so they have no incoming Calls edges.
Instead of hardcoding self/this dispatch, we use a structural signal:
if the parent type (struct/class/enum) has incoming edges (it’s
constructed or referenced), its private methods are likely alive
via self-dispatch.
Sourcepub fn is_decorated(&self, id: SymbolId) -> bool
pub fn is_decorated(&self, id: SymbolId) -> bool
Structural check: does this symbol (or a parent module) have any decorator / attribute annotations?
This is a language-agnostic heuristic for framework-registered symbols
(tests, route handlers, event listeners, DI-managed beans, etc.).
Instead of hardcoding per-language name prefixes like test_, we rely
on the graph structure: if the symbol (or an ancestor module) carries
an AnnotatedWith edge to a Decorator node, some framework knows
about it and it should not be considered dead code.
Sourcepub fn remove_phantom_nodes(&mut self) -> usize
pub fn remove_phantom_nodes(&mut self) -> usize
Remove orphaned phantom nodes — phantoms with no incoming edges at all. Keeps phantom nodes that are call targets (have incoming Calls edges) since they represent useful callee information in context views.
Sourcepub fn indexed_files(&self) -> Vec<&PathBuf>
pub fn indexed_files(&self) -> Vec<&PathBuf>
All indexed file paths.
Sourcepub fn all_nodes_mut(&mut self) -> impl Iterator<Item = &mut GirNode>
pub fn all_nodes_mut(&mut self) -> impl Iterator<Item = &mut GirNode>
Mutable iterator over all nodes.
Sourcepub fn remove_edges_by_kind(&mut self, kind: EdgeKind) -> usize
pub fn remove_edges_by_kind(&mut self, kind: EdgeKind) -> usize
Remove all edges of a given kind from the entire graph. Used to clear analysis-phase edges before re-running analysis.
Sourcepub fn remove_edges_by_kinds(&mut self, kinds: &[EdgeKind]) -> usize
pub fn remove_edges_by_kinds(&mut self, kinds: &[EdgeKind]) -> usize
Remove all edges of any of the given kinds from the entire graph.