pub struct GraphBuilder { /* private fields */ }Expand description
Builds code graphs from source directories.
The GraphBuilder walks a source directory, parses files using tree-sitter,
extracts code entities via SCM queries, and constructs a code graph with
nodes and edges representing code structure and dependencies.
§Example
use codeprysm_core::builder::{GraphBuilder, BuilderConfig};
use std::path::Path;
let config = BuilderConfig::default();
let builder = GraphBuilder::with_config(Path::new("queries"), config)?;
let graph = builder.build_from_directory(Path::new("src"))?;
println!("Built graph with {} nodes", graph.node_count());Implementations§
Source§impl GraphBuilder
impl GraphBuilder
Sourcepub fn new_with_embedded_queries() -> Self
pub fn new_with_embedded_queries() -> Self
Create a new graph builder with default configuration using embedded queries.
This is the preferred constructor for production use as it doesn’t require external query files.
Sourcepub fn with_embedded_queries(config: BuilderConfig) -> Self
pub fn with_embedded_queries(config: BuilderConfig) -> Self
Create a new graph builder with custom configuration using embedded queries.
This is the preferred constructor for production use as it doesn’t require external query files.
Sourcepub fn new(queries_dir: &Path) -> Result<Self, BuilderError>
pub fn new(queries_dir: &Path) -> Result<Self, BuilderError>
Sourcepub fn with_config(
queries_dir: &Path,
config: BuilderConfig,
) -> Result<Self, BuilderError>
pub fn with_config( queries_dir: &Path, config: BuilderConfig, ) -> Result<Self, BuilderError>
Sourcepub fn build_from_directory(
&mut self,
directory: &Path,
) -> Result<PetCodeGraph, BuilderError>
pub fn build_from_directory( &mut self, directory: &Path, ) -> Result<PetCodeGraph, BuilderError>
Build a code graph from a directory.
Walks the directory, processes all supported source files, and constructs a code graph with nodes and edges.
§Arguments
directory- Root directory to process
§Returns
A PetCodeGraph containing all discovered code entities and relationships.
Uses petgraph::StableGraph internally for efficient traversal and algorithms.
Sourcepub fn build_from_workspace(
&mut self,
workspace_path: &Path,
) -> Result<(PetCodeGraph, Vec<DiscoveredRoot>), BuilderError>
pub fn build_from_workspace( &mut self, workspace_path: &Path, ) -> Result<(PetCodeGraph, Vec<DiscoveredRoot>), BuilderError>
Build a code graph from a workspace root that may contain multiple repositories.
This method discovers all code roots (git repositories and code directories) under the given workspace path and builds a unified graph.
- If the root is a single repository or contains only one code root, returns a graph with that repository as the root (backward compatible).
- Otherwise, creates a workspace container with multiple repository children.
§Arguments
workspace_path- Root directory to analyze (may contain multiple repos)
§Returns
A tuple containing:
- The unified
PetCodeGraphwith all discovered code entities - A list of
DiscoveredRootdescribing each discovered root
§Example
use codeprysm_core::builder::GraphBuilder;
use std::path::Path;
let builder = GraphBuilder::new(Path::new("queries"))?;
let (graph, roots) = builder.build_from_workspace(Path::new("/workspace"))?;
println!("Found {} code roots", roots.len());
println!("Graph has {} nodes", graph.node_count());Sourcepub fn parse_file(
&mut self,
file_path: &Path,
rel_path: &str,
) -> Result<PetCodeGraph, BuilderError>
pub fn parse_file( &mut self, file_path: &Path, rel_path: &str, ) -> Result<PetCodeGraph, BuilderError>
Parse a single file and return a graph with its entities.
This method is useful for incremental updates where only specific files need to be reparsed. Returns a graph containing:
- FILE node with hash
- All definition nodes (Container, Callable, Data)
- CONTAINS edges (parent → child)
- DEFINES edges (Container/Callable → Data)
Note: USES edges are NOT included because they require cross-file
reference resolution. Call resolve_references_for_file() after
merging into the main graph if needed.
§Arguments
file_path- Absolute path to the filerel_path- Relative path (used for node IDs)
§Returns
A PetCodeGraph containing entities from this file only.
Auto Trait Implementations§
impl Freeze for GraphBuilder
impl RefUnwindSafe for GraphBuilder
impl Send for GraphBuilder
impl Sync for GraphBuilder
impl Unpin for GraphBuilder
impl UnwindSafe for GraphBuilder
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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