Skip to main content

TreeSnapshotResource

Struct TreeSnapshotResource 

Source
pub struct TreeSnapshotResource { /* private fields */ }
Expand description

Backing for the tree-snapshot WIT resource: a point-in-time parse tree.

Implementations§

Source§

impl TreeSnapshotResource

Source

pub fn new(snapshot: Arc<SyntaxSnapshot>) -> Self

Wrap an immutable syntax snapshot as a tree-snapshot backing.

Source

pub fn has_tree(&self) -> bool

Whether the snapshot carries a parse tree. The trampoline mints a resource only when this holds, so every resource method resolves.

Source

pub fn root(&self) -> NodeResource

The tree root.

Source

pub fn language(&self) -> String

The grammar id (e.g. "rust").

Source

pub fn node_at(&self, pos: Position) -> Option<NodeResource>

The smallest NAMED node spanning pos — descend to the smallest node, then walk up to the nearest named ancestor (the root is always named). None when there’s no tree / pos is out of range.

Source

pub fn enclosing(&self, pos: Position, kinds: &[String]) -> Option<NodeResource>

The nearest ancestor of pos (inclusive) whose kind is in kinds — the auto-pair scope query (the native scope_toward precedent). kinds empty → the nearest named ancestor (i.e. node_at). None when no ancestor matches / no tree.

Source

pub fn compile_query(&self, source: &str) -> Result<QueryResource, String>

TS.2: compile a tree-sitter query against this snapshot’s grammar. Err (the tree-sitter message) on a malformed query or a language with no registered grammar.

Source

pub fn run_query( &self, query: &QueryResource, within: Option<NativeRange>, ) -> Vec<(String, NodeResource)>

TS.2: run query over the whole tree (or within a point range), returning the surviving captures — tree-sitter evaluates the #eq? / #match? / #any-of? text predicates against the snapshot’s source (the TextProvider), so only matches that pass cross. Empty when there’s no tree or query was compiled for a different grammar (graceful).

Source

pub fn run_query_ranges( &self, query: &QueryResource, within: Option<NativeRange>, ) -> Vec<(String, u32, NativeRange)>

TS.2b: run_query reduced to extents — same traversal, same host-side predicate filtering, but no NodeResource per capture.

The saving is not the allocation: it is that every returned NodeResource becomes a guest-visible resource-table entry holding its own snapshot bump, which the guest must then drop one at a time across the boundary. A structural query over a large file returns tens of thousands of captures, and that per-capture round trip — not the query itself — is what made whole-file structural queries too slow to run.

The returned u32 is the match ordinal within THIS call, so captures from one pattern match stay groupable (@context with its @context.end) without a containment test on the guest side.

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

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
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> Pointee for T

§

type Pointer = u32

§

fn debug( pointer: <T as Pointee>::Pointer, f: &mut Formatter<'_>, ) -> Result<(), Error>

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more