From b93c6bc5575db4acc5aa5867b6f0cc0dd37858f4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 18 Jan 2019 14:50:04 +0300 Subject: simplify --- crates/ra_hir/src/nameres/lower.rs | 84 +++++++++++++++++++++++--------------- 1 file changed, 52 insertions(+), 32 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/nameres/lower.rs b/crates/ra_hir/src/nameres/lower.rs index dd3bf245f..35bdbafbf 100644 --- a/crates/ra_hir/src/nameres/lower.rs +++ b/crates/ra_hir/src/nameres/lower.rs @@ -33,48 +33,68 @@ impl InputModuleItems { let source = module_id.source(&module_tree); let file_id = source.file_id; let source = ModuleSource::from_source_item_id(db, source); - let file_items = db.file_items(file_id); - let fill = |acc: &mut InputModuleItems, items: &mut Iterator| { - for item in items { - match item { - ast::ItemOrMacro::Item(it) => { - acc.add_item(file_id, &file_items, it); - } - ast::ItemOrMacro::Macro(macro_call) => { - let item_id = file_items.id_of_unchecked(macro_call.syntax()); - let loc = MacroCallLoc { - source_root_id, - module_id, - source_item_id: SourceItemId { - file_id, - item_id: Some(item_id), - }, - }; - let id = loc.id(db); - let file_id = HirFileId::from(id); - let file_items = db.file_items(file_id); - //FIXME: expand recursively - for item in db.hir_source_file(file_id).items() { - acc.add_item(file_id, &file_items, item); - } - } - } - } - }; - let mut res = InputModuleItems::default(); match source { - ModuleSource::SourceFile(it) => fill(&mut res, &mut it.items_with_macros()), + ModuleSource::SourceFile(it) => res.fill( + db, + source_root_id, + module_id, + file_id, + &mut it.items_with_macros(), + ), ModuleSource::Module(it) => { if let Some(item_list) = it.item_list() { - fill(&mut res, &mut item_list.items_with_macros()) + res.fill( + db, + source_root_id, + module_id, + file_id, + &mut item_list.items_with_macros(), + ) } } }; Arc::new(res) } - pub(crate) fn add_item( + fn fill( + &mut self, + db: &impl HirDatabase, + source_root_id: SourceRootId, + module_id: ModuleId, + file_id: HirFileId, + items: &mut Iterator, + ) { + let file_items = db.file_items(file_id); + + for item in items { + match item { + ast::ItemOrMacro::Item(it) => { + self.add_item(file_id, &file_items, it); + } + ast::ItemOrMacro::Macro(macro_call) => { + let item_id = file_items.id_of_unchecked(macro_call.syntax()); + let loc = MacroCallLoc { + source_root_id, + module_id, + source_item_id: SourceItemId { + file_id, + item_id: Some(item_id), + }, + }; + let id = loc.id(db); + let file_id = HirFileId::from(id); + let file_items = db.file_items(file_id); + //FIXME: expand recursively + for item in db.hir_source_file(file_id).items() { + self.add_item(file_id, &file_items, item); + } + } + } + } + } + + fn add_item( &mut self, file_id: HirFileId, file_items: &SourceFileItems, -- cgit v1.2.3