SemanticIndex

Struct SemanticIndex 

Source
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: StringTable

Interned string storage

§entry_points: Vec<u32>

Entry point symbol IDs (for fast traversal starting points)

Implementations§

Source§

impl SemanticIndex

Source

pub fn new() -> Self

Create a new empty semantic index

Source

pub fn with_capacity( symbols: usize, tokens: usize, references: usize, scopes: usize, edges: usize, files: usize, ) -> Self

Create with estimated capacity for better allocation

Source

pub fn add_file(&mut self, path: PathBuf) -> u16

Add a file to the index, returning its file_id

Source

pub fn add_symbol(&mut self, symbol: Symbol, name: &str)

Add a symbol to the index

Source

pub fn add_token(&mut self, token: Token, name: &str)

Add a token to the index

Source

pub fn add_reference(&mut self, reference: Reference)

Add a reference to the index

Source

pub fn add_scope(&mut self, scope: Scope)

Add a scope to the index

Source

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

Add an edge to the index

Source

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.

Source

pub fn symbols_by_name(&self, name: &str) -> Option<&SmallVec<[u32; 4]>>

Find symbols by exact name

Source

pub fn symbols_matching(&self, pattern: &str) -> Vec<u32>

Find symbols matching a name pattern (substring match)

Source

pub fn tokens_by_name(&self, name: &str) -> Option<&Vec<u32>>

Find tokens by exact name

Source

pub fn tokens_matching(&self, pattern: &str) -> Vec<u32>

Find tokens matching a name pattern (substring match)

Source

pub fn symbol(&self, id: u32) -> Option<&Symbol>

Get a symbol by ID

Source

pub fn token(&self, id: u32) -> Option<&Token>

Get a token by ID

Source

pub fn scope(&self, id: u32) -> Option<&Scope>

Get a scope by ID

Source

pub fn symbol_name(&self, symbol: &Symbol) -> Option<&str>

Get the name of a symbol

Source

pub fn token_name(&self, token: &Token) -> Option<&str>

Get the name of a token

Source

pub fn file_path(&self, file_id: u16) -> Option<&PathBuf>

Get the file path for a file_id

Source

pub fn callers(&self, symbol_id: u32) -> &[u32]

Get symbols that call a given symbol (incoming edges)

Source

pub fn callees(&self, symbol_id: u32) -> &[u32]

Get symbols that a given symbol calls (outgoing edges)

Source

pub fn references_to( &self, symbol_id: u32, ) -> impl Iterator<Item = &Reference> + '_

Get all references to a symbol

Source

pub fn references_of_kind( &self, symbol_id: u32, kind: RefKind, ) -> impl Iterator<Item = &Reference>

Get references of a specific kind to a symbol

Source

pub fn call_references( &self, symbol_id: u32, ) -> impl Iterator<Item = &Reference>

Get call references to a symbol

Source

pub fn entry_point_symbols(&self) -> impl Iterator<Item = &Symbol>

Get all entry point symbols

Source

pub fn symbols_in_file(&self, file_id: u16) -> impl Iterator<Item = &Symbol>

Find symbols in a specific file

Source

pub fn tokens_in_file(&self, file_id: u16) -> impl Iterator<Item = &Token>

Find tokens in a specific file

Source

pub fn stats(&self) -> IndexStats

Get index statistics

Source

pub fn file_id_for_path(&self, path: &Path) -> Option<u16>

Find file_id for a given path, if it exists in the index

Source

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.

Source

pub fn next_symbol_id(&self) -> u32

Get the next available symbol ID (for incremental additions)

Source

pub fn next_token_id(&self) -> u32

Get the next available token ID (for incremental additions)

Source

pub fn next_scope_id(&self) -> u32

Get the next available scope ID (for incremental additions)

Source

pub fn has_file(&self, path: &Path) -> bool

Check if a file path is already indexed

Trait Implementations§

Source§

impl Debug for SemanticIndex

Source§

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

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

impl Default for SemanticIndex

Source§

fn default() -> Self

Returns the “default value” for a type. 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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Send + Sync>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
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> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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> Fruit for T
where T: Send + Downcast,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,