From 2c60f42825e68d8133854d378d9550139c71d9b4 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 22 Dec 2019 15:21:48 +0100 Subject: Separate defs from imports --- crates/ra_hir_def/src/item_scope.rs | 11 ++++++----- crates/ra_hir_def/src/nameres/collector.rs | 2 ++ 2 files changed, 8 insertions(+), 5 deletions(-) (limited to 'crates/ra_hir_def') diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index a96b5cfd2..b5c07ed5f 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs @@ -10,6 +10,7 @@ use crate::{per_ns::PerNs, AdtId, BuiltinType, ImplId, MacroDefId, ModuleDefId, #[derive(Debug, Default, PartialEq, Eq)] pub struct ItemScope { visible: FxHashMap, + defs: Vec, impls: Vec, /// Macros visible in current module in legacy textual scope /// @@ -53,11 +54,7 @@ impl ItemScope { } pub fn declarations(&self) -> impl Iterator + '_ { - self.entries() - .filter_map(|(_name, res)| if !res.import { Some(res.def) } else { None }) - .flat_map(|per_ns| { - per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) - }) + self.defs.iter().copied() } pub fn impls(&self) -> impl Iterator + ExactSizeIterator + '_ { @@ -100,6 +97,10 @@ impl ItemScope { }) } + pub(crate) fn define_def(&mut self, def: ModuleDefId) { + self.defs.push(def) + } + pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option { self.legacy_macros.get(name).copied() } diff --git a/crates/ra_hir_def/src/nameres/collector.rs b/crates/ra_hir_def/src/nameres/collector.rs index b4e438257..745e31c0d 100644 --- a/crates/ra_hir_def/src/nameres/collector.rs +++ b/crates/ra_hir_def/src/nameres/collector.rs @@ -716,6 +716,7 @@ where modules[self.module_id].children.insert(name.clone(), res); let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res }; let def: ModuleDefId = module.into(); + self.def_collector.def_map.modules[self.module_id].scope.define_def(def); let resolution = Resolution { def: def.into(), import: false }; self.def_collector.update(self.module_id, None, &[(name, resolution)]); res @@ -775,6 +776,7 @@ where .intern(self.def_collector.db) .into(), }; + self.def_collector.def_map.modules[self.module_id].scope.define_def(def); let resolution = Resolution { def: def.into(), import: false }; self.def_collector.update(self.module_id, None, &[(name, resolution)]) } -- cgit v1.2.3