pub struct SyntaxNode { /* private fields */ }Expand description
A node in the untyped syntax tree.
Implementations§
Source§impl SyntaxNode
impl SyntaxNode
Source§impl SyntaxNode
impl SyntaxNode
Sourcepub fn leaf(kind: SyntaxKind, text: impl Into<EcoString>) -> Self
pub fn leaf(kind: SyntaxKind, text: impl Into<EcoString>) -> Self
Create a new leaf node.
Sourcepub fn inner(kind: SyntaxKind, children: Vec<SyntaxNode>) -> Self
pub fn inner(kind: SyntaxKind, children: Vec<SyntaxNode>) -> Self
Create a new inner node with children.
Sourcepub fn error(message: impl Into<EcoString>, text: impl Into<EcoString>) -> Self
pub fn error(message: impl Into<EcoString>, text: impl Into<EcoString>) -> Self
Create a new error node with a user-presentable message for the given text. Note that the message is the first argument, and the text causing the error is the second argument.
Sourcepub fn warn(&mut self, message: impl Into<EcoString>)
pub fn warn(&mut self, message: impl Into<EcoString>)
Add a warning message to an existing node.
Sourcepub fn warn_at(&mut self, _: Range<usize>, message: impl Into<EcoString>)
pub fn warn_at(&mut self, _: Range<usize>, message: impl Into<EcoString>)
Add a warning around this node at a particular sub-range of the node’s text. Panics if the range is empty or exceeds the length of the wrapped text.
Sourcepub fn hint(&mut self, hint: impl Into<EcoString>)
pub fn hint(&mut self, hint: impl Into<EcoString>)
Add a user-presentable hint to an existing error or warning. Panics if this is not an error or warning.
Sourcepub fn hint_at(&mut self, _: Range<usize>, hint: impl Into<EcoString>)
pub fn hint_at(&mut self, _: Range<usize>, hint: impl Into<EcoString>)
Add a user-presentable hint to an existing error or warning at a sub-range of the text. Panics if the range is empty or exceeds the length of the wrapped text. Panics if this is not an error or warning node.
Sourcepub fn with_hints(self, new_hints: impl IntoIterator<Item = EcoString>) -> Self
pub fn with_hints(self, new_hints: impl IntoIterator<Item = EcoString>) -> Self
Add multiple hints while building an error or warning. Panics if this is not an error or warning.
Sourcepub const fn placeholder(kind: SyntaxKind) -> Self
pub const fn placeholder(kind: SyntaxKind) -> Self
Create a dummy node of the given kind.
Panics if kind is SyntaxKind::Error.
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 synthesize(&mut self, span: Span)
pub fn synthesize(&mut self, span: Span)
Set a synthetic span for the node and all its descendants.
Sourcepub fn synthesize_mapped(
&mut self,
id: FileId,
mapper: &RangeMapper,
) -> Result<(), EcoString>
pub fn synthesize_mapped( &mut self, id: FileId, mapper: &RangeMapper, ) -> Result<(), EcoString>
Set a raw range span for each node.
The range is determined by mapping the node’s ranges through the given
mapper.
Returns an error with the mapper’s length if it was shorter than the length of the source text.
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 Clone for SyntaxNode
impl Clone for SyntaxNode
Source§fn clone(&self) -> SyntaxNode
fn clone(&self) -> SyntaxNode
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 SyntaxNode
impl Debug for SyntaxNode
Source§impl Default for SyntaxNode
impl Default for SyntaxNode
impl Eq for SyntaxNode
Source§impl Hash for SyntaxNode
impl Hash for SyntaxNode
Source§impl PartialEq for SyntaxNode
impl PartialEq for SyntaxNode
Source§fn eq(&self, other: &SyntaxNode) -> bool
fn eq(&self, other: &SyntaxNode) -> bool
self and other values to be equal, and is used by ==.impl StructuralPartialEq for SyntaxNode
Auto Trait Implementations§
impl Freeze for SyntaxNode
impl RefUnwindSafe for SyntaxNode
impl Send for SyntaxNode
impl Sync for SyntaxNode
impl Unpin for SyntaxNode
impl UnsafeUnpin for SyntaxNode
impl UnwindSafe for SyntaxNode
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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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