aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-23 14:57:41 +0000
committerAleksey Kladov <[email protected]>2019-01-23 14:57:41 +0000
commit343852d8b24a199b4f2ad4e1149214724b4526db (patch)
treea187da1781d5e10e56d4d7183103feb4cd2712f9 /crates
parentd853e9b1ef54be586d8e5b0c43519b5f74e090ef (diff)
simiplify
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/src/module_tree.rs44
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
212fn 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
228fn create_module_tree<'a>(db: &impl HirDatabase, source_root: SourceRootId) -> ModuleTree { 224fn 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