diff options
-rw-r--r-- | crates/ra_hir/src/module_tree.rs | 44 |
1 files changed, 20 insertions, 24 deletions
diff --git a/crates/ra_hir/src/module_tree.rs b/crates/ra_hir/src/module_tree.rs index c9a15967c..dd3aa6d73 100644 --- a/crates/ra_hir/src/module_tree.rs +++ b/crates/ra_hir/src/module_tree.rs | |||
@@ -62,14 +62,26 @@ impl Submodule { | |||
62 | file_items: &SourceFileItems, | 62 | file_items: &SourceFileItems, |
63 | root: &impl ast::ModuleItemOwner, | 63 | root: &impl ast::ModuleItemOwner, |
64 | ) -> Vec<Submodule> { | 64 | ) -> Vec<Submodule> { |
65 | modules(root) | 65 | root.items() |
66 | .map(|(name, m)| Submodule { | 66 | .filter_map(|item| match item.kind() { |
67 | name, | 67 | ast::ModuleItemKind::Module(m) => Some(m), |
68 | is_declaration: m.has_semi(), | 68 | _ => None, |
69 | source: SourceItemId { | 69 | }) |
70 | file_id, | 70 | .filter_map(|module| { |
71 | item_id: Some(file_items.id_of(file_id, m.syntax())), | 71 | let name = module.name()?.as_name(); |
72 | }, | 72 | if !module.has_semi() && module.item_list().is_none() { |
73 | tested_by!(name_res_works_for_broken_modules); | ||
74 | return None; | ||
75 | } | ||
76 | let sub = Submodule { | ||
77 | name, | ||
78 | is_declaration: module.has_semi(), | ||
79 | source: SourceItemId { | ||
80 | file_id, | ||
81 | item_id: Some(file_items.id_of(file_id, module.syntax())), | ||
82 | }, | ||
83 | }; | ||
84 | Some(sub) | ||
73 | }) | 85 | }) |
74 | .collect() | 86 | .collect() |
75 | } | 87 | } |
@@ -209,22 +221,6 @@ impl LinkId { | |||
209 | } | 221 | } |
210 | } | 222 | } |
211 | 223 | ||
212 | fn modules(root: &impl ast::ModuleItemOwner) -> impl Iterator<Item = (Name, &ast::Module)> { | ||
213 | root.items() | ||
214 | .filter_map(|item| match item.kind() { | ||
215 | ast::ModuleItemKind::Module(m) => Some(m), | ||
216 | _ => None, | ||
217 | }) | ||
218 | .filter_map(|module| { | ||
219 | let name = module.name()?.as_name(); | ||
220 | if !module.has_semi() && module.item_list().is_none() { | ||
221 | tested_by!(name_res_works_for_broken_modules); | ||
222 | return None; | ||
223 | } | ||
224 | Some((name, module)) | ||
225 | }) | ||
226 | } | ||
227 | |||
228 | fn create_module_tree<'a>(db: &impl HirDatabase, source_root: SourceRootId) -> ModuleTree { | 224 | fn create_module_tree<'a>(db: &impl HirDatabase, source_root: SourceRootId) -> ModuleTree { |
229 | let mut tree = ModuleTree::default(); | 225 | let mut tree = ModuleTree::default(); |
230 | 226 | ||