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 mode_after(&self) -> Option<SyntaxMode>
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.
Sourcepub fn parent_mode(&self) -> Option<SyntaxMode>
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.
impl LinkedNode<'_>
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 prev_sibling_with_trivia(&self) -> Option<Self>
pub fn prev_sibling_with_trivia(&self) -> Option<Self>
Get the first previous sibling node, including potential trivia.
Sourcepub fn next_sibling(&self) -> Option<Self>
pub fn next_sibling(&self) -> Option<Self>
Get the next non-trivia sibling node.
Sourcepub fn next_sibling_with_trivia(&self) -> Option<Self>
pub fn next_sibling_with_trivia(&self) -> Option<Self>
Get the next sibling node, including potential trivia.
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 LinkedNode<'_>
Access to leaves.
impl LinkedNode<'_>
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 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 kind(&self) -> SyntaxKind
pub fn kind(&self) -> SyntaxKind
The type of the node.
Sourcepub fn leaf_text(&self) -> &EcoString
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.
Sourcepub fn full_text(&self) -> EcoString
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.
Sourcepub fn children(&self) -> Iter<'_, SyntaxNode>
pub fn children(&self) -> Iter<'_, SyntaxNode>
The node’s children.
Sourcepub fn diagnosis(&self) -> Diagnosis
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.
Sourcepub fn errors_and_warnings(
&self,
) -> (Vec<SyntaxDiagnostic>, Vec<SyntaxDiagnostic>)
pub fn errors_and_warnings( &self, ) -> (Vec<SyntaxDiagnostic>, Vec<SyntaxDiagnostic>)
The error and warning diagnostics 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 (const: unstable) · 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> !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> 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