tree_sitter

Struct Tree

Source
pub struct Tree(/* private fields */);
Expand description

A tree that represents the syntactic structure of a source code file.

Implementations§

Source§

impl Tree

Source

pub const unsafe fn from_raw(ptr: *mut TSTree) -> Self

Reconstructs a Tree from a raw pointer.

§Safety

ptr must be non-null.

Source

pub fn into_raw(self) -> *mut TSTree

Consumes the Tree, returning a raw pointer to the underlying C structure.

Source§

impl Tree

Source

pub fn root_node(&self) -> Node<'_>

Get the root node of the syntax tree.

Source

pub fn root_node_with_offset( &self, offset_bytes: usize, offset_extent: Point, ) -> Node<'_>

Get the root node of the syntax tree, but with its position shifted forward by the given offset.

Source

pub fn language(&self) -> LanguageRef<'_>

Get the language that was used to parse the syntax tree.

Source

pub fn edit(&mut self, edit: &InputEdit)

Edit the syntax tree to keep it in sync with source code that has been edited.

You must describe the edit both in terms of byte offsets and in terms of row/column coordinates.

Source

pub fn walk(&self) -> TreeCursor<'_>

Create a new TreeCursor starting from the root of the tree.

Source

pub fn changed_ranges( &self, other: &Self, ) -> impl ExactSizeIterator<Item = Range>

Compare this old edited syntax tree to a new syntax tree representing the same document, returning a sequence of ranges whose syntactic structure has changed.

For this to work correctly, this syntax tree must have been edited such that its ranges match up to the new tree. Generally, you’ll want to call this method right after calling one of the Parser::parse functions. Call it on the old tree that was passed to parse, and pass the new tree that was returned from parse.

Source

pub fn included_ranges(&self) -> Vec<Range>

Get the included ranges that were used to parse the syntax tree.

Source

pub fn print_dot_graph(&self, file: &impl AsRawFd)

Print a graph of the tree to the given file descriptor. The graph is formatted in the DOT language. You may want to pipe this graph directly to a dot(1) process in order to generate SVG output.

Trait Implementations§

Source§

impl Clone for Tree

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Tree

Source§

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

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

impl Drop for Tree

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for Tree

Source§

impl Sync for Tree

Auto Trait Implementations§

§

impl Freeze for Tree

§

impl RefUnwindSafe for Tree

§

impl Unpin for Tree

§

impl UnwindSafe for Tree

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.