pub struct TreeSnapshotResource { /* private fields */ }Expand description
Backing for the tree-snapshot WIT resource: a point-in-time parse tree.
Implementations§
Source§impl TreeSnapshotResource
impl TreeSnapshotResource
Sourcepub fn new(snapshot: Arc<SyntaxSnapshot>) -> Self
pub fn new(snapshot: Arc<SyntaxSnapshot>) -> Self
Wrap an immutable syntax snapshot as a tree-snapshot backing.
Sourcepub fn has_tree(&self) -> bool
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.
Sourcepub fn root(&self) -> NodeResource
pub fn root(&self) -> NodeResource
The tree root.
Sourcepub fn node_at(&self, pos: Position) -> Option<NodeResource>
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.
Sourcepub fn enclosing(&self, pos: Position, kinds: &[String]) -> Option<NodeResource>
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.
Sourcepub fn compile_query(&self, source: &str) -> Result<QueryResource, String>
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.
Sourcepub fn run_query(
&self,
query: &QueryResource,
within: Option<NativeRange>,
) -> Vec<(String, NodeResource)>
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).
Sourcepub fn run_query_ranges(
&self,
query: &QueryResource,
within: Option<NativeRange>,
) -> Vec<(String, u32, NativeRange)>
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§
impl Freeze for TreeSnapshotResource
impl RefUnwindSafe for TreeSnapshotResource
impl Send for TreeSnapshotResource
impl Sync for TreeSnapshotResource
impl Unpin for TreeSnapshotResource
impl UnsafeUnpin for TreeSnapshotResource
impl UnwindSafe for TreeSnapshotResource
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> 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