From 2e1d739a8063307facf9ff098c26b02005092e05 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 10 Feb 2019 15:41:44 +0100 Subject: Import glob imports from other crates This is the easy part since we don't have to consider the fixpoint algorithm. --- crates/ra_hir/src/marks.rs | 1 + crates/ra_hir/src/nameres.rs | 17 +++++++++++++++-- crates/ra_hir/src/nameres/tests.rs | 1 + 3 files changed, 17 insertions(+), 2 deletions(-) (limited to 'crates') diff --git a/crates/ra_hir/src/marks.rs b/crates/ra_hir/src/marks.rs index 5732eeccf..50d4e824c 100644 --- a/crates/ra_hir/src/marks.rs +++ b/crates/ra_hir/src/marks.rs @@ -5,4 +5,5 @@ test_utils::marks!( type_var_cycles_resolve_as_possible type_var_resolves_to_int_var glob_enum + glob_across_crates ); diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index 0b6ab1211..2442e754e 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -276,12 +276,25 @@ where log::debug!("glob import: {:?}", import); match def.take_types() { Some(ModuleDef::Module(m)) => { - // TODO + if m.krate != self.krate { + tested_by!(glob_across_crates); + // glob import from other crate => we can just import everything once + let item_map = self.db.item_map(m.krate); + let scope = &item_map[m.module_id]; + self.update(module_id, |items| { + // TODO: handle shadowing and visibility + items.items.extend( + scope.items.iter().map(|(name, res)| (name.clone(), res.clone())), + ); + }); + } } Some(ModuleDef::Enum(e)) => { tested_by!(glob_enum); + // glob import from enum => just import all the variants let variants = e.variants(self.db); - let resolutions = variants.into_iter() + let resolutions = variants + .into_iter() .filter_map(|variant| { let res = Resolution { def: PerNs::both(variant.into(), e.into()), diff --git a/crates/ra_hir/src/nameres/tests.rs b/crates/ra_hir/src/nameres/tests.rs index 91566fc98..9c0e4ef29 100644 --- a/crates/ra_hir/src/nameres/tests.rs +++ b/crates/ra_hir/src/nameres/tests.rs @@ -251,6 +251,7 @@ fn glob_enum() { #[test] fn glob_across_crates() { + covers!(glob_across_crates); let (mut db, sr) = MockDatabase::with_files( " //- /main.rs -- cgit v1.2.3