Struct tree_sitter::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> 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,

§

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>,

§

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>,

§

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.