pub struct SyntaxNode(/* private fields */);
Expand description
SyntaxNode. Untyped view of the syntax tree. Adds parent() and offset() capabilities.
Implementations§
Source§impl SyntaxNode
impl SyntaxNode
pub fn new_root(db: &dyn SyntaxGroup, file_id: FileId, green: GreenId) -> Self
pub fn offset(&self) -> TextOffset
pub fn width(&self, db: &dyn SyntaxGroup) -> TextWidth
pub fn kind(&self, db: &dyn SyntaxGroup) -> SyntaxKind
pub fn span(&self, db: &dyn SyntaxGroup) -> TextSpan
Sourcepub fn text(&self, db: &dyn SyntaxGroup) -> Option<SmolStr>
pub fn text(&self, db: &dyn SyntaxGroup) -> Option<SmolStr>
Returns the text of the token if this node is a token.
pub fn green_node(&self, db: &dyn SyntaxGroup) -> Arc<GreenNode>
pub fn span_without_trivia(&self, db: &dyn SyntaxGroup) -> TextSpan
pub fn parent(&self) -> Option<SyntaxNode>
Sourcepub fn position_in_parent(&self, db: &dyn SyntaxGroup) -> Option<usize>
pub fn position_in_parent(&self, db: &dyn SyntaxGroup) -> Option<usize>
Returns the position of a syntax node in its parent’s children, or None if the node has no parent.
pub fn stable_ptr(&self) -> SyntaxStablePtrId
Sourcepub fn get_terminal_token(&self, db: &dyn SyntaxGroup) -> Option<SyntaxNode>
pub fn get_terminal_token(&self, db: &dyn SyntaxGroup) -> Option<SyntaxNode>
Gets the inner token from a terminal SyntaxNode. If the given node is not a terminal, returns None.
pub fn span_start_without_trivia(&self, db: &dyn SyntaxGroup) -> TextOffset
pub fn span_end_without_trivia(&self, db: &dyn SyntaxGroup) -> TextOffset
Sourcepub fn lookup_offset(
&self,
db: &dyn SyntaxGroup,
offset: TextOffset,
) -> SyntaxNode
pub fn lookup_offset( &self, db: &dyn SyntaxGroup, offset: TextOffset, ) -> SyntaxNode
Lookups a syntax node using an offset.
Sourcepub fn lookup_position(
&self,
db: &dyn SyntaxGroup,
position: TextPosition,
) -> SyntaxNode
pub fn lookup_position( &self, db: &dyn SyntaxGroup, position: TextPosition, ) -> SyntaxNode
Lookups a syntax node using a position.
Sourcepub fn get_text(&self, db: &dyn SyntaxGroup) -> String
pub fn get_text(&self, db: &dyn SyntaxGroup) -> String
Returns all the text under the syntax node. Note that this traverses the syntax tree, and generates a new string, so use responsibly.
Sourcepub fn get_text_without_trivia(self, db: &dyn SyntaxGroup) -> String
pub fn get_text_without_trivia(self, db: &dyn SyntaxGroup) -> String
Returns all the text under the syntax node, without the outmost trivia (the leading trivia of the first token and the trailing trivia of the last token).
Note that this traverses the syntax tree, and generates a new string, so use responsibly.
Sourcepub fn get_text_of_span(self, db: &dyn SyntaxGroup, span: TextSpan) -> String
pub fn get_text_of_span(self, db: &dyn SyntaxGroup, span: TextSpan) -> String
Returns the text under the syntax node, according to the given span.
span
is assumed to be contained within the span of self.
Note that this traverses the syntax tree, and generates a new string, so use responsibly.
Sourcepub fn descendants<'db>(
&self,
db: &'db dyn SyntaxGroup,
) -> impl Iterator<Item = SyntaxNode> + 'db
pub fn descendants<'db>( &self, db: &'db dyn SyntaxGroup, ) -> impl Iterator<Item = SyntaxNode> + 'db
Traverse the subtree rooted at the current node (including the current node) in preorder.
This is a shortcut for Self::preorder
paired with filtering for WalkEvent::Enter
events only.
Sourcepub fn preorder<'db>(&self, db: &'db dyn SyntaxGroup) -> Preorder<'db> ⓘ
pub fn preorder<'db>(&self, db: &'db dyn SyntaxGroup) -> Preorder<'db> ⓘ
Traverse the subtree rooted at the current node (including the current node) in preorder, excluding tokens.
Trait Implementations§
Source§impl Clone for SyntaxNode
impl Clone for SyntaxNode
Source§fn clone(&self) -> SyntaxNode
fn clone(&self) -> SyntaxNode
1.0.0 · 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 Hash for SyntaxNode
impl Hash for SyntaxNode
Source§impl PartialEq for SyntaxNode
impl PartialEq for SyntaxNode
Source§impl QueryAttrs for SyntaxNode
impl QueryAttrs for SyntaxNode
Allows querying attributes of a syntax node, any typed node which QueryAttrs is implemented for should be added here.
Source§fn query_attr(&self, db: &dyn SyntaxGroup, attr: &str) -> Vec<Attribute>
fn query_attr(&self, db: &dyn SyntaxGroup, attr: &str) -> Vec<Attribute>
attr
attached to this node.Source§fn find_attr(&self, db: &dyn SyntaxGroup, attr: &str) -> Option<Attribute>
fn find_attr(&self, db: &dyn SyntaxGroup, attr: &str) -> Option<Attribute>
attr
attached do this node.Source§fn has_attr(&self, db: &dyn SyntaxGroup, attr: &str) -> bool
fn has_attr(&self, db: &dyn SyntaxGroup, attr: &str) -> bool
attr
.Source§fn has_attr_with_arg(
&self,
db: &dyn SyntaxGroup,
attr_name: &str,
arg_name: &str,
) -> bool
fn has_attr_with_arg( &self, db: &dyn SyntaxGroup, attr_name: &str, arg_name: &str, ) -> bool
impl Eq for SyntaxNode
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 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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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