Skip to main content

CodeGraph

Struct CodeGraph 

Source
pub struct CodeGraph {
    pub nodes: HashMap<SymbolId, SymbolNode>,
    pub edges_out: HashMap<SymbolId, Vec<Edge>>,
    pub edges_in: HashMap<SymbolId, Vec<Edge>>,
    pub file_symbols: HashMap<PathBuf, Vec<SymbolId>>,
    pub file_mtimes: HashMap<PathBuf, u64>,
}
Expand description

Cross-file code knowledge graph indexing symbol relationships.

Fields§

§nodes: HashMap<SymbolId, SymbolNode>§edges_out: HashMap<SymbolId, Vec<Edge>>§edges_in: HashMap<SymbolId, Vec<Edge>>§file_symbols: HashMap<PathBuf, Vec<SymbolId>>§file_mtimes: HashMap<PathBuf, u64>

Implementations§

Source§

impl CodeGraph

Source

pub fn new() -> Self

Create an empty graph.

Source

pub fn make_id(file: &PathBuf, name: &str, start_line: usize) -> SymbolId

Deterministic symbol ID from file path, name, and start line.

Source

pub fn add_symbol(&mut self, node: SymbolNode)

Add a symbol node to the graph.

Source

pub fn add_edge(&mut self, from: SymbolId, edge: Edge)

Add a directed edge from from to the target in edge.

Source

pub fn node(&self, id: SymbolId) -> Option<&SymbolNode>

Look up a node by ID.

Source

pub fn symbols_in_file(&self, file: &PathBuf) -> Option<&Vec<SymbolId>>

Get all symbol IDs in a file.

Source

pub fn callees(&self, id: SymbolId) -> Option<&Vec<Edge>>

Get outgoing edges (callees / targets) from a symbol.

Source

pub fn callers(&self, id: SymbolId) -> Option<&Vec<Edge>>

Get incoming edges (callers / sources) to a symbol.

Source

pub fn remove_file(&mut self, file: &PathBuf)

Remove all symbols belonging to a file and clean up associated edges.

Source

pub fn find_by_name(&self, name: &str) -> Vec<&SymbolNode>

Find symbols by name (exact match).

Source

pub fn node_count(&self) -> usize

Total number of symbol nodes.

Source

pub fn file_count(&self) -> usize

Total number of indexed files.

Source

pub fn is_ready(&self) -> bool

Whether the graph has any data.

Source

pub fn trace_callers( &self, id: SymbolId, max_depth: usize, ) -> Vec<(SymbolId, usize)>

BFS reverse traversal — find all transitive callers up to max_depth.

Source

pub fn trace_callees( &self, id: SymbolId, max_depth: usize, ) -> Vec<(SymbolId, usize)>

BFS forward traversal — find all transitive callees up to max_depth.

Source

pub fn shortest_path( &self, from: SymbolId, to: SymbolId, ) -> Option<Vec<SymbolId>>

BFS shortest path from from to to, max 10 hops. Returns the ordered path [from, ..., to] or None.

Source

pub fn file_dependents(&self, file: &Path, max_depth: usize) -> Vec<PathBuf>

Find all files that depend on (call into) symbols in the given file.

Source

pub fn file_dependency_summary(&self, filename: &str) -> Option<String>

Generate a dependency summary for a file: what it uses, what uses it.

Source

pub fn call_chain_summary(&self, fn_name: &str) -> Option<String>

Generate a call chain summary for a function. Skips struct/enum/trait nodes (they don’t have call edges). If multiple functions match, picks the one with the most callees.

Trait Implementations§

Source§

impl Clone for CodeGraph

Source§

fn clone(&self) -> CodeGraph

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CodeGraph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CodeGraph

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for CodeGraph

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for CodeGraph

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,