pub struct ASTMutationContext<'a> {
pub ast_registry: &'a mut ASTRegistry,
pub symbol_registry: &'a mut SymbolRegistry,
/* private fields */
}Expand description
Context passed to ASTRegApply::apply_to_registry
Provides access to ASTRegistry, SymbolRegistry, and event emission.
§Binary Entry (main.rs) Support
Binary entry symbols (main.rs, src/bin/*.rs) are registered in the unified
items map like library symbols. Use WorkspaceFilePath::is_binary_entry()
to identify binary files when needed for file output.
Fields§
§ast_registry: &'a mut ASTRegistryAST storage (complete PureItem per symbol)
symbol_registry: &'a mut SymbolRegistrySymbol metadata (path ↔ id, kind, span, etc.)
Implementations§
Source§impl<'a> ASTMutationContext<'a>
impl<'a> ASTMutationContext<'a>
Sourcepub fn new(
ast_registry: &'a mut ASTRegistry,
symbol_registry: &'a mut SymbolRegistry,
) -> Self
pub fn new( ast_registry: &'a mut ASTRegistry, symbol_registry: &'a mut SymbolRegistry, ) -> Self
Create a new mutation context
Sourcepub fn into_events(self) -> Vec<MutationEvent>
pub fn into_events(self) -> Vec<MutationEvent>
Consume context and return collected events
Sourcepub fn emit(&mut self, event: MutationEvent)
pub fn emit(&mut self, event: MutationEvent)
Emit an event (for logging/tracking)
Sourcepub fn emit_added(&mut self, path: SymbolPath, kind: SymbolKind)
pub fn emit_added(&mut self, path: SymbolPath, kind: SymbolKind)
Emit symbol added event
Sourcepub fn emit_removed(&mut self, path: SymbolPath)
pub fn emit_removed(&mut self, path: SymbolPath)
Emit symbol removed event
Sourcepub fn emit_modified(&mut self, id: SymbolId, modification: ModificationType)
pub fn emit_modified(&mut self, id: SymbolId, modification: ModificationType)
Emit symbol modified event
Sourcepub fn emit_renamed(&mut self, old_path: SymbolPath, new_path: SymbolPath)
pub fn emit_renamed(&mut self, old_path: SymbolPath, new_path: SymbolPath)
Emit symbol renamed event
Sourcepub fn get_ast_mut(&mut self, id: SymbolId) -> Option<&mut PureItem>
pub fn get_ast_mut(&mut self, id: SymbolId) -> Option<&mut PureItem>
Get AST for a symbol (mutable)
Sourcepub fn lookup(&self, path: &SymbolPath) -> Option<SymbolId>
pub fn lookup(&self, path: &SymbolPath) -> Option<SymbolId>
Lookup symbol by path
Sourcepub fn path(&self, id: SymbolId) -> Option<&SymbolPath>
pub fn path(&self, id: SymbolId) -> Option<&SymbolPath>
Get symbol path by ID
Sourcepub fn kind(&self, id: SymbolId) -> Option<SymbolKind>
pub fn kind(&self, id: SymbolId) -> Option<SymbolKind>
Get symbol kind by ID
Sourcepub fn resolve_symbol_by_name(
&self,
name: &str,
kinds: &[SymbolKind],
) -> Result<SymbolId, ResolveError>
pub fn resolve_symbol_by_name( &self, name: &str, kinds: &[SymbolKind], ) -> Result<SymbolId, ResolveError>
Resolve symbol ID by name, supporting both simple name and full path.
- If
namecontains “::”, performs full path match (always unique) - Otherwise, matches by last segment (symbol name) only
§Errors
ResolveError::NotFound- no matching symbolResolveError::Ambiguous- multiple symbols match (use full path)
§Example
// Find struct by simple name (fails if multiple "User" exist)
let id = ctx.resolve_symbol_by_name("User", &[SymbolKind::Struct])?;
// Find by full path (always unambiguous)
let id = ctx.resolve_symbol_by_name("crate::user::UserStatus", &[SymbolKind::Enum])?;Sourcepub fn register(
&mut self,
path: SymbolPath,
kind: SymbolKind,
) -> Option<SymbolId>
pub fn register( &mut self, path: SymbolPath, kind: SymbolKind, ) -> Option<SymbolId>
Register new symbol (emits SymbolAdded event)
Returns None if registration fails (e.g., duplicate path).
Sourcepub fn register_with_ast(
&mut self,
path: SymbolPath,
kind: SymbolKind,
ast: PureItem,
) -> Option<SymbolId>
pub fn register_with_ast( &mut self, path: SymbolPath, kind: SymbolKind, ast: PureItem, ) -> Option<SymbolId>
Register new symbol with AST (emits SymbolAdded event)
Returns None if registration fails.
Sourcepub fn remove_symbol(&mut self, id: SymbolId) -> Option<PureItem>
pub fn remove_symbol(&mut self, id: SymbolId) -> Option<PureItem>
Remove symbol (emits SymbolRemoved event)
This removes the symbol from:
- SymbolRegistry (path → id mapping)
- ASTRegistry items (id → PureItem mapping)
- Parent module’s module_items list (for file generation)
Sourcepub fn rename_symbol(
&mut self,
id: SymbolId,
new_path: SymbolPath,
) -> Result<(), String>
pub fn rename_symbol( &mut self, id: SymbolId, new_path: SymbolPath, ) -> Result<(), String>
Rename symbol (emits SymbolRenamed event)
Auto Trait Implementations§
impl<'a> Freeze for ASTMutationContext<'a>
impl<'a> RefUnwindSafe for ASTMutationContext<'a>
impl<'a> Send for ASTMutationContext<'a>
impl<'a> Sync for ASTMutationContext<'a>
impl<'a> Unpin for ASTMutationContext<'a>
impl<'a> UnsafeUnpin for ASTMutationContext<'a>
impl<'a> !UnwindSafe for ASTMutationContext<'a>
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