pub struct ScopeTree<K: ScopeKindTrait> {
pub scopes: Vec<Scope<K>>,
pub interner: StringInterner,
pub class_members: ClassMemberIndex,
pub class_infos: ClassInfoIndex,
pub debug: DebugLogLimiter,
pub content_len: usize,
/* private fields */
}Expand description
Per-file scope tree with variable binding and resolution.
Generic over K, a language-specific ScopeKind enum that implements
ScopeKindTrait.
Fields§
§scopes: Vec<Scope<K>>All scopes, indexed by ScopeId.
interner: StringInternerString deduplication cache.
class_members: ClassMemberIndexClass member tracking (for OOP languages).
class_infos: ClassInfoIndexClass info index (for type name resolution).
debug: DebugLogLimiterRate-limited debug logger.
content_len: usizeTotal content length in bytes (for span validation).
Implementations§
Source§impl<K: ScopeKindTrait> ScopeTree<K>
impl<K: ScopeKindTrait> ScopeTree<K>
Sourcepub fn new(content_len: usize) -> Self
pub fn new(content_len: usize) -> Self
Create a new empty scope tree for the given content length.
Language plugins should populate the tree using add_scope(),
add_binding(), and rebuild_index().
Sourcepub fn attach_node_id(
&mut self,
name: &str,
decl_start_byte: usize,
node_id: NodeId,
) -> bool
pub fn attach_node_id( &mut self, name: &str, decl_start_byte: usize, node_id: NodeId, ) -> bool
Attach a graph NodeId to an existing variable binding.
First tries exact match by name + byte position. Falls back to
a fuzzy match (single unattached binding with the same name).
Returns true if a binding was found and updated.
Sourcepub fn resolve_identifier(
&mut self,
usage_byte: usize,
identifier: &str,
) -> ResolutionOutcome
pub fn resolve_identifier( &mut self, usage_byte: usize, identifier: &str, ) -> ResolutionOutcome
Resolve an identifier to a local variable, class member, or no-match.
This is the primary entry point for resolution. It:
- Finds the innermost scope at the usage byte position
- Builds a scope chain to the root
- Detects class boundaries and handles capture semantics
- Falls back to class member resolution for OOP languages
Sourcepub fn is_known_type_name(&self, name: &str) -> bool
pub fn is_known_type_name(&self, name: &str) -> bool
Quick check if a name is a known type/class name.
Sourcepub fn has_local_binding(&self, name: &str, byte: usize) -> bool
pub fn has_local_binding(&self, name: &str, byte: usize) -> bool
Quick check if a local variable binding exists for name at the given byte position.
Sourcepub fn resolve_local_in_chain(
&self,
identifier: &str,
usage_byte: usize,
chain: &[ScopeId],
) -> Option<LocalBindingMatch>
pub fn resolve_local_in_chain( &self, identifier: &str, usage_byte: usize, chain: &[ScopeId], ) -> Option<LocalBindingMatch>
Walk a scope chain looking for a binding matching identifier before usage_byte.
Sourcepub fn resolve_class_member(
&mut self,
scope_id: ScopeId,
identifier: &str,
) -> Option<ResolutionOutcome>
pub fn resolve_class_member( &mut self, scope_id: ScopeId, identifier: &str, ) -> Option<ResolutionOutcome>
Resolve a class member by scope ID and identifier name.
Sourcepub fn innermost_scope_at(&self, byte: usize) -> Option<ScopeId>
pub fn innermost_scope_at(&self, byte: usize) -> Option<ScopeId>
Find the innermost (deepest) scope containing the given byte position.
Uses a sorted interval index with binary search + reverse scan for O(log n) lookup.
Sourcepub fn scope_chain(&self, innermost: ScopeId) -> Vec<ScopeId> ⓘ
pub fn scope_chain(&self, innermost: ScopeId) -> Vec<ScopeId> ⓘ
Build the parent chain from a scope to the root.
Sourcepub fn add_scope(
&mut self,
kind: K,
start_byte: usize,
end_byte: usize,
parent: Option<ScopeId>,
) -> Option<ScopeId>
pub fn add_scope( &mut self, kind: K, start_byte: usize, end_byte: usize, parent: Option<ScopeId>, ) -> Option<ScopeId>
Add a new scope to the tree.
Returns None if the span is invalid (start > end or beyond content).
Sourcepub fn rebuild_index(&mut self)
pub fn rebuild_index(&mut self)
Rebuild the interval index from the current scopes.
Must be called after adding scopes and before performing lookups.
Sourcepub fn add_binding(
&mut self,
scope_id: ScopeId,
name: &str,
decl_start_byte: usize,
decl_end_byte: usize,
declarator_end_byte: usize,
initializer_start_byte: Option<usize>,
)
pub fn add_binding( &mut self, scope_id: ScopeId, name: &str, decl_start_byte: usize, decl_end_byte: usize, declarator_end_byte: usize, initializer_start_byte: Option<usize>, )
Add a variable binding to a scope.
Performs overlap detection before adding. If the binding would overlap with an existing binding in the same or enclosing scope (depending on language rules), it is silently rejected.
Trait Implementations§
Auto Trait Implementations§
impl<K> Freeze for ScopeTree<K>
impl<K> RefUnwindSafe for ScopeTree<K>where
K: RefUnwindSafe,
impl<K> Send for ScopeTree<K>
impl<K> Sync for ScopeTree<K>
impl<K> Unpin for ScopeTree<K>where
K: Unpin,
impl<K> UnsafeUnpin for ScopeTree<K>
impl<K> UnwindSafe for ScopeTree<K>where
K: UnwindSafe,
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 moreSource§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