Struct biome_formatter::comments::DecoratedComment
source · pub struct DecoratedComment<L: Language> { /* private fields */ }Expand description
A comment decorated with additional information about its surrounding context in the source document.
Used by CommentStyle::place_comment to determine if this should become a leading, dangling, or trailing comment.
Implementations§
source§impl<L: Language> DecoratedComment<L>
impl<L: Language> DecoratedComment<L>
sourcepub fn enclosing_node(&self) -> &SyntaxNode<L>
pub fn enclosing_node(&self) -> &SyntaxNode<L>
The closest parent node that fully encloses the comment.
A node encloses a comment when the comment is between two of its direct children (ignoring lists).
§Examples
[a, /* comment */ b]The enclosing node is the array expression and not the identifier b because
a and b are children of the array expression and comment is a comment between the two nodes.
sourcepub fn piece(&self) -> &SyntaxTriviaPieceComments<L>
pub fn piece(&self) -> &SyntaxTriviaPieceComments<L>
Returns the comment piece.
sourcepub fn preceding_node(&self) -> Option<&SyntaxNode<L>>
pub fn preceding_node(&self) -> Option<&SyntaxNode<L>>
Returns the node preceding the comment.
The direct child node (ignoring lists) of the enclosing_node that precedes this comment.
Returns None if the enclosing_node only consists of tokens or if
all preceding children of the enclosing_node have been tokens.
The Preceding node is guaranteed to be a sibling of following_node.
§Examples
§Preceding tokens only
[/* comment */]Returns None because the comment has no preceding node, only a preceding [ token.
§Preceding node
[a /* comment */, b]Returns Some(a) because a directly precedes the comment.
§Preceding token and node
[a, /* comment */]Returns Some(a) because a is the preceding node of comment. The presence of the , token
doesn’t change that.
sourcepub fn following_node(&self) -> Option<&SyntaxNode<L>>
pub fn following_node(&self) -> Option<&SyntaxNode<L>>
Returns the node following the comment.
The direct child node (ignoring lists) of the enclosing_node that follows this comment.
Returns None if the enclosing_node only consists of tokens or if
all children children of the enclosing_node following this comment are tokens.
The following node is guaranteed to be a sibling of preceding_node.
§Examples
§Following tokens only
[ /* comment */ ]Returns None because there’s no node following the comment, only the ] token.
§Following node
[ /* comment */ a ]Returns Some(a) because a is the node directly following the comment.
§Following token and node
async /* comment */ function test() {}Returns Some(test) because the test identifier is the first node following comment.
§Following parenthesized expression
!(
a /* comment */
);
bReturns None because comment is enclosed inside the parenthesized expression and it has no children
following `/* comment */.
sourcepub fn lines_before(&self) -> u32
pub fn lines_before(&self) -> u32
The number of line breaks between this comment and the previous token or comment.
§Examples
§Same line
a // end of lineReturns 0 because there’s no line break between the token a and the comment.
§Own Line
a;
/* comment */Returns 2 because there are two line breaks between the token a and the comment.
sourcepub fn lines_after(&self) -> u32
pub fn lines_after(&self) -> u32
sourcepub fn kind(&self) -> CommentKind
pub fn kind(&self) -> CommentKind
Returns the CommentKind of the comment.
sourcepub fn text_position(&self) -> CommentTextPosition
pub fn text_position(&self) -> CommentTextPosition
The position of the comment in the text.
sourcepub fn following_token(&self) -> Option<&SyntaxToken<L>>
pub fn following_token(&self) -> Option<&SyntaxToken<L>>
The next token that comes after this comment. It is possible that other comments are between this comment and the token.
a /* comment */ /* other */ bThe following_token for both comments is b because it’s the token coming after the comments.
Trait Implementations§
source§impl<L: Clone + Language> Clone for DecoratedComment<L>
impl<L: Clone + Language> Clone for DecoratedComment<L>
source§fn clone(&self) -> DecoratedComment<L>
fn clone(&self) -> DecoratedComment<L>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more