ContainmentContext

Struct ContainmentContext 

Source
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

Source

pub fn new() -> Self

Create a new empty containment context.

Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn is_container_active(&self, node_id: &str) -> bool

Check if a container is currently active (on the stack).

Source

pub fn depth(&self) -> usize

Get the current stack depth.

Source

pub fn is_empty(&self) -> bool

Check if the stack is empty (at file level).

Source

pub fn clear(&mut self)

Clear the containment stack (typically called between files).

Source

pub fn stack(&self) -> &[ContainmentEntry]

Get a reference to the current stack.

Trait Implementations§

Source§

impl Debug for ContainmentContext

Source§

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

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

impl Default for ContainmentContext

Source§

fn default() -> ContainmentContext

Returns the “default value” for a type. Read more
Source§

impl Display for ContainmentContext

Source§

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

Formats the value using the given formatter. 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<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