aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-12-22 14:21:48 +0000
committerAleksey Kladov <[email protected]>2019-12-22 14:21:48 +0000
commit2c60f42825e68d8133854d378d9550139c71d9b4 (patch)
tree758ae7afaa82f127f7967e53dcd373092aa9fc81
parente69af8596262931f8e55b7f9203f65d14827e2d8 (diff)
Separate defs from imports
-rw-r--r--crates/ra_hir_def/src/item_scope.rs11
-rw-r--r--crates/ra_hir_def/src/nameres/collector.rs2
2 files changed, 8 insertions, 5 deletions
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,
10#[derive(Debug, Default, PartialEq, Eq)] 10#[derive(Debug, Default, PartialEq, Eq)]
11pub struct ItemScope { 11pub struct ItemScope {
12 visible: FxHashMap<Name, Resolution>, 12 visible: FxHashMap<Name, Resolution>,
13 defs: Vec<ModuleDefId>,
13 impls: Vec<ImplId>, 14 impls: Vec<ImplId>,
14 /// Macros visible in current module in legacy textual scope 15 /// Macros visible in current module in legacy textual scope
15 /// 16 ///
@@ -53,11 +54,7 @@ impl ItemScope {
53 } 54 }
54 55
55 pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { 56 pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ {
56 self.entries() 57 self.defs.iter().copied()
57 .filter_map(|(_name, res)| if !res.import { Some(res.def) } else { None })
58 .flat_map(|per_ns| {
59 per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter())
60 })
61 } 58 }
62 59
63 pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ { 60 pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ {
@@ -100,6 +97,10 @@ impl ItemScope {
100 }) 97 })
101 } 98 }
102 99
100 pub(crate) fn define_def(&mut self, def: ModuleDefId) {
101 self.defs.push(def)
102 }
103
103 pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<MacroDefId> { 104 pub(crate) fn get_legacy_macro(&self, name: &Name) -> Option<MacroDefId> {
104 self.legacy_macros.get(name).copied() 105 self.legacy_macros.get(name).copied()
105 } 106 }
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
716 modules[self.module_id].children.insert(name.clone(), res); 716 modules[self.module_id].children.insert(name.clone(), res);
717 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res }; 717 let module = ModuleId { krate: self.def_collector.def_map.krate, local_id: res };
718 let def: ModuleDefId = module.into(); 718 let def: ModuleDefId = module.into();
719 self.def_collector.def_map.modules[self.module_id].scope.define_def(def);
719 let resolution = Resolution { def: def.into(), import: false }; 720 let resolution = Resolution { def: def.into(), import: false };
720 self.def_collector.update(self.module_id, None, &[(name, resolution)]); 721 self.def_collector.update(self.module_id, None, &[(name, resolution)]);
721 res 722 res
@@ -775,6 +776,7 @@ where
775 .intern(self.def_collector.db) 776 .intern(self.def_collector.db)
776 .into(), 777 .into(),
777 }; 778 };
779 self.def_collector.def_map.modules[self.module_id].scope.define_def(def);
778 let resolution = Resolution { def: def.into(), import: false }; 780 let resolution = Resolution { def: def.into(), import: false };
779 self.def_collector.update(self.module_id, None, &[(name, resolution)]) 781 self.def_collector.update(self.module_id, None, &[(name, resolution)])
780 } 782 }