diff options
Diffstat (limited to 'crates/ra_syntax/src/ast/traits.rs')
-rw-r--r-- | crates/ra_syntax/src/ast/traits.rs | 32 |
1 files changed, 16 insertions, 16 deletions
diff --git a/crates/ra_syntax/src/ast/traits.rs b/crates/ra_syntax/src/ast/traits.rs index 576378306..e6f3a4ebb 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::{ | 7 | use crate::ast::{ |
8 | ast::{self, child_opt, children, AstChildren, AstNode, AstToken}, | 8 | self, child_elements, child_opt, child_token_opt, child_tokens, children, AstChildElements, |
9 | syntax_node::SyntaxElementChildren, | 9 | AstChildTokens, AstChildren, AstNode, AstToken, |
10 | }; | 10 | }; |
11 | 11 | ||
12 | pub trait TypeAscriptionOwner: AstNode { | 12 | pub trait TypeAscriptionOwner: AstNode { |
@@ -31,6 +31,10 @@ pub trait LoopBodyOwner: AstNode { | |||
31 | fn loop_body(&self) -> Option<ast::BlockExpr> { | 31 | fn loop_body(&self) -> Option<ast::BlockExpr> { |
32 | child_opt(self) | 32 | child_opt(self) |
33 | } | 33 | } |
34 | |||
35 | fn label(&self) -> Option<ast::Label> { | ||
36 | child_opt(self) | ||
37 | } | ||
34 | } | 38 | } |
35 | 39 | ||
36 | pub trait ArgListOwner: AstNode { | 40 | pub trait ArgListOwner: AstNode { |
@@ -65,6 +69,10 @@ pub trait TypeBoundsOwner: AstNode { | |||
65 | fn type_bound_list(&self) -> Option<ast::TypeBoundList> { | 69 | fn type_bound_list(&self) -> Option<ast::TypeBoundList> { |
66 | child_opt(self) | 70 | child_opt(self) |
67 | } | 71 | } |
72 | |||
73 | fn colon(&self) -> Option<ast::Colon> { | ||
74 | child_token_opt(self) | ||
75 | } | ||
68 | } | 76 | } |
69 | 77 | ||
70 | pub trait AttrsOwner: AstNode { | 78 | pub trait AttrsOwner: AstNode { |
@@ -74,11 +82,14 @@ pub trait AttrsOwner: AstNode { | |||
74 | fn has_atom_attr(&self, atom: &str) -> bool { | 82 | fn has_atom_attr(&self, atom: &str) -> bool { |
75 | 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) |
76 | } | 84 | } |
85 | fn attr_or_comments(&self) -> AstChildElements<ast::AttrOrComment> { | ||
86 | child_elements(self) | ||
87 | } | ||
77 | } | 88 | } |
78 | 89 | ||
79 | pub trait DocCommentsOwner: AstNode { | 90 | pub trait DocCommentsOwner: AstNode { |
80 | fn doc_comments(&self) -> CommentIter { | 91 | fn doc_comments(&self) -> AstChildTokens<ast::Comment> { |
81 | CommentIter { iter: self.syntax().children_with_tokens() } | 92 | child_tokens(self) |
82 | } | 93 | } |
83 | 94 | ||
84 | /// Returns the textual content of a doc comment block as a single string. | 95 | /// Returns the textual content of a doc comment block as a single string. |
@@ -123,14 +134,3 @@ pub trait DocCommentsOwner: AstNode { | |||
123 | } | 134 | } |
124 | } | 135 | } |
125 | } | 136 | } |
126 | |||
127 | pub struct CommentIter { | ||
128 | iter: SyntaxElementChildren, | ||
129 | } | ||
130 | |||
131 | impl Iterator for CommentIter { | ||
132 | type Item = ast::Comment; | ||
133 | fn next(&mut self) -> Option<ast::Comment> { | ||
134 | self.iter.by_ref().find_map(|el| el.into_token().and_then(ast::Comment::cast)) | ||
135 | } | ||
136 | } | ||