pub struct DependencyIndex { /* private fields */ }Expand description
Manages dependency storage and graph operations
Implementations§
Source§impl DependencyIndex
impl DependencyIndex
Sourcepub fn new(cache: CacheManager) -> Self
pub fn new(cache: CacheManager) -> Self
Create a new dependency index for the given cache
Sourcepub fn from_db_path(db_path: impl Into<PathBuf>) -> Self
pub fn from_db_path(db_path: impl Into<PathBuf>) -> Self
Create a dependency index pointing directly at a database file.
Used by Pulse to run analysis against snapshot databases.
Sourcepub fn get_cache(&self) -> &CacheManager
pub fn get_cache(&self) -> &CacheManager
Get a reference to the cache manager.
Panics if this index was created via from_db_path().
Sourcepub fn insert_dependency(
&self,
file_id: i64,
imported_path: String,
resolved_file_id: Option<i64>,
import_type: ImportType,
line_number: usize,
imported_symbols: Option<Vec<String>>,
) -> Result<()>
pub fn insert_dependency( &self, file_id: i64, imported_path: String, resolved_file_id: Option<i64>, import_type: ImportType, line_number: usize, imported_symbols: Option<Vec<String>>, ) -> Result<()>
Insert a dependency into the database
§Arguments
file_id- Source file IDimported_path- Import path as written in sourceresolved_file_id- Resolved target file ID (None if external/stdlib)import_type- Type of import (internal/external/stdlib)line_number- Line where import appearsimported_symbols- Optional list of imported symbols
Sourcepub fn insert_export(
&self,
file_id: i64,
exported_symbol: Option<String>,
source_path: String,
resolved_source_id: Option<i64>,
line_number: usize,
) -> Result<()>
pub fn insert_export( &self, file_id: i64, exported_symbol: Option<String>, source_path: String, resolved_source_id: Option<i64>, line_number: usize, ) -> Result<()>
Insert an export into the database
§Arguments
file_id- Source file ID containing the export statementexported_symbol- Symbol name being exported (None for wildcard exports)source_path- Path where the symbol is re-exported fromresolved_source_id- Resolved target file ID (None if unresolved)line_number- Line where export appears
Sourcepub fn batch_insert_dependencies(
&self,
dependencies: &[Dependency],
) -> Result<()>
pub fn batch_insert_dependencies( &self, dependencies: &[Dependency], ) -> Result<()>
Batch insert multiple dependencies in a single transaction
More efficient than individual inserts for bulk operations.
Sourcepub fn get_dependencies(&self, file_id: i64) -> Result<Vec<Dependency>>
pub fn get_dependencies(&self, file_id: i64) -> Result<Vec<Dependency>>
Get all direct dependencies for a file
Returns a list of files/modules that this file imports.
Sourcepub fn get_dependents(&self, file_id: i64) -> Result<Vec<i64>>
pub fn get_dependents(&self, file_id: i64) -> Result<Vec<i64>>
Get all files that depend on this file (reverse lookup)
Returns a list of file IDs that import this file.
Uses resolved_file_id column for instant SQL lookup (sub-10ms).
Sourcepub fn get_dependencies_info(&self, file_id: i64) -> Result<Vec<DependencyInfo>>
pub fn get_dependencies_info(&self, file_id: i64) -> Result<Vec<DependencyInfo>>
Get dependencies as DependencyInfo (for API output)
Converts internal Dependency records to simplified DependencyInfo suitable for JSON output.
Sourcepub fn get_transitive_deps(
&self,
file_id: i64,
max_depth: usize,
) -> Result<HashMap<i64, usize>>
pub fn get_transitive_deps( &self, file_id: i64, max_depth: usize, ) -> Result<HashMap<i64, usize>>
Get transitive dependencies up to a given depth
Traverses the dependency graph using BFS to find all dependencies
reachable within the specified depth.
Uses resolved_file_id column for instant SQL lookup (sub-100ms).
§Arguments
file_id- Starting file IDmax_depth- Maximum traversal depth (0 = only direct deps)
§Returns
HashMap mapping file_id to depth (distance from start file)
Sourcepub fn detect_circular_dependencies(&self) -> Result<Vec<Vec<i64>>>
pub fn detect_circular_dependencies(&self) -> Result<Vec<Vec<i64>>>
Detect circular dependencies in the entire codebase
Uses depth-first search to find cycles in the dependency graph.
Uses resolved_file_id column for instant SQL lookup (sub-100ms).
Returns a list of cycle paths, where each cycle is represented as a vector of file IDs forming the cycle.
Sourcepub fn get_file_paths(&self, file_ids: &[i64]) -> Result<HashMap<i64, String>>
pub fn get_file_paths(&self, file_ids: &[i64]) -> Result<HashMap<i64, String>>
Get file paths for a list of file IDs
Useful for converting file ID results to human-readable paths.
Sourcepub fn find_hotspots(
&self,
limit: Option<usize>,
min_dependents: usize,
) -> Result<Vec<(i64, usize)>>
pub fn find_hotspots( &self, limit: Option<usize>, min_dependents: usize, ) -> Result<Vec<(i64, usize)>>
Find hotspots (most imported files)
Returns a list of (file_id, count) tuples sorted by import count descending.
Uses resolved_file_id column for instant SQL aggregation (sub-100ms).
§Arguments
limit- Maximum number of hotspots to return (None = all)min_dependents- Minimum number of imports required to be a hotspot (default: 2)
Sourcepub fn find_unused_files(&self) -> Result<Vec<i64>>
pub fn find_unused_files(&self) -> Result<Vec<i64>>
Find unused files (files with no incoming dependencies)
Files that are never imported are potential candidates for deletion.
Uses resolved_file_id column for instant SQL lookup (sub-10ms).
Barrel Export Resolution: This function now follows barrel export chains to detect files that are indirectly imported via re-exports. For example:
WithLabel.vueexported bypackages/ui/components/index.ts- App imports
@packages/ui/components(resolves to index.ts) - This function follows the export chain and marks
WithLabel.vueas used
Sourcepub fn resolve_through_barrel_exports(
&self,
barrel_file_id: i64,
) -> Result<Vec<i64>>
pub fn resolve_through_barrel_exports( &self, barrel_file_id: i64, ) -> Result<Vec<i64>>
Resolve barrel export chains to find all files transitively exported from a given file
Given a barrel file (e.g., index.ts that re-exports from other files), this function
follows the export chain to find all source files that are transitively exported.
§Example
If packages/ui/components/index.ts contains:
export { default as WithLabel } from './WithLabel.vue';
export { default as Button } from './Button.vue';Then calling this with the file_id of index.ts will return the file IDs of
WithLabel.vue and Button.vue.
§Arguments
barrel_file_id- File ID of the barrel file to start from
§Returns
Vec of file IDs that are transitively exported (includes the barrel file itself)
Sourcepub fn find_islands(&self) -> Result<Vec<Vec<i64>>>
pub fn find_islands(&self) -> Result<Vec<Vec<i64>>>
Find disconnected components (islands) in the dependency graph
An “island” is a connected component - a group of files that depend on each other (directly or transitively) but have no dependencies to files outside the group.
This is useful for identifying:
- Independent subsystems that could be extracted as separate modules
- Unreachable code clusters that might be dead code
- Microservice boundaries in a monolith
Returns a list of islands, where each island is a vector of file IDs. Islands are sorted by size (largest first).
Sourcepub fn clear_dependencies(&self, file_id: i64) -> Result<()>
pub fn clear_dependencies(&self, file_id: i64) -> Result<()>
Clear all dependencies for a file (used during incremental reindexing)
Sourcepub fn resolve_imported_path_to_file_id(
&self,
imported_path: &str,
) -> Result<Option<i64>>
pub fn resolve_imported_path_to_file_id( &self, imported_path: &str, ) -> Result<Option<i64>>
Resolve an imported path to a file ID using fuzzy matching
This method converts an import path (e.g., namespace, module path) to various file path variants and tries to find a matching file using fuzzy path matching.
§Arguments
imported_path- The import path as stored in the database (e.g., “Rcm\Http\Controllers\Controller”, “crate::models”, etc.)
§Returns
Some(file_id) if exactly one matching file is found, None otherwise
§Examples
Rcm\\Http\\Controllers\\Controller→ findsservices/php/rcm-backend/app/Http/Controllers/Controller.phpcrate::models→ findssrc/models.rs
Sourcepub fn get_file_id_by_path(&self, path: &str) -> Result<Option<i64>>
pub fn get_file_id_by_path(&self, path: &str) -> Result<Option<i64>>
Get file ID by path with fuzzy matching support
Supports various path formats:
- Exact paths:
services/php/app/Http/Controllers/FooController.php - Relative paths:
./services/php/app/Http/Controllers/FooController.php - Path fragments:
Controllers/FooController.phporFooController.php - Absolute paths:
/home/user/project/services/php/.../FooController.php
Returns None if no matches found. Returns error if multiple matches found (ambiguous path fragment).
Sourcepub fn get_resolution_stats(&self) -> Result<Vec<(String, usize, usize, f64)>>
pub fn get_resolution_stats(&self) -> Result<Vec<(String, usize, usize, f64)>>
Get dependency resolution statistics grouped by language
Returns statistics showing how many internal dependencies are resolved vs unresolved for each language in the project.
§Returns
A vector of tuples: (language, total_deps, resolved_deps, resolution_rate)
Sourcepub fn get_all_internal_dependencies(
&self,
) -> Result<Vec<(String, String, Option<String>)>>
pub fn get_all_internal_dependencies( &self, ) -> Result<Vec<(String, String, Option<String>)>>
Get all internal dependencies with their resolution status
Returns detailed information about each internal dependency including source file, imported path, and whether it was successfully resolved.
§Returns
A vector of tuples: (source_file, imported_path, resolved_file_path) where resolved_file_path is None if the dependency couldn’t be resolved.
Auto Trait Implementations§
impl Freeze for DependencyIndex
impl RefUnwindSafe for DependencyIndex
impl Send for DependencyIndex
impl Sync for DependencyIndex
impl Unpin for DependencyIndex
impl UnsafeUnpin for DependencyIndex
impl UnwindSafe for DependencyIndex
Blanket Implementations§
Source§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
Source§type ArchivedMetadata = ()
type ArchivedMetadata = ()
Source§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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 moreSource§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
Source§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Source§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
Source§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
Source§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out indicating that a T is niched.Source§impl<D> OwoColorize for D
impl<D> OwoColorize for D
Source§fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>where
C: Color,
Source§fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>where
C: Color,
Source§fn black(&self) -> FgColorDisplay<'_, Black, Self>
fn black(&self) -> FgColorDisplay<'_, Black, Self>
Source§fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
fn on_black(&self) -> BgColorDisplay<'_, Black, Self>
Source§fn red(&self) -> FgColorDisplay<'_, Red, Self>
fn red(&self) -> FgColorDisplay<'_, Red, Self>
Source§fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
fn on_red(&self) -> BgColorDisplay<'_, Red, Self>
Source§fn green(&self) -> FgColorDisplay<'_, Green, Self>
fn green(&self) -> FgColorDisplay<'_, Green, Self>
Source§fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
fn on_green(&self) -> BgColorDisplay<'_, Green, Self>
Source§fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
fn yellow(&self) -> FgColorDisplay<'_, Yellow, Self>
Source§fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
fn on_yellow(&self) -> BgColorDisplay<'_, Yellow, Self>
Source§fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
fn blue(&self) -> FgColorDisplay<'_, Blue, Self>
Source§fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
fn on_blue(&self) -> BgColorDisplay<'_, Blue, Self>
Source§fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
fn magenta(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_magenta(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
fn purple(&self) -> FgColorDisplay<'_, Magenta, Self>
Source§fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
fn on_purple(&self) -> BgColorDisplay<'_, Magenta, Self>
Source§fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
fn cyan(&self) -> FgColorDisplay<'_, Cyan, Self>
Source§fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
fn on_cyan(&self) -> BgColorDisplay<'_, Cyan, Self>
Source§fn white(&self) -> FgColorDisplay<'_, White, Self>
fn white(&self) -> FgColorDisplay<'_, White, Self>
Source§fn on_white(&self) -> BgColorDisplay<'_, White, Self>
fn on_white(&self) -> BgColorDisplay<'_, White, Self>
Source§fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
fn default_color(&self) -> FgColorDisplay<'_, Default, Self>
Source§fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
fn on_default_color(&self) -> BgColorDisplay<'_, Default, Self>
Source§fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
fn bright_black(&self) -> FgColorDisplay<'_, BrightBlack, Self>
Source§fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
fn on_bright_black(&self) -> BgColorDisplay<'_, BrightBlack, Self>
Source§fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
fn bright_red(&self) -> FgColorDisplay<'_, BrightRed, Self>
Source§fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
fn on_bright_red(&self) -> BgColorDisplay<'_, BrightRed, Self>
Source§fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
fn bright_green(&self) -> FgColorDisplay<'_, BrightGreen, Self>
Source§fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
fn on_bright_green(&self) -> BgColorDisplay<'_, BrightGreen, Self>
Source§fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
fn bright_yellow(&self) -> FgColorDisplay<'_, BrightYellow, Self>
Source§fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
fn on_bright_yellow(&self) -> BgColorDisplay<'_, BrightYellow, Self>
Source§fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
fn bright_blue(&self) -> FgColorDisplay<'_, BrightBlue, Self>
Source§fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
fn on_bright_blue(&self) -> BgColorDisplay<'_, BrightBlue, Self>
Source§fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_magenta(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_magenta(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
fn bright_purple(&self) -> FgColorDisplay<'_, BrightMagenta, Self>
Source§fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
fn on_bright_purple(&self) -> BgColorDisplay<'_, BrightMagenta, Self>
Source§fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
fn bright_cyan(&self) -> FgColorDisplay<'_, BrightCyan, Self>
Source§fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
fn on_bright_cyan(&self) -> BgColorDisplay<'_, BrightCyan, Self>
Source§fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
fn bright_white(&self) -> FgColorDisplay<'_, BrightWhite, Self>
Source§fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
fn on_bright_white(&self) -> BgColorDisplay<'_, BrightWhite, Self>
Source§fn bold(&self) -> BoldDisplay<'_, Self>
fn bold(&self) -> BoldDisplay<'_, Self>
Source§fn dimmed(&self) -> DimDisplay<'_, Self>
fn dimmed(&self) -> DimDisplay<'_, Self>
Source§fn italic(&self) -> ItalicDisplay<'_, Self>
fn italic(&self) -> ItalicDisplay<'_, Self>
Source§fn underline(&self) -> UnderlineDisplay<'_, Self>
fn underline(&self) -> UnderlineDisplay<'_, Self>
Source§fn blink(&self) -> BlinkDisplay<'_, Self>
fn blink(&self) -> BlinkDisplay<'_, Self>
Source§fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
fn blink_fast(&self) -> BlinkFastDisplay<'_, Self>
Source§fn reversed(&self) -> ReversedDisplay<'_, Self>
fn reversed(&self) -> ReversedDisplay<'_, Self>
Source§fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
fn strikethrough(&self) -> StrikeThroughDisplay<'_, Self>
Source§fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::fg or
a color-specific method, such as OwoColorize::green, Read moreSource§fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>where
Color: DynColor,
OwoColorize::bg or
a color-specific method, such as OwoColorize::on_yellow, Read more