mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-26 11:59:49 +00:00
Generate AnyHasDocComments
node
This commit is contained in:
parent
2fb6f5e46a
commit
69dbfc7754
6 changed files with 95 additions and 21 deletions
|
@ -1,10 +1,12 @@
|
|||
//! Various traits that are implemented by ast nodes.
|
||||
//!
|
||||
//! The implementations are usually trivial, and live in generated.rs
|
||||
use itertools::Either;
|
||||
|
||||
use crate::{
|
||||
ast::{self, support, AstChildren, AstNode, AstToken},
|
||||
syntax_node::SyntaxElementChildren,
|
||||
SyntaxToken, T,
|
||||
SyntaxElement, SyntaxToken, T,
|
||||
};
|
||||
|
||||
pub trait HasName: AstNode {
|
||||
|
@ -74,6 +76,9 @@ pub trait HasDocComments: HasAttrs {
|
|||
fn doc_comments(&self) -> CommentIter {
|
||||
CommentIter { iter: self.syntax().children_with_tokens() }
|
||||
}
|
||||
fn doc_comments_and_attrs(&self) -> AttrCommentIter {
|
||||
AttrCommentIter { iter: self.syntax().children_with_tokens() }
|
||||
}
|
||||
}
|
||||
|
||||
impl CommentIter {
|
||||
|
@ -105,3 +110,17 @@ impl Iterator for CommentIter {
|
|||
self.iter.by_ref().find_map(|el| el.into_token().and_then(ast::Comment::cast))
|
||||
}
|
||||
}
|
||||
|
||||
pub struct AttrCommentIter {
|
||||
iter: SyntaxElementChildren,
|
||||
}
|
||||
|
||||
impl Iterator for AttrCommentIter {
|
||||
type Item = Either<ast::Comment, ast::Attr>;
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.by_ref().find_map(|el| match el {
|
||||
SyntaxElement::Node(node) => ast::Attr::cast(node).map(Either::Right),
|
||||
SyntaxElement::Token(tok) => ast::Comment::cast(tok).map(Either::Left),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue