pub struct SymbolRegistry { /* private fields */ }Expand description
Central registry for symbol management
§Single Point of Access
All symbol operations must go through SymbolRegistry.
- Get SymbolId:
register()orlookup() - Get/update metadata:
kind(),span(),set_span(), etc. - Graph operations also use SymbolId
§Responsibilities
- Bidirectional SymbolPath ↔ SymbolId conversion
- Metadata management (Kind, Span, Visibility, etc.)
- Symbol lifecycle management
§Thread Safety
- Read operations are thread-safe
- Write operations require exclusive access (Executor controls this at Tick boundaries)
Implementations§
Source§impl SymbolRegistry
impl SymbolRegistry
Sourcepub fn new() -> SymbolRegistry
pub fn new() -> SymbolRegistry
Create a new empty registry
Sourcepub fn with_capacity(capacity: usize) -> SymbolRegistry
pub fn with_capacity(capacity: usize) -> SymbolRegistry
Create with pre-allocated capacity
Sourcepub fn register(
&mut self,
path: SymbolPath,
kind: SymbolKind,
) -> Result<SymbolId, RegistrationError>
pub fn register( &mut self, path: SymbolPath, kind: SymbolKind, ) -> Result<SymbolId, RegistrationError>
Register a symbol (returns existing ID if already registered)
§Returns
Ok(SymbolId): Registration successful (new or existing)Err(RegistrationError): Registration failed
Sourcepub fn register_with_metadata(
&mut self,
path: SymbolPath,
kind: SymbolKind,
span: Option<FileSpan>,
vis: Option<Visibility>,
) -> Result<SymbolId, RegistrationError>
pub fn register_with_metadata( &mut self, path: SymbolPath, kind: SymbolKind, span: Option<FileSpan>, vis: Option<Visibility>, ) -> Result<SymbolId, RegistrationError>
Register with full metadata
Sourcepub fn register_var(
&mut self,
containing_symbol: SymbolId,
scope: VarScope,
name: &str,
kind: SymbolKind,
) -> Result<SymbolId, RegistrationError>
pub fn register_var( &mut self, containing_symbol: SymbolId, scope: VarScope, name: &str, kind: SymbolKind, ) -> Result<SymbolId, RegistrationError>
Register a variable (InSymbol)
Creates a path like parent::$scope::name and registers it.
§Arguments
containing_symbol: Parent symbol (function/method/struct)scope: Variable scope typename: Variable namekind: Symbol kind (Variable, Parameter, or Field)
Sourcepub fn lookup(&self, path: &SymbolPath) -> Option<SymbolId>
pub fn lookup(&self, path: &SymbolPath) -> Option<SymbolId>
SymbolPath → SymbolId (O(1) hash lookup)
Also resolves re-export aliases to their canonical ID.
Sourcepub fn resolve(&self, id: SymbolId) -> Option<&SymbolPath>
pub fn resolve(&self, id: SymbolId) -> Option<&SymbolPath>
SymbolId → SymbolPath (O(1) array access)
Sourcepub fn path(&self, id: SymbolId) -> Option<&SymbolPath>
pub fn path(&self, id: SymbolId) -> Option<&SymbolPath>
Alias for resolve() - get path from ID
Sourcepub fn contains(&self, id: SymbolId) -> bool
pub fn contains(&self, id: SymbolId) -> bool
Check if SymbolId is valid (with generation check)
Sourcepub fn kind(&self, id: SymbolId) -> Option<SymbolKind>
pub fn kind(&self, id: SymbolId) -> Option<SymbolKind>
Get kind
Sourcepub fn visibility(&self, id: SymbolId) -> Option<&Visibility>
pub fn visibility(&self, id: SymbolId) -> Option<&Visibility>
Get visibility
Sourcepub fn set_span(
&mut self,
id: SymbolId,
span: FileSpan,
) -> Result<(), InvalidSymbolId>
pub fn set_span( &mut self, id: SymbolId, span: FileSpan, ) -> Result<(), InvalidSymbolId>
Set/update span
Sourcepub fn set_visibility(
&mut self,
id: SymbolId,
vis: Visibility,
) -> Result<(), InvalidSymbolId>
pub fn set_visibility( &mut self, id: SymbolId, vis: Visibility, ) -> Result<(), InvalidSymbolId>
Set/update visibility
Sourcepub fn set_kind(
&mut self,
id: SymbolId,
kind: SymbolKind,
) -> Result<(), InvalidSymbolId>
pub fn set_kind( &mut self, id: SymbolId, kind: SymbolKind, ) -> Result<(), InvalidSymbolId>
Set/update kind
Sourcepub fn remove(&mut self, id: SymbolId) -> Option<SymbolPath>
pub fn remove(&mut self, id: SymbolId) -> Option<SymbolPath>
Remove a symbol from the registry
Returns the path of the removed symbol, or None if the ID was invalid. Also removes the persistent UUID mapping if present.
Sourcepub fn rename(
&mut self,
id: SymbolId,
new_path: SymbolPath,
) -> Result<SymbolPath, RenameError>
pub fn rename( &mut self, id: SymbolId, new_path: SymbolPath, ) -> Result<SymbolPath, RenameError>
Rename a symbol
Returns the old path on success.
Sourcepub fn find_by_name(&self, name: &str) -> Vec<SymbolId>
pub fn find_by_name(&self, name: &str) -> Vec<SymbolId>
Find all symbols with the given name (last segment of path).
Also includes canonical symbols that have re-export aliases matching the name.
Sourcepub fn lookup_by_name(&self, name: &str) -> Option<SymbolId>
pub fn lookup_by_name(&self, name: &str) -> Option<SymbolId>
Find a single symbol by name (returns first match)
Sourcepub fn register_reexport(
&mut self,
canonical_id: SymbolId,
alias_path: SymbolPath,
origin_file: WorkspaceFilePath,
) -> Result<(), InvalidSymbolId>
pub fn register_reexport( &mut self, canonical_id: SymbolId, alias_path: SymbolPath, origin_file: WorkspaceFilePath, ) -> Result<(), InvalidSymbolId>
Register a re-export
Sourcepub fn unregister_reexport(
&mut self,
alias_path: &SymbolPath,
) -> Result<(), UnregisterReexportError>
pub fn unregister_reexport( &mut self, alias_path: &SymbolPath, ) -> Result<(), UnregisterReexportError>
Unregister a re-export
Sourcepub fn re_exports(&self, id: SymbolId) -> Option<&[ReExportInfo]>
pub fn re_exports(&self, id: SymbolId) -> Option<&[ReExportInfo]>
Get re-exports for a symbol
Sourcepub fn register_persistent(
&mut self,
path: SymbolPath,
kind: SymbolKind,
uuid: Option<Uuid>,
) -> Result<(SymbolId, Uuid), RegistrationError>
pub fn register_persistent( &mut self, path: SymbolPath, kind: SymbolKind, uuid: Option<Uuid>, ) -> Result<(SymbolId, Uuid), RegistrationError>
Register a symbol with persistent UUID
This method assigns a stable UUID to the symbol that survives across sessions. Use this for symbols that need to be tracked through renames or serialized.
§Arguments
path: Symbol pathkind: Symbol kinduuid:Some(uuid)when restoring from serialized data,Noneto generate new
§Returns
Ok((SymbolId, Uuid)): The runtime ID and persistent UUIDErr(RegistrationError): Registration failed
§Example
// New symbol (generates UUID)
let (id, uuid) = registry.register_persistent(path, kind, None)?;
// Restore from serialized data
let (id, uuid) = registry.register_persistent(path, kind, Some(saved_uuid))?;Sourcepub fn assign_uuid(
&mut self,
id: SymbolId,
uuid: Option<Uuid>,
) -> Result<Uuid, InvalidSymbolId>
pub fn assign_uuid( &mut self, id: SymbolId, uuid: Option<Uuid>, ) -> Result<Uuid, InvalidSymbolId>
Assign a persistent UUID to an existing symbol
Use this to add persistence to a symbol that was registered without UUID.
§Returns
Ok(Uuid): The assigned UUID (existing or new)Err(InvalidSymbolId): Symbol doesn’t exist
Sourcepub fn uuid(&self, id: SymbolId) -> Option<Uuid>
pub fn uuid(&self, id: SymbolId) -> Option<Uuid>
Get persistent UUID for a symbol (O(1))
Returns None if the symbol was not registered with persistence.
Sourcepub fn lookup_by_uuid(&self, uuid: Uuid) -> Option<SymbolId>
pub fn lookup_by_uuid(&self, uuid: Uuid) -> Option<SymbolId>
Lookup symbol by persistent UUID (O(1))
Use this when deserializing references from saved data.
Sourcepub fn iter_persistent(&self) -> impl Iterator<Item = (SymbolId, Uuid)>
pub fn iter_persistent(&self) -> impl Iterator<Item = (SymbolId, Uuid)>
Get all symbols with persistent UUIDs
Sourcepub fn persistent_count(&self) -> usize
pub fn persistent_count(&self) -> usize
Get count of symbols with persistent UUIDs
Sourcepub fn preload_uuid_mapping(&mut self, mappings: HashMap<SymbolPath, Uuid>)
pub fn preload_uuid_mapping(&mut self, mappings: HashMap<SymbolPath, Uuid>)
Preload UUID mappings from a previous session.
Call this before registering symbols to restore persistent UUIDs.
When register() is called, it will use preloaded UUIDs instead of
generating new ones.
§Arguments
mappings- HashMap of SymbolPath → UUID from previous session
§Example
// Load from file
let mappings: HashMap<SymbolPath, Uuid> = load_from_file(path)?;
registry.preload_uuid_mapping(mappings);
// Now register symbols - they'll get their previous UUIDs
registry.register(path, kind)?;Sourcepub fn export_uuid_mapping(&self) -> HashMap<SymbolPath, Uuid>
pub fn export_uuid_mapping(&self) -> HashMap<SymbolPath, Uuid>
Sourcepub fn export_uuid_mapping_strings(&self) -> HashMap<String, String>
pub fn export_uuid_mapping_strings(&self) -> HashMap<String, String>
Export UUID mappings as strings for JSON serialization.
Converts SymbolPath and Uuid to String for easy JSON storage.
Sourcepub fn preload_uuid_mapping_strings(
&mut self,
mappings: HashMap<String, String>,
)
pub fn preload_uuid_mapping_strings( &mut self, mappings: HashMap<String, String>, )
Preload UUID mappings from string format (for JSON deserialization).
Parses string keys/values back to SymbolPath/Uuid. Invalid entries are silently skipped.
Sourcepub fn iter(&self) -> impl Iterator<Item = (SymbolId, &SymbolPath)>
pub fn iter(&self) -> impl Iterator<Item = (SymbolId, &SymbolPath)>
Iterate over all symbols
Sourcepub fn iter_by_kind(&self, kind: SymbolKind) -> impl Iterator<Item = SymbolId>
pub fn iter_by_kind(&self, kind: SymbolKind) -> impl Iterator<Item = SymbolId>
Iterate over symbols of a specific kind
Sourcepub fn iter_in_crate<'a>(
&'a self,
crate_name: &'a str,
) -> impl Iterator<Item = SymbolId> + 'a
pub fn iter_in_crate<'a>( &'a self, crate_name: &'a str, ) -> impl Iterator<Item = SymbolId> + 'a
Iterate over symbols in a specific crate
Sourcepub fn memory_stats(&self) -> MemoryStats
pub fn memory_stats(&self) -> MemoryStats
Get memory usage statistics
Trait Implementations§
Source§impl Clone for SymbolRegistry
impl Clone for SymbolRegistry
Source§fn clone(&self) -> SymbolRegistry
fn clone(&self) -> SymbolRegistry
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Default for SymbolRegistry
impl Default for SymbolRegistry
Source§fn default() -> SymbolRegistry
fn default() -> SymbolRegistry
Auto Trait Implementations§
impl Freeze for SymbolRegistry
impl RefUnwindSafe for SymbolRegistry
impl Send for SymbolRegistry
impl Sync for SymbolRegistry
impl Unpin for SymbolRegistry
impl UnsafeUnpin for SymbolRegistry
impl UnwindSafe for SymbolRegistry
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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