diff options
Diffstat (limited to 'crates/ra_hir_def/src/item_scope.rs')
-rw-r--r-- | crates/ra_hir_def/src/item_scope.rs | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/crates/ra_hir_def/src/item_scope.rs b/crates/ra_hir_def/src/item_scope.rs index 5c14fefff..6b9be8325 100644 --- a/crates/ra_hir_def/src/item_scope.rs +++ b/crates/ra_hir_def/src/item_scope.rs | |||
@@ -5,7 +5,7 @@ use hir_expand::name::Name; | |||
5 | use once_cell::sync::Lazy; | 5 | use once_cell::sync::Lazy; |
6 | use rustc_hash::FxHashMap; | 6 | use rustc_hash::FxHashMap; |
7 | 7 | ||
8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, MacroDefId, ModuleDefId, TraitId}; | 8 | use crate::{per_ns::PerNs, BuiltinType, ImplId, LocalImportId, MacroDefId, ModuleDefId, TraitId}; |
9 | 9 | ||
10 | #[derive(Debug, Default, PartialEq, Eq)] | 10 | #[derive(Debug, Default, PartialEq, Eq)] |
11 | pub struct ItemScope { | 11 | pub struct ItemScope { |
@@ -30,7 +30,7 @@ static BUILTIN_SCOPE: Lazy<FxHashMap<Name, Resolution>> = Lazy::new(|| { | |||
30 | BuiltinType::ALL | 30 | BuiltinType::ALL |
31 | .iter() | 31 | .iter() |
32 | .map(|(name, ty)| { | 32 | .map(|(name, ty)| { |
33 | (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), declaration: false }) | 33 | (name.clone(), Resolution { def: PerNs::types(ty.clone().into()), import: None }) |
34 | }) | 34 | }) |
35 | .collect() | 35 | .collect() |
36 | }); | 36 | }); |
@@ -53,9 +53,11 @@ impl ItemScope { | |||
53 | } | 53 | } |
54 | 54 | ||
55 | pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { | 55 | pub fn declarations(&self) -> impl Iterator<Item = ModuleDefId> + '_ { |
56 | self.entries().filter(|(_name, res)| res.declaration).flat_map(|(_name, res)| { | 56 | self.entries() |
57 | res.def.take_types().into_iter().chain(res.def.take_values().into_iter()) | 57 | .filter_map(|(_name, res)| if res.import.is_none() { Some(res.def) } else { None }) |
58 | }) | 58 | .flat_map(|per_ns| { |
59 | per_ns.take_types().into_iter().chain(per_ns.take_values().into_iter()) | ||
60 | }) | ||
59 | } | 61 | } |
60 | 62 | ||
61 | pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ { | 63 | pub fn impls(&self) -> impl Iterator<Item = ImplId> + ExactSizeIterator + '_ { |
@@ -110,26 +112,38 @@ impl ItemScope { | |||
110 | self.legacy_macros.insert(name, mac); | 112 | self.legacy_macros.insert(name, mac); |
111 | } | 113 | } |
112 | 114 | ||
113 | pub(crate) fn push_res(&mut self, name: Name, res: &Resolution, declaration: bool) -> bool { | 115 | pub(crate) fn push_res( |
116 | &mut self, | ||
117 | name: Name, | ||
118 | res: &Resolution, | ||
119 | import: Option<LocalImportId>, | ||
120 | ) -> bool { | ||
114 | let mut changed = false; | 121 | let mut changed = false; |
115 | let existing = self.items.entry(name.clone()).or_default(); | 122 | let existing = self.items.entry(name.clone()).or_default(); |
116 | 123 | ||
117 | if existing.def.types.is_none() && res.def.types.is_some() { | 124 | if existing.def.types.is_none() && res.def.types.is_some() { |
118 | existing.def.types = res.def.types; | 125 | existing.def.types = res.def.types; |
119 | existing.declaration |= declaration; | 126 | existing.import = import.or(res.import); |
120 | changed = true; | 127 | changed = true; |
121 | } | 128 | } |
122 | if existing.def.values.is_none() && res.def.values.is_some() { | 129 | if existing.def.values.is_none() && res.def.values.is_some() { |
123 | existing.def.values = res.def.values; | 130 | existing.def.values = res.def.values; |
124 | existing.declaration |= declaration; | 131 | existing.import = import.or(res.import); |
125 | changed = true; | 132 | changed = true; |
126 | } | 133 | } |
127 | if existing.def.macros.is_none() && res.def.macros.is_some() { | 134 | if existing.def.macros.is_none() && res.def.macros.is_some() { |
128 | existing.def.macros = res.def.macros; | 135 | existing.def.macros = res.def.macros; |
129 | existing.declaration |= declaration; | 136 | existing.import = import.or(res.import); |
130 | changed = true; | 137 | changed = true; |
131 | } | 138 | } |
132 | 139 | ||
140 | if existing.def.is_none() | ||
141 | && res.def.is_none() | ||
142 | && existing.import.is_none() | ||
143 | && res.import.is_some() | ||
144 | { | ||
145 | existing.import = res.import; | ||
146 | } | ||
133 | changed | 147 | changed |
134 | } | 148 | } |
135 | 149 | ||
@@ -146,5 +160,6 @@ impl ItemScope { | |||
146 | pub struct Resolution { | 160 | pub struct Resolution { |
147 | /// None for unresolved | 161 | /// None for unresolved |
148 | pub def: PerNs, | 162 | pub def: PerNs, |
149 | pub declaration: bool, | 163 | /// ident by which this is imported into local scope. |
164 | pub import: Option<LocalImportId>, | ||
150 | } | 165 | } |