diff options
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r-- | crates/ra_hir/src/nameres.rs | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs index f8627acbe..7ec6512b6 100644 --- a/crates/ra_hir/src/nameres.rs +++ b/crates/ra_hir/src/nameres.rs | |||
@@ -24,13 +24,13 @@ use rustc_hash::{FxHashMap, FxHashSet}; | |||
24 | 24 | ||
25 | use crate::{ | 25 | use crate::{ |
26 | Module, ModuleDef, | 26 | Module, ModuleDef, |
27 | Path, PathKind, Crate, | 27 | Path, PathKind, PersistentHirDatabase, |
28 | Name, PersistentHirDatabase, | 28 | Crate, Name, |
29 | module_tree::{ModuleId, ModuleTree}, | 29 | module_tree::{ModuleId, ModuleTree}, |
30 | nameres::lower::{ImportId, LoweredModule, ImportData}, | 30 | nameres::lower::{ImportId, LoweredModule, ImportData}, |
31 | }; | 31 | }; |
32 | 32 | ||
33 | /// `ItemMap` is the result of name resolution. It contains, for each | 33 | /// `ItemMap` is the result of module name resolution. It contains, for each |
34 | /// module, the set of visible items. | 34 | /// module, the set of visible items. |
35 | #[derive(Default, Debug, PartialEq, Eq)] | 35 | #[derive(Default, Debug, PartialEq, Eq)] |
36 | pub struct ItemMap { | 36 | pub struct ItemMap { |
@@ -46,7 +46,7 @@ impl std::ops::Index<ModuleId> for ItemMap { | |||
46 | 46 | ||
47 | #[derive(Debug, Default, PartialEq, Eq, Clone)] | 47 | #[derive(Debug, Default, PartialEq, Eq, Clone)] |
48 | pub struct ModuleScope { | 48 | pub struct ModuleScope { |
49 | items: FxHashMap<Name, Resolution>, | 49 | pub(crate) items: FxHashMap<Name, Resolution>, |
50 | } | 50 | } |
51 | 51 | ||
52 | impl ModuleScope { | 52 | impl ModuleScope { |
@@ -80,6 +80,15 @@ pub struct PerNs<T> { | |||
80 | pub values: Option<T>, | 80 | pub values: Option<T>, |
81 | } | 81 | } |
82 | 82 | ||
83 | impl<T> Default for PerNs<T> { | ||
84 | fn default() -> Self { | ||
85 | PerNs { | ||
86 | types: None, | ||
87 | values: None, | ||
88 | } | ||
89 | } | ||
90 | } | ||
91 | |||
83 | impl<T> PerNs<T> { | 92 | impl<T> PerNs<T> { |
84 | pub fn none() -> PerNs<T> { | 93 | pub fn none() -> PerNs<T> { |
85 | PerNs { | 94 | PerNs { |
@@ -113,6 +122,10 @@ impl<T> PerNs<T> { | |||
113 | self.types.is_none() && self.values.is_none() | 122 | self.types.is_none() && self.values.is_none() |
114 | } | 123 | } |
115 | 124 | ||
125 | pub fn is_both(&self) -> bool { | ||
126 | self.types.is_some() && self.values.is_some() | ||
127 | } | ||
128 | |||
116 | pub fn take(self, namespace: Namespace) -> Option<T> { | 129 | pub fn take(self, namespace: Namespace) -> Option<T> { |
117 | match namespace { | 130 | match namespace { |
118 | Namespace::Types => self.types, | 131 | Namespace::Types => self.types, |
@@ -139,6 +152,13 @@ impl<T> PerNs<T> { | |||
139 | } | 152 | } |
140 | } | 153 | } |
141 | 154 | ||
155 | pub fn combine(self, other: PerNs<T>) -> PerNs<T> { | ||
156 | PerNs { | ||
157 | types: self.types.or(other.types), | ||
158 | values: self.values.or(other.values), | ||
159 | } | ||
160 | } | ||
161 | |||
142 | pub fn and_then<U>(self, f: impl Fn(T) -> Option<U>) -> PerNs<U> { | 162 | pub fn and_then<U>(self, f: impl Fn(T) -> Option<U>) -> PerNs<U> { |
143 | PerNs { | 163 | PerNs { |
144 | types: self.types.and_then(&f), | 164 | types: self.types.and_then(&f), |
@@ -402,10 +422,11 @@ impl ItemMap { | |||
402 | if module.krate != original_module.krate { | 422 | if module.krate != original_module.krate { |
403 | let path = Path { | 423 | let path = Path { |
404 | segments: path.segments[i..].iter().cloned().collect(), | 424 | segments: path.segments[i..].iter().cloned().collect(), |
405 | kind: PathKind::Crate, | 425 | kind: PathKind::Self_, |
406 | }; | 426 | }; |
407 | log::debug!("resolving {:?} in other crate", path); | 427 | log::debug!("resolving {:?} in other crate", path); |
408 | let def = module.resolve_path(db, &path); | 428 | let item_map = db.item_map(module.krate); |
429 | let def = item_map.resolve_path(db, *module, &path); | ||
409 | return (def, ReachedFixedPoint::Yes); | 430 | return (def, ReachedFixedPoint::Yes); |
410 | } | 431 | } |
411 | 432 | ||