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>
impl<'a> LinkedNode<'a>
Sourcepub fn new(root: &'a SyntaxNode) -> Self
pub fn new(root: &'a SyntaxNode) -> Self
Start a new traversal at a root node.
Sourcepub fn get(&self) -> &'a SyntaxNode
pub fn get(&self) -> &'a SyntaxNode
Get the contained syntax node.
Sourcepub fn children(&self) -> LinkedChildren<'a> ⓘ
pub fn children(&self) -> LinkedChildren<'a> ⓘ
An iterator over this node’s children.
Sourcepub fn find(&self, span: Span) -> Option<LinkedNode<'a>>
pub fn find(&self, span: Span) -> Option<LinkedNode<'a>>
Find a descendant with the given span.
Source§impl<'a> LinkedNode<'a>
Access to parents and siblings.
impl<'a> LinkedNode<'a>
Access to parents and siblings.
Sourcepub fn prev_sibling(&self) -> Option<Self>
pub fn prev_sibling(&self) -> Option<Self>
Get the first previous non-trivia sibling node.
Sourcepub fn next_sibling(&self) -> Option<Self>
pub fn next_sibling(&self) -> Option<Self>
Get the next non-trivia sibling node.
Sourcepub fn parent_kind(&self) -> Option<SyntaxKind>
pub fn parent_kind(&self) -> Option<SyntaxKind>
Get the kind of this node’s parent.
Sourcepub fn prev_sibling_kind(&self) -> Option<SyntaxKind>
pub fn prev_sibling_kind(&self) -> Option<SyntaxKind>
Get the kind of this node’s first previous non-trivia sibling.
Sourcepub fn next_sibling_kind(&self) -> Option<SyntaxKind>
pub fn next_sibling_kind(&self) -> Option<SyntaxKind>
Get the kind of this node’s next non-trivia sibling.
Source§impl<'a> LinkedNode<'a>
Access to leaves.
impl<'a> LinkedNode<'a>
Access to leaves.
Sourcepub fn leftmost_leaf(&self) -> Option<Self>
pub fn leftmost_leaf(&self) -> Option<Self>
Find the leftmost contained non-trivia leaf.
Sourcepub fn leaf_at(&self, cursor: usize, side: Side) -> Option<Self>
pub fn leaf_at(&self, cursor: usize, side: Side) -> Option<Self>
Get the leaf at the specified byte offset.
Sourcepub fn rightmost_leaf(&self) -> Option<Self>
pub fn rightmost_leaf(&self) -> Option<Self>
Find the rightmost contained non-trivia leaf.
Methods from Deref<Target = SyntaxNode>§
Sourcepub fn kind(&self) -> SyntaxKind
pub fn kind(&self) -> SyntaxKind
The type of the node.
Sourcepub fn text(&self) -> &EcoString
pub fn 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.
Sourcepub fn children(&self) -> Iter<'_, SyntaxNode>
pub fn children(&self) -> Iter<'_, SyntaxNode>
The node’s children.
Sourcepub fn is<'a, T: AstNode<'a>>(&'a self) -> bool
pub fn is<'a, T: AstNode<'a>>(&'a self) -> bool
Whether the node can be cast to the given AST node.
Sourcepub fn cast<'a, T: AstNode<'a>>(&'a self) -> Option<T>
pub fn cast<'a, T: AstNode<'a>>(&'a self) -> Option<T>
Try to convert the node to a typed AST node.
Sourcepub fn cast_first_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
pub fn cast_first_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
Cast the first child that can cast to the AST type T
.
Sourcepub fn cast_last_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
pub fn cast_last_match<'a, T: AstNode<'a>>(&'a self) -> Option<T>
Cast the last child that can cast to the AST type T
.
Sourcepub fn errors(&self) -> Vec<SyntaxError>
pub fn errors(&self) -> Vec<SyntaxError>
The error messages for this node and its descendants.
Sourcepub fn spanless_eq(&self, other: &Self) -> bool
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>
impl<'a> Clone for LinkedNode<'a>
Source§fn clone(&self) -> LinkedNode<'a>
fn clone(&self) -> LinkedNode<'a>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for LinkedNode<'_>
impl Debug for LinkedNode<'_>
Auto Trait Implementations§
impl<'a> Freeze for LinkedNode<'a>
impl<'a> RefUnwindSafe for LinkedNode<'a>
impl<'a> !Send for LinkedNode<'a>
impl<'a> !Sync for LinkedNode<'a>
impl<'a> Unpin for LinkedNode<'a>
impl<'a> UnwindSafe for LinkedNode<'a>
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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