IncrementalCache

Struct IncrementalCache 

Source
pub struct IncrementalCache<'pool, L: Language> {
    pub pool: &'pool mut GreenBuilder<L>,
    pub last_lex: Option<Vec<Token<L::SyntaxKind>>>,
    pub last_parse: Option<Arc<GreenNode<L::SyntaxKind>>>,
}
Expand description

Incremental cache for preserving old green trees and optional lexical caches.

This struct maintains state from previous parsing operations to enable incremental reparsing when source code changes. It stores the last lexed tokens and the last parsed green tree, allowing the parser to reuse unchanged portions of the kind tree.

Fields§

§pool: &'pool mut GreenBuilder<L>

The green builder for constructing new nodes

§last_lex: Option<Vec<Token<L::SyntaxKind>>>

The tokens from the previous lexical analysis

§last_parse: Option<Arc<GreenNode<L::SyntaxKind>>>

The green tree from the previous parsing operation

Implementations§

Source§

impl<'pool, L: Language> IncrementalCache<'pool, L>

Source

pub fn new(pool: &'pool mut GreenBuilder<L>) -> Self

Creates a new incremental cache with the provided green builder.

§Arguments
  • pool - The green builder to use for constructing new nodes
§Returns

A new IncrementalCache with no previous tokens or parse tree

Source

pub fn with_lexed(self, tokens: Vec<Token<L::SyntaxKind>>) -> Self

Sets the previously lexed tokens in the cache.

§Arguments
  • tokens - The tokens from a previous lexical analysis
§Returns

Self with the lexed tokens set

Source

pub fn with_parsed(self, green: GreenNode<L::SyntaxKind>) -> Self

Sets the previously parsed green tree in the cache.

§Arguments
  • green - The green tree from a previous parsing operation
§Returns

Self with the parsed tree set

Source

pub fn get_token(&self, index: usize) -> Option<&Token<L::SyntaxKind>>

Get a token from the cached lexical analysis by index.

§Arguments
  • index - The index of the token to retrieve
§Returns

An optional reference to the token at the specified index, or None if no tokens are cached or the index is out of bounds

Source

pub fn count_tokens(&self) -> usize

Get the total number of tokens in the cached lexical analysis.

§Returns

The number of tokens in the cache, or 0 if no tokens are cached

Trait Implementations§

Source§

impl<'pool, L: Debug + Language> Debug for IncrementalCache<'pool, L>
where L::SyntaxKind: Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'pool, L> Freeze for IncrementalCache<'pool, L>

§

impl<'pool, L> RefUnwindSafe for IncrementalCache<'pool, L>

§

impl<'pool, L> Send for IncrementalCache<'pool, L>
where <L as Language>::SyntaxKind: Sync,

§

impl<'pool, L> Sync for IncrementalCache<'pool, L>
where <L as Language>::SyntaxKind: Sync,

§

impl<'pool, L> Unpin for IncrementalCache<'pool, L>
where <L as Language>::SyntaxKind: Unpin,

§

impl<'pool, L> !UnwindSafe for IncrementalCache<'pool, L>

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, 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, 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> ErasedDestructor for T
where T: 'static,