pub struct ContainmentContext { /* private fields */ }Expand description
Tracks containment context during graph generation.
Maintains a stack of currently open containers based on line ranges, enabling determination of parent-child relationships for nested entities.
§Example
use codeprysm_core::parser::ContainmentContext;
let mut ctx = ContainmentContext::new();
// Processing a class definition at lines 10-50
ctx.push_container("file.py:MyClass".to_string(), "Container".to_string(), 10, 50, "MyClass".to_string());
// Inside the class, push a method at lines 15-25
ctx.update(15);
ctx.push_container("file.py:MyClass:method".to_string(), "Callable".to_string(), 15, 25, "method".to_string());
// Get the containment path
assert_eq!(ctx.get_containment_path(), vec!["MyClass", "method"]);
// After the method ends, update pops it
ctx.update(30);
assert_eq!(ctx.get_containment_path(), vec!["MyClass"]);Implementations§
Source§impl ContainmentContext
impl ContainmentContext
Sourcepub fn update(&mut self, current_line: usize)
pub fn update(&mut self, current_line: usize)
Update the stack by popping containers that have ended.
Call this before processing each new entity to ensure the stack reflects the current position in the source file.
Sourcepub fn push_container(
&mut self,
node_id: String,
node_type: String,
start_line: usize,
end_line: usize,
entity_name: String,
)
pub fn push_container( &mut self, node_id: String, node_type: String, start_line: usize, end_line: usize, entity_name: String, )
Push a new container onto the stack.
Only Container and Callable types can contain other entities.
Sourcepub fn get_current_parent_id(&self) -> Option<&str>
pub fn get_current_parent_id(&self) -> Option<&str>
Get the node ID of the current innermost container.
Returns None if at file level (no active containers).
Sourcepub fn get_containment_path(&self) -> Vec<&str>
pub fn get_containment_path(&self) -> Vec<&str>
Get the full containment path as a list of entity names.
Returns the path from outermost to innermost container.
Sourcepub fn is_container_active(&self, node_id: &str) -> bool
pub fn is_container_active(&self, node_id: &str) -> bool
Check if a container is currently active (on the stack).
Sourcepub fn stack(&self) -> &[ContainmentEntry]
pub fn stack(&self) -> &[ContainmentEntry]
Get a reference to the current stack.
Trait Implementations§
Source§impl Debug for ContainmentContext
impl Debug for ContainmentContext
Source§impl Default for ContainmentContext
impl Default for ContainmentContext
Source§fn default() -> ContainmentContext
fn default() -> ContainmentContext
Auto Trait Implementations§
impl Freeze for ContainmentContext
impl RefUnwindSafe for ContainmentContext
impl Send for ContainmentContext
impl Sync for ContainmentContext
impl Unpin for ContainmentContext
impl UnwindSafe for ContainmentContext
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