Skip to main content

LinkedNode

Struct LinkedNode 

Source
pub struct LinkedNode<'a> { /* private fields */ }
Expand description

A syntax node in a context.

Knows its exact offset in the file and provides access to its children, parent and siblings.

Note that all sibling and leaf accessors skip over trivia!

Implementations§

Source§

impl<'a> LinkedNode<'a>

Source

pub fn new(root: &'a SyntaxNode) -> Self

Start a new traversal at a root node.

Source

pub fn get(&self) -> &'a SyntaxNode

Get the contained syntax node.

Source

pub fn index(&self) -> usize

The index of this node in its parent’s children list.

Source

pub fn offset(&self) -> usize

The absolute byte offset of this node in the source file.

Source

pub fn range(&self) -> Range<usize>

The byte range of this node in the source file.

Source

pub fn children(&self) -> LinkedChildren<'a>

An iterator over this node’s children.

Source

pub fn find(&self, span: Span) -> Option<Self>

Find a descendant with the given span.

Source

pub fn mode_after(&self) -> Option<SyntaxMode>

Get the SyntaxMode we will be in when immediately after this node.

Unlike some other LinkedNode methods, this does not treat all trivia the same: it returns None for both comments and the bodies of raw text and returns Some for whitespace (based on the parent’s mode). The only other way this would return None is when inside a partial tree, i.e. one not rooted in Markup, Math, or Code.

Also note that errors inherit the mode of their parent.

Source

pub fn parent_mode(&self) -> Option<SyntaxMode>

Get the SyntaxMode we will be in when immediately after the parent of this node.

Source§

impl LinkedNode<'_>

Access to parents and siblings.

Source

pub fn parent(&self) -> Option<&Self>

Get this node’s parent.

Source

pub fn prev_sibling(&self) -> Option<Self>

Get the first previous non-trivia sibling node.

Source

pub fn prev_sibling_with_trivia(&self) -> Option<Self>

Get the first previous sibling node, including potential trivia.

Source

pub fn next_sibling(&self) -> Option<Self>

Get the next non-trivia sibling node.

Source

pub fn next_sibling_with_trivia(&self) -> Option<Self>

Get the next sibling node, including potential trivia.

Source

pub fn parent_kind(&self) -> Option<SyntaxKind>

Get the kind of this node’s parent.

Source

pub fn prev_sibling_kind(&self) -> Option<SyntaxKind>

Get the kind of this node’s first previous non-trivia sibling.

Source

pub fn next_sibling_kind(&self) -> Option<SyntaxKind>

Get the kind of this node’s next non-trivia sibling.

Source§

impl LinkedNode<'_>

Access to leaves.

Source

pub fn prev_leaf(&self) -> Option<Self>

Get the rightmost non-trivia leaf before this node.

Source

pub fn leftmost_leaf(&self) -> Option<Self>

Find the leftmost contained non-trivia leaf.

Source

pub fn leaf_at(&self, cursor: usize, side: Side) -> Option<Self>

Get the leaf at the specified byte offset.

Source

pub fn rightmost_leaf(&self) -> Option<Self>

Find the rightmost contained non-trivia leaf.

Source

pub fn next_leaf(&self) -> Option<Self>

Get the leftmost non-trivia leaf after this node.

Methods from Deref<Target = SyntaxNode>§

Source

pub fn is<'a, T: AstNode<'a>>(&'a self) -> bool

Whether the node can be cast to the given AST node.

Source

pub fn cast<'a, T: AstNode<'a>>(&'a self) -> Option<T>

Try to convert the node to a typed AST node.

Source

pub fn kind(&self) -> SyntaxKind

The type of the node.

Source

pub fn is_empty(&self) -> bool

Return true if the length is 0.

Source

pub fn len(&self) -> usize

The byte length of the node in the source text.

Source

pub fn span(&self) -> Span

The span of the node.

Source

pub fn leaf_text(&self) -> &EcoString

The text of the node if it is a leaf or error node.

Returns the empty string if this is an inner node.

Source

pub fn full_text(&self) -> EcoString

Clone the full text from the node. If this is an inner node, it will traverse the tree to build the text which may be expensive.

Source

pub fn children(&self) -> Iter<'_, SyntaxNode>

The node’s children.

Source

pub fn diagnosis(&self) -> Diagnosis

Whether the node has diagnostic errors and/or warnings in it or its children. Diagnosis has public fields, so you can write node.diagnosis().errors to determine if a node is erroneous.

This can be used to determine whether Self::errors_and_warnings will return an empty vector without traversing the tree if it will not.

Source

pub fn errors_and_warnings( &self, ) -> (Vec<SyntaxDiagnostic>, Vec<SyntaxDiagnostic>)

The error and warning diagnostics for this node and its descendants.

Source

pub fn spanless_eq(&self, other: &Self) -> bool

Whether the two syntax nodes are the same apart from spans.

Trait Implementations§

Source§

impl<'a> Clone for LinkedNode<'a>

Source§

fn clone(&self) -> LinkedNode<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for LinkedNode<'_>

Source§

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

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

impl Deref for LinkedNode<'_>

Source§

fn deref(&self) -> &Self::Target

Dereference to a syntax node. Note that this shortens the lifetime, so you may need to use get() instead in some situations.

Source§

type Target = SyntaxNode

The resulting type after dereferencing.

Auto Trait Implementations§

§

impl<'a> !Send for LinkedNode<'a>

§

impl<'a> !Sync for LinkedNode<'a>

§

impl<'a> Freeze for LinkedNode<'a>

§

impl<'a> RefUnwindSafe for LinkedNode<'a>

§

impl<'a> Unpin for LinkedNode<'a>

§

impl<'a> UnsafeUnpin for LinkedNode<'a>

§

impl<'a> UnwindSafe for LinkedNode<'a>

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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.