aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/nameres.rs')
-rw-r--r--crates/ra_hir/src/nameres.rs23
1 files changed, 18 insertions, 5 deletions
diff --git a/crates/ra_hir/src/nameres.rs b/crates/ra_hir/src/nameres.rs
index e825ec089..193c6a977 100644
--- a/crates/ra_hir/src/nameres.rs
+++ b/crates/ra_hir/src/nameres.rs
@@ -24,8 +24,9 @@ use rustc_hash::{FxHashMap, FxHashSet};
24 24
25use crate::{ 25use crate::{
26 Module, ModuleDef, 26 Module, ModuleDef,
27 Path, PathKind, Crate, 27 Path, PathKind, PersistentHirDatabase,
28 Name, PersistentHirDatabase, 28 Crate,
29 Name,
29 module_tree::{ModuleId, ModuleTree}, 30 module_tree::{ModuleId, ModuleTree},
30 nameres::lower::{ImportId, LoweredModule, ImportData}, 31 nameres::lower::{ImportId, LoweredModule, ImportData},
31}; 32};
@@ -46,7 +47,7 @@ impl std::ops::Index<ModuleId> for ItemMap {
46 47
47#[derive(Debug, Default, PartialEq, Eq, Clone)] 48#[derive(Debug, Default, PartialEq, Eq, Clone)]
48pub struct ModuleScope { 49pub struct ModuleScope {
49 items: FxHashMap<Name, Resolution>, 50 pub(crate) items: FxHashMap<Name, Resolution>,
50} 51}
51 52
52impl ModuleScope { 53impl ModuleScope {
@@ -113,6 +114,10 @@ impl<T> PerNs<T> {
113 self.types.is_none() && self.values.is_none() 114 self.types.is_none() && self.values.is_none()
114 } 115 }
115 116
117 pub fn is_both(&self) -> bool {
118 self.types.is_some() && self.values.is_some()
119 }
120
116 pub fn take(self, namespace: Namespace) -> Option<T> { 121 pub fn take(self, namespace: Namespace) -> Option<T> {
117 match namespace { 122 match namespace {
118 Namespace::Types => self.types, 123 Namespace::Types => self.types,
@@ -139,6 +144,13 @@ impl<T> PerNs<T> {
139 } 144 }
140 } 145 }
141 146
147 pub fn combine(self, other: PerNs<T>) -> PerNs<T> {
148 PerNs {
149 types: self.types.or(other.types),
150 values: self.values.or(other.values),
151 }
152 }
153
142 pub fn and_then<U>(self, f: impl Fn(T) -> Option<U>) -> PerNs<U> { 154 pub fn and_then<U>(self, f: impl Fn(T) -> Option<U>) -> PerNs<U> {
143 PerNs { 155 PerNs {
144 types: self.types.and_then(&f), 156 types: self.types.and_then(&f),
@@ -402,10 +414,11 @@ impl ItemMap {
402 if module.krate != original_module.krate { 414 if module.krate != original_module.krate {
403 let path = Path { 415 let path = Path {
404 segments: path.segments[i..].iter().cloned().collect(), 416 segments: path.segments[i..].iter().cloned().collect(),
405 kind: PathKind::Crate, 417 kind: PathKind::Self_,
406 }; 418 };
407 log::debug!("resolving {:?} in other crate", path); 419 log::debug!("resolving {:?} in other crate", path);
408 let def = module.resolve_path(db, &path); 420 let item_map = db.item_map(module.krate);
421 let def = item_map.resolve_path(db, *module, &path);
409 return (def, ReachedFixedPoint::Yes); 422 return (def, ReachedFixedPoint::Yes);
410 } 423 }
411 424