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_inner_commentable_children(
&self,
db: &dyn SyntaxGroup,
) -> String
pub fn get_text_without_inner_commentable_children( &self, db: &dyn SyntaxGroup, ) -> String
Returns all the text under the syntax node. It traverses all the syntax tree of the node, but ignores functions and modules. We ignore those, because if there’s some inner functions or modules, we don’t want to get raw text of them. Comments inside them refer themselves directly, not this SyntaxNode.
sourcepub fn get_text_without_all_comment_trivia(
&self,
db: &dyn SyntaxGroup,
) -> String
pub fn get_text_without_all_comment_trivia( &self, db: &dyn SyntaxGroup, ) -> String
Returns all the text of the item without comments trivia. It traverses all the syntax tree of the node.
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.
sourcepub fn tokens<'a>(
&'a self,
db: &'a dyn SyntaxGroup,
) -> impl Iterator<Item = Self> + 'a
pub fn tokens<'a>( &'a self, db: &'a dyn SyntaxGroup, ) -> impl Iterator<Item = Self> + 'a
Gets all the leaves of the SyntaxTree, where the self node is the root of a tree.
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§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)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