pub struct SemanticIndex {Show 13 fields
pub symbols: Vec<Symbol>,
pub tokens: Vec<Token>,
pub references: Vec<Reference>,
pub scopes: Vec<Scope>,
pub edges: Vec<Edge>,
pub symbol_by_name: HashMap<CompactString, SmallVec<[u32; 4]>>,
pub token_by_name: HashMap<CompactString, Vec<u32>>,
pub incoming_edges: Vec<SmallVec<[u32; 8]>>,
pub outgoing_edges: Vec<SmallVec<[u32; 8]>>,
pub refs_to_symbol: Vec<Vec<u32>>,
pub files: Vec<PathBuf>,
pub strings: StringTable,
pub entry_points: Vec<u32>,
}Expand description
The main semantic index containing all code structure information
This structure is designed for:
- Fast lookup by name (HashMap)
- Fast traversal (adjacency lists with SmallVec)
- Memory efficiency (interned strings, compact types)
- Mmap compatibility (repr(C) data types)
Fields§
§symbols: Vec<Symbol>All symbol definitions
tokens: Vec<Token>All token occurrences
references: Vec<Reference>All symbol references
scopes: Vec<Scope>All scopes
edges: Vec<Edge>All call graph edges
symbol_by_name: HashMap<CompactString, SmallVec<[u32; 4]>>Symbol lookup by name -> list of symbol IDs with that name SmallVec<[u32; 4]> because most names have 1-4 definitions
token_by_name: HashMap<CompactString, Vec<u32>>Token lookup by name -> list of token IDs with that name
incoming_edges: Vec<SmallVec<[u32; 8]>>Incoming edges per symbol (who calls this symbol) SmallVec<[u32; 8]> because most functions have <8 callers
outgoing_edges: Vec<SmallVec<[u32; 8]>>Outgoing edges per symbol (what does this symbol call) SmallVec<[u32; 8]> because most functions call <8 others
refs_to_symbol: Vec<Vec<u32>>References to each symbol (index by symbol_id)
files: Vec<PathBuf>List of indexed files (index = file_id)
strings: StringTableInterned string storage
entry_points: Vec<u32>Entry point symbol IDs (for fast traversal starting points)
Implementations§
Source§impl SemanticIndex
impl SemanticIndex
Sourcepub fn with_capacity(
symbols: usize,
tokens: usize,
references: usize,
scopes: usize,
edges: usize,
files: usize,
) -> Self
pub fn with_capacity( symbols: usize, tokens: usize, references: usize, scopes: usize, edges: usize, files: usize, ) -> Self
Create with estimated capacity for better allocation
Sourcepub fn add_file(&mut self, path: PathBuf) -> u16
pub fn add_file(&mut self, path: PathBuf) -> u16
Add a file to the index, returning its file_id
Sourcepub fn add_symbol(&mut self, symbol: Symbol, name: &str)
pub fn add_symbol(&mut self, symbol: Symbol, name: &str)
Add a symbol to the index
Sourcepub fn add_reference(&mut self, reference: Reference)
pub fn add_reference(&mut self, reference: Reference)
Add a reference to the index
Sourcepub fn rebuild_lookups(&mut self)
pub fn rebuild_lookups(&mut self)
Rebuild all lookup structures from raw data
Call this after loading from storage to populate HashMaps and adjacency lists.
Sourcepub fn symbols_by_name(&self, name: &str) -> Option<&SmallVec<[u32; 4]>>
pub fn symbols_by_name(&self, name: &str) -> Option<&SmallVec<[u32; 4]>>
Find symbols by exact name
Sourcepub fn symbols_matching(&self, pattern: &str) -> Vec<u32>
pub fn symbols_matching(&self, pattern: &str) -> Vec<u32>
Find symbols matching a name pattern (substring match)
Sourcepub fn tokens_matching(&self, pattern: &str) -> Vec<u32>
pub fn tokens_matching(&self, pattern: &str) -> Vec<u32>
Find tokens matching a name pattern (substring match)
Sourcepub fn symbol_name(&self, symbol: &Symbol) -> Option<&str>
pub fn symbol_name(&self, symbol: &Symbol) -> Option<&str>
Get the name of a symbol
Sourcepub fn token_name(&self, token: &Token) -> Option<&str>
pub fn token_name(&self, token: &Token) -> Option<&str>
Get the name of a token
Sourcepub fn callers(&self, symbol_id: u32) -> &[u32]
pub fn callers(&self, symbol_id: u32) -> &[u32]
Get symbols that call a given symbol (incoming edges)
Sourcepub fn callees(&self, symbol_id: u32) -> &[u32]
pub fn callees(&self, symbol_id: u32) -> &[u32]
Get symbols that a given symbol calls (outgoing edges)
Sourcepub fn references_to(
&self,
symbol_id: u32,
) -> impl Iterator<Item = &Reference> + '_
pub fn references_to( &self, symbol_id: u32, ) -> impl Iterator<Item = &Reference> + '_
Get all references to a symbol
Sourcepub fn references_of_kind(
&self,
symbol_id: u32,
kind: RefKind,
) -> impl Iterator<Item = &Reference>
pub fn references_of_kind( &self, symbol_id: u32, kind: RefKind, ) -> impl Iterator<Item = &Reference>
Get references of a specific kind to a symbol
Sourcepub fn call_references(
&self,
symbol_id: u32,
) -> impl Iterator<Item = &Reference>
pub fn call_references( &self, symbol_id: u32, ) -> impl Iterator<Item = &Reference>
Get call references to a symbol
Sourcepub fn entry_point_symbols(&self) -> impl Iterator<Item = &Symbol>
pub fn entry_point_symbols(&self) -> impl Iterator<Item = &Symbol>
Get all entry point symbols
Sourcepub fn symbols_in_file(&self, file_id: u16) -> impl Iterator<Item = &Symbol>
pub fn symbols_in_file(&self, file_id: u16) -> impl Iterator<Item = &Symbol>
Find symbols in a specific file
Sourcepub fn tokens_in_file(&self, file_id: u16) -> impl Iterator<Item = &Token>
pub fn tokens_in_file(&self, file_id: u16) -> impl Iterator<Item = &Token>
Find tokens in a specific file
Sourcepub fn stats(&self) -> IndexStats
pub fn stats(&self) -> IndexStats
Get index statistics
Sourcepub fn file_id_for_path(&self, path: &Path) -> Option<u16>
pub fn file_id_for_path(&self, path: &Path) -> Option<u16>
Find file_id for a given path, if it exists in the index
Sourcepub fn remove_file_data(&mut self, file_id: u16) -> usize
pub fn remove_file_data(&mut self, file_id: u16) -> usize
Remove all data associated with a specific file.
This removes symbols, tokens, references, scopes, and edges for the file, and cleans up the lookup structures accordingly.
Returns the number of symbols removed.
Sourcepub fn next_symbol_id(&self) -> u32
pub fn next_symbol_id(&self) -> u32
Get the next available symbol ID (for incremental additions)
Sourcepub fn next_token_id(&self) -> u32
pub fn next_token_id(&self) -> u32
Get the next available token ID (for incremental additions)
Sourcepub fn next_scope_id(&self) -> u32
pub fn next_scope_id(&self) -> u32
Get the next available scope ID (for incremental additions)
Trait Implementations§
Source§impl Debug for SemanticIndex
impl Debug for SemanticIndex
Auto Trait Implementations§
impl Freeze for SemanticIndex
impl RefUnwindSafe for SemanticIndex
impl Send for SemanticIndex
impl Sync for SemanticIndex
impl Unpin for SemanticIndex
impl UnwindSafe for SemanticIndex
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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