aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/traits.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r--crates/ra_syntax/src/ast/traits.rs26
1 files changed, 17 insertions, 9 deletions
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs
index e6f3a4ebb..870e83804 100644
--- a/crates/ra_syntax/src/ast/traits.rs
+++ b/crates/ra_syntax/src/ast/traits.rs
@@ -4,9 +4,9 @@
4 4
5use itertools::Itertools; 5use itertools::Itertools;
6 6
7use crate::ast::{ 7use crate::{
8 self, child_elements, child_opt, child_token_opt, child_tokens, children, AstChildElements, 8 ast::{self, child_opt, children, support, AstChildren, AstNode, AstToken},
9 AstChildTokens, AstChildren, AstNode, AstToken, 9 syntax_node::SyntaxElementChildren,
10}; 10};
11 11
12pub trait TypeAscriptionOwner: AstNode { 12pub trait TypeAscriptionOwner: AstNode {
@@ -71,7 +71,7 @@ pub trait TypeBoundsOwner: AstNode {
71 } 71 }
72 72
73 fn colon(&self) -> Option<ast::Colon> { 73 fn colon(&self) -> Option<ast::Colon> {
74 child_token_opt(self) 74 support::token(self.syntax())
75 } 75 }
76} 76}
77 77
@@ -82,14 +82,11 @@ pub trait AttrsOwner: AstNode {
82 fn has_atom_attr(&self, atom: &str) -> bool { 82 fn has_atom_attr(&self, atom: &str) -> bool {
83 self.attrs().filter_map(|x| x.as_simple_atom()).any(|x| x == atom) 83 self.attrs().filter_map(|x| x.as_simple_atom()).any(|x| x == atom)
84 } 84 }
85 fn attr_or_comments(&self) -> AstChildElements<ast::AttrOrComment> {
86 child_elements(self)
87 }
88} 85}
89 86
90pub trait DocCommentsOwner: AstNode { 87pub trait DocCommentsOwner: AstNode {
91 fn doc_comments(&self) -> AstChildTokens<ast::Comment> { 88 fn doc_comments(&self) -> CommentIter {
92 child_tokens(self) 89 CommentIter { iter: self.syntax().children_with_tokens() }
93 } 90 }
94 91
95 /// Returns the textual content of a doc comment block as a single string. 92 /// Returns the textual content of a doc comment block as a single string.
@@ -134,3 +131,14 @@ pub trait DocCommentsOwner: AstNode {
134 } 131 }
135 } 132 }
136} 133}
134
135pub struct CommentIter {
136 iter: SyntaxElementChildren,
137}
138
139impl Iterator for CommentIter {
140 type Item = ast::Comment;
141 fn next(&mut self) -> Option<ast::Comment> {
142 self.iter.by_ref().find_map(|el| el.into_token().and_then(ast::Comment::cast))
143 }
144}