diff options
Diffstat (limited to 'crates/ra_hir_def/src/resolver.rs')
-rw-r--r-- | crates/ra_hir_def/src/resolver.rs | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/crates/ra_hir_def/src/resolver.rs b/crates/ra_hir_def/src/resolver.rs index cf3c33d78..5d16dd087 100644 --- a/crates/ra_hir_def/src/resolver.rs +++ b/crates/ra_hir_def/src/resolver.rs | |||
@@ -19,6 +19,7 @@ use crate::{ | |||
19 | nameres::CrateDefMap, | 19 | nameres::CrateDefMap, |
20 | path::{ModPath, PathKind}, | 20 | path::{ModPath, PathKind}, |
21 | per_ns::PerNs, | 21 | per_ns::PerNs, |
22 | visibility::{RawVisibility, Visibility}, | ||
22 | AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, | 23 | AdtId, AssocContainerId, ConstId, ContainerId, DefWithBodyId, EnumId, EnumVariantId, |
23 | FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, | 24 | FunctionId, GenericDefId, HasModule, ImplId, LocalModuleId, Lookup, ModuleDefId, ModuleId, |
24 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, | 25 | StaticId, StructId, TraitId, TypeAliasId, TypeParamId, VariantId, |
@@ -231,6 +232,23 @@ impl Resolver { | |||
231 | Some(res) | 232 | Some(res) |
232 | } | 233 | } |
233 | 234 | ||
235 | pub fn resolve_visibility( | ||
236 | &self, | ||
237 | db: &impl DefDatabase, | ||
238 | visibility: &RawVisibility, | ||
239 | ) -> Option<Visibility> { | ||
240 | match visibility { | ||
241 | RawVisibility::Module(_) => { | ||
242 | let (item_map, module) = match self.module() { | ||
243 | Some(it) => it, | ||
244 | None => return None, | ||
245 | }; | ||
246 | item_map.resolve_visibility(db, module, visibility) | ||
247 | } | ||
248 | RawVisibility::Public => Some(Visibility::Public), | ||
249 | } | ||
250 | } | ||
251 | |||
234 | pub fn resolve_path_in_value_ns( | 252 | pub fn resolve_path_in_value_ns( |
235 | &self, | 253 | &self, |
236 | db: &impl DefDatabase, | 254 | db: &impl DefDatabase, |
@@ -448,10 +466,10 @@ impl Scope { | |||
448 | f(name.clone(), ScopeDef::PerNs(def)); | 466 | f(name.clone(), ScopeDef::PerNs(def)); |
449 | }); | 467 | }); |
450 | m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { | 468 | m.crate_def_map[m.module_id].scope.legacy_macros().for_each(|(name, macro_)| { |
451 | f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_))); | 469 | f(name.clone(), ScopeDef::PerNs(PerNs::macros(macro_, Visibility::Public))); |
452 | }); | 470 | }); |
453 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { | 471 | m.crate_def_map.extern_prelude.iter().for_each(|(name, &def)| { |
454 | f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into()))); | 472 | f(name.clone(), ScopeDef::PerNs(PerNs::types(def.into(), Visibility::Public))); |
455 | }); | 473 | }); |
456 | if let Some(prelude) = m.crate_def_map.prelude { | 474 | if let Some(prelude) = m.crate_def_map.prelude { |
457 | let prelude_def_map = db.crate_def_map(prelude.krate); | 475 | let prelude_def_map = db.crate_def_map(prelude.krate); |
@@ -626,7 +644,7 @@ impl HasResolver for ContainerId { | |||
626 | fn resolver(self, db: &impl DefDatabase) -> Resolver { | 644 | fn resolver(self, db: &impl DefDatabase) -> Resolver { |
627 | match self { | 645 | match self { |
628 | ContainerId::ModuleId(it) => it.resolver(db), | 646 | ContainerId::ModuleId(it) => it.resolver(db), |
629 | ContainerId::DefWithBodyId(it) => it.resolver(db), | 647 | ContainerId::DefWithBodyId(it) => it.module(db).resolver(db), |
630 | } | 648 | } |
631 | } | 649 | } |
632 | } | 650 | } |