diff options
author | Aleksey Kladov <[email protected]> | 2018-09-07 23:35:20 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2018-09-07 23:35:20 +0100 |
commit | 127814d9a7f62c834c0893ff05e933aac4be89e9 (patch) | |
tree | 412432e0308c8b22b28e3b84776b44b311b283da /crates/libsyntax2/src/ast | |
parent | ff1c82216cc05f2621a301e30ab7a1102dea9d2b (diff) |
nested mod completion
Diffstat (limited to 'crates/libsyntax2/src/ast')
-rw-r--r-- | crates/libsyntax2/src/ast/generated.rs | 13 | ||||
-rw-r--r-- | crates/libsyntax2/src/ast/mod.rs | 24 |
2 files changed, 18 insertions, 19 deletions
diff --git a/crates/libsyntax2/src/ast/generated.rs b/crates/libsyntax2/src/ast/generated.rs index a239f0630..c945c094a 100644 --- a/crates/libsyntax2/src/ast/generated.rs +++ b/crates/libsyntax2/src/ast/generated.rs | |||
@@ -699,11 +699,8 @@ impl<'a> AstNode<'a> for ItemList<'a> { | |||
699 | } | 699 | } |
700 | 700 | ||
701 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} | 701 | impl<'a> ast::FnDefOwner<'a> for ItemList<'a> {} |
702 | impl<'a> ItemList<'a> { | 702 | impl<'a> ast::ModuleItemOwner<'a> for ItemList<'a> {} |
703 | pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a { | 703 | impl<'a> ItemList<'a> {} |
704 | super::children(self) | ||
705 | } | ||
706 | } | ||
707 | 704 | ||
708 | // Label | 705 | // Label |
709 | #[derive(Debug, Clone, Copy)] | 706 | #[derive(Debug, Clone, Copy)] |
@@ -979,7 +976,6 @@ impl<'a> AstNode<'a> for Module<'a> { | |||
979 | 976 | ||
980 | impl<'a> ast::NameOwner<'a> for Module<'a> {} | 977 | impl<'a> ast::NameOwner<'a> for Module<'a> {} |
981 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} | 978 | impl<'a> ast::AttrsOwner<'a> for Module<'a> {} |
982 | impl<'a> ast::FnDefOwner<'a> for Module<'a> {} | ||
983 | impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> { | 979 | impl<'a> Module<'a> {pub fn item_list(self) -> Option<ItemList<'a>> { |
984 | super::child_opt(self) | 980 | super::child_opt(self) |
985 | } | 981 | } |
@@ -1616,12 +1612,9 @@ impl<'a> AstNode<'a> for Root<'a> { | |||
1616 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } | 1612 | fn syntax(self) -> SyntaxNodeRef<'a> { self.syntax } |
1617 | } | 1613 | } |
1618 | 1614 | ||
1615 | impl<'a> ast::ModuleItemOwner<'a> for Root<'a> {} | ||
1619 | impl<'a> ast::FnDefOwner<'a> for Root<'a> {} | 1616 | impl<'a> ast::FnDefOwner<'a> for Root<'a> {} |
1620 | impl<'a> Root<'a> { | 1617 | impl<'a> Root<'a> { |
1621 | pub fn items(self) -> impl Iterator<Item = ModuleItem<'a>> + 'a { | ||
1622 | super::children(self) | ||
1623 | } | ||
1624 | |||
1625 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { | 1618 | pub fn modules(self) -> impl Iterator<Item = Module<'a>> + 'a { |
1626 | super::children(self) | 1619 | super::children(self) |
1627 | } | 1620 | } |
diff --git a/crates/libsyntax2/src/ast/mod.rs b/crates/libsyntax2/src/ast/mod.rs index 0b6868547..a6da82957 100644 --- a/crates/libsyntax2/src/ast/mod.rs +++ b/crates/libsyntax2/src/ast/mod.rs | |||
@@ -36,7 +36,13 @@ pub trait ArgListOwner<'a>: AstNode<'a> { | |||
36 | } | 36 | } |
37 | 37 | ||
38 | pub trait FnDefOwner<'a>: AstNode<'a> { | 38 | pub trait FnDefOwner<'a>: AstNode<'a> { |
39 | fn functions(self) -> AstNodeChildren<'a, FnDef<'a>> { | 39 | fn functions(self) -> AstChildren<'a, FnDef<'a>> { |
40 | children(self) | ||
41 | } | ||
42 | } | ||
43 | |||
44 | pub trait ModuleItemOwner<'a>: AstNode<'a> { | ||
45 | fn items(self) -> AstChildren<'a, ModuleItem<'a>> { | ||
40 | children(self) | 46 | children(self) |
41 | } | 47 | } |
42 | } | 48 | } |
@@ -52,7 +58,7 @@ pub trait TypeParamsOwner<'a>: AstNode<'a> { | |||
52 | } | 58 | } |
53 | 59 | ||
54 | pub trait AttrsOwner<'a>: AstNode<'a> { | 60 | pub trait AttrsOwner<'a>: AstNode<'a> { |
55 | fn attrs(self) -> AstNodeChildren<'a, Attr<'a>> { | 61 | fn attrs(self) -> AstChildren<'a, Attr<'a>> { |
56 | children(self) | 62 | children(self) |
57 | } | 63 | } |
58 | } | 64 | } |
@@ -158,7 +164,7 @@ impl<'a> IfExpr<'a> { | |||
158 | pub fn else_branch(self) -> Option<Block<'a>> { | 164 | pub fn else_branch(self) -> Option<Block<'a>> { |
159 | self.blocks().nth(1) | 165 | self.blocks().nth(1) |
160 | } | 166 | } |
161 | fn blocks(self) -> AstNodeChildren<'a, Block<'a>> { | 167 | fn blocks(self) -> AstChildren<'a, Block<'a>> { |
162 | children(self) | 168 | children(self) |
163 | } | 169 | } |
164 | } | 170 | } |
@@ -167,27 +173,27 @@ fn child_opt<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> Option<C> { | |||
167 | children(parent).next() | 173 | children(parent).next() |
168 | } | 174 | } |
169 | 175 | ||
170 | fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstNodeChildren<'a, C> { | 176 | fn children<'a, P: AstNode<'a>, C: AstNode<'a>>(parent: P) -> AstChildren<'a, C> { |
171 | AstNodeChildren::new(parent.syntax()) | 177 | AstChildren::new(parent.syntax()) |
172 | } | 178 | } |
173 | 179 | ||
174 | 180 | ||
175 | #[derive(Debug)] | 181 | #[derive(Debug)] |
176 | pub struct AstNodeChildren<'a, N> { | 182 | pub struct AstChildren<'a, N> { |
177 | inner: SyntaxNodeChildren<RefRoot<'a>>, | 183 | inner: SyntaxNodeChildren<RefRoot<'a>>, |
178 | ph: PhantomData<N>, | 184 | ph: PhantomData<N>, |
179 | } | 185 | } |
180 | 186 | ||
181 | impl<'a, N> AstNodeChildren<'a, N> { | 187 | impl<'a, N> AstChildren<'a, N> { |
182 | fn new(parent: SyntaxNodeRef<'a>) -> Self { | 188 | fn new(parent: SyntaxNodeRef<'a>) -> Self { |
183 | AstNodeChildren { | 189 | AstChildren { |
184 | inner: parent.children(), | 190 | inner: parent.children(), |
185 | ph: PhantomData, | 191 | ph: PhantomData, |
186 | } | 192 | } |
187 | } | 193 | } |
188 | } | 194 | } |
189 | 195 | ||
190 | impl<'a, N: AstNode<'a>> Iterator for AstNodeChildren<'a, N> { | 196 | impl<'a, N: AstNode<'a>> Iterator for AstChildren<'a, N> { |
191 | type Item = N; | 197 | type Item = N; |
192 | fn next(&mut self) -> Option<N> { | 198 | fn next(&mut self) -> Option<N> { |
193 | loop { | 199 | loop { |