From 911e32bca9b73e66eceb6bbee3768c82e94597d5 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Wed, 13 Feb 2019 20:53:42 +0100 Subject: Complete names from prelude --- crates/ra_hir/src/nameres.rs | 2 +- crates/ra_hir/src/resolve.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'crates/ra_hir') diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index cd7b41cff..e35b4b129 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs @@ -40,7 +40,7 @@ pub struct ItemMap { /// The prelude module for this crate. This either comes from an import /// marked with the `prelude_import` attribute, or (in the normal case) from /// a dependency (`std` or `core`). - prelude: Option, + pub(crate) prelude: Option, pub(crate) extern_prelude: FxHashMap, per_module: ArenaMap, } diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs index fde4d6580..91a531801 100644 --- a/crates/ra_hir/src/resolve.rs +++ b/crates/ra_hir/src/resolve.rs @@ -82,10 +82,10 @@ impl Resolver { } } - pub fn all_names(&self) -> FxHashMap> { + pub fn all_names(&self, db: &impl HirDatabase) -> FxHashMap> { let mut names = FxHashMap::default(); for scope in self.scopes.iter().rev() { - scope.collect_names(&mut |name, res| { + scope.collect_names(db, &mut |name, res| { let current: &mut PerNs = names.entry(name).or_default(); if current.types.is_none() { current.types = res.types; @@ -174,7 +174,7 @@ impl Scope { } } - fn collect_names(&self, f: &mut dyn FnMut(Name, PerNs)) { + fn collect_names(&self, db: &impl HirDatabase, f: &mut dyn FnMut(Name, PerNs)) { match self { Scope::ModuleScope(m) => { // TODO: should we provide `self` here? @@ -190,6 +190,12 @@ impl Scope { m.item_map.extern_prelude.iter().for_each(|(name, def)| { f(name.clone(), PerNs::types(Resolution::Def(*def))); }); + if let Some(prelude) = m.item_map.prelude { + let prelude_item_map = db.item_map(prelude.krate); + prelude_item_map[prelude.module_id].entries().for_each(|(name, res)| { + f(name.clone(), res.def.map(Resolution::Def)); + }); + } } Scope::GenericParams(gp) => { for param in &gp.params { -- cgit v1.2.3