diff options
author | Florian Diebold <[email protected]> | 2019-02-10 14:41:44 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-02-10 15:20:01 +0000 |
commit | 2e1d739a8063307facf9ff098c26b02005092e05 (patch) | |
tree | 0a31bfcd8cae51b157893c516115acbe454d3ee5 /crates | |
parent | c1e295682ec23b7f9923cda07fc28d99c987f327 (diff) |
Import glob imports from other crates
This is the easy part since we don't have to consider the fixpoint algorithm.
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/marks.rs | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 17 | ||||
-rw-r--r-- | crates/ra_hir/src/nameres/tests.rs | 1 |
3 files changed, 17 insertions, 2 deletions
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!( | |||
5 | type_var_cycles_resolve_as_possible | 5 | type_var_cycles_resolve_as_possible |
6 | type_var_resolves_to_int_var | 6 | type_var_resolves_to_int_var |
7 | glob_enum | 7 | glob_enum |
8 | glob_across_crates | ||
8 | ); | 9 | ); |
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 | |||
276 | log::debug!("glob import: {:?}", import); | 276 | log::debug!("glob import: {:?}", import); |
277 | match def.take_types() { | 277 | match def.take_types() { |
278 | Some(ModuleDef::Module(m)) => { | 278 | Some(ModuleDef::Module(m)) => { |
279 | // TODO | 279 | if m.krate != self.krate { |
280 | tested_by!(glob_across_crates); | ||
281 | // glob import from other crate => we can just import everything once | ||
282 | let item_map = self.db.item_map(m.krate); | ||
283 | let scope = &item_map[m.module_id]; | ||
284 | self.update(module_id, |items| { | ||
285 | // TODO: handle shadowing and visibility | ||
286 | items.items.extend( | ||
287 | scope.items.iter().map(|(name, res)| (name.clone(), res.clone())), | ||
288 | ); | ||
289 | }); | ||
290 | } | ||
280 | } | 291 | } |
281 | Some(ModuleDef::Enum(e)) => { | 292 | Some(ModuleDef::Enum(e)) => { |
282 | tested_by!(glob_enum); | 293 | tested_by!(glob_enum); |
294 | // glob import from enum => just import all the variants | ||
283 | let variants = e.variants(self.db); | 295 | let variants = e.variants(self.db); |
284 | let resolutions = variants.into_iter() | 296 | let resolutions = variants |
297 | .into_iter() | ||
285 | .filter_map(|variant| { | 298 | .filter_map(|variant| { |
286 | let res = Resolution { | 299 | let res = Resolution { |
287 | def: PerNs::both(variant.into(), e.into()), | 300 | 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() { | |||
251 | 251 | ||
252 | #[test] | 252 | #[test] |
253 | fn glob_across_crates() { | 253 | fn glob_across_crates() { |
254 | covers!(glob_across_crates); | ||
254 | let (mut db, sr) = MockDatabase::with_files( | 255 | let (mut db, sr) = MockDatabase::with_files( |
255 | " | 256 | " |
256 | //- /main.rs | 257 | //- /main.rs |