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>
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>
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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