diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/traits.rs | 26 |
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 | ||
5 | use itertools::Itertools; | 5 | use itertools::Itertools; |
6 | 6 | ||
7 | use crate::ast::{ | 7 | use 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 | ||
12 | pub trait TypeAscriptionOwner: AstNode { | 12 | pub 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 | ||
90 | pub trait DocCommentsOwner: AstNode { | 87 | pub 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 | |||
135 | pub struct CommentIter { | ||
136 | iter: SyntaxElementChildren, | ||
137 | } | ||
138 | |||
139 | impl 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 | } | ||