aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/resolve.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/resolve.rs')
-rw-r--r--crates/ra_hir/src/resolve.rs24
1 files changed, 15 insertions, 9 deletions
diff --git a/crates/ra_hir/src/resolve.rs b/crates/ra_hir/src/resolve.rs
index 40c860cf4..91a531801 100644
--- a/crates/ra_hir/src/resolve.rs
+++ b/crates/ra_hir/src/resolve.rs
@@ -56,10 +56,10 @@ pub enum Resolution {
56} 56}
57 57
58impl Resolver { 58impl Resolver {
59 pub fn resolve_name(&self, name: &Name) -> PerNs<Resolution> { 59 pub fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
60 let mut resolution = PerNs::none(); 60 let mut resolution = PerNs::none();
61 for scope in self.scopes.iter().rev() { 61 for scope in self.scopes.iter().rev() {
62 resolution = resolution.or(scope.resolve_name(name)); 62 resolution = resolution.or(scope.resolve_name(db, name));
63 if resolution.is_both() { 63 if resolution.is_both() {
64 return resolution; 64 return resolution;
65 } 65 }
@@ -69,9 +69,9 @@ impl Resolver {
69 69
70 pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resolution> { 70 pub fn resolve_path(&self, db: &impl HirDatabase, path: &Path) -> PerNs<Resolution> {
71 if let Some(name) = path.as_ident() { 71 if let Some(name) = path.as_ident() {
72 self.resolve_name(name) 72 self.resolve_name(db, name)
73 } else if path.is_self() { 73 } else if path.is_self() {
74 self.resolve_name(&Name::self_param()) 74 self.resolve_name(db, &Name::self_param())
75 } else { 75 } else {
76 let (item_map, module) = match self.module() { 76 let (item_map, module) = match self.module() {
77 Some(m) => m, 77 Some(m) => m,
@@ -82,10 +82,10 @@ impl Resolver {
82 } 82 }
83 } 83 }
84 84
85 pub fn all_names(&self) -> FxHashMap<Name, PerNs<Resolution>> { 85 pub fn all_names(&self, db: &impl HirDatabase) -> FxHashMap<Name, PerNs<Resolution>> {
86 let mut names = FxHashMap::default(); 86 let mut names = FxHashMap::default();
87 for scope in self.scopes.iter().rev() { 87 for scope in self.scopes.iter().rev() {
88 scope.collect_names(&mut |name, res| { 88 scope.collect_names(db, &mut |name, res| {
89 let current: &mut PerNs<Resolution> = names.entry(name).or_default(); 89 let current: &mut PerNs<Resolution> = names.entry(name).or_default();
90 if current.types.is_none() { 90 if current.types.is_none() {
91 current.types = res.types; 91 current.types = res.types;
@@ -143,13 +143,13 @@ impl Resolver {
143} 143}
144 144
145impl Scope { 145impl Scope {
146 fn resolve_name(&self, name: &Name) -> PerNs<Resolution> { 146 fn resolve_name(&self, db: &impl HirDatabase, name: &Name) -> PerNs<Resolution> {
147 match self { 147 match self {
148 Scope::ModuleScope(m) => { 148 Scope::ModuleScope(m) => {
149 if let Some(KnownName::SelfParam) = name.as_known_name() { 149 if let Some(KnownName::SelfParam) = name.as_known_name() {
150 PerNs::types(Resolution::Def(m.module.into())) 150 PerNs::types(Resolution::Def(m.module.into()))
151 } else { 151 } else {
152 m.item_map.resolve_name_in_module(m.module, name).map(Resolution::Def) 152 m.item_map.resolve_name_in_module(db, m.module, name).map(Resolution::Def)
153 } 153 }
154 } 154 }
155 Scope::GenericParams(gp) => match gp.find_by_name(name) { 155 Scope::GenericParams(gp) => match gp.find_by_name(name) {
@@ -174,7 +174,7 @@ impl Scope {
174 } 174 }
175 } 175 }
176 176
177 fn collect_names(&self, f: &mut dyn FnMut(Name, PerNs<Resolution>)) { 177 fn collect_names(&self, db: &impl HirDatabase, f: &mut dyn FnMut(Name, PerNs<Resolution>)) {
178 match self { 178 match self {
179 Scope::ModuleScope(m) => { 179 Scope::ModuleScope(m) => {
180 // TODO: should we provide `self` here? 180 // TODO: should we provide `self` here?
@@ -190,6 +190,12 @@ impl Scope {
190 m.item_map.extern_prelude.iter().for_each(|(name, def)| { 190 m.item_map.extern_prelude.iter().for_each(|(name, def)| {
191 f(name.clone(), PerNs::types(Resolution::Def(*def))); 191 f(name.clone(), PerNs::types(Resolution::Def(*def)));
192 }); 192 });
193 if let Some(prelude) = m.item_map.prelude {
194 let prelude_item_map = db.item_map(prelude.krate);
195 prelude_item_map[prelude.module_id].entries().for_each(|(name, res)| {
196 f(name.clone(), res.def.map(Resolution::Def));
197 });
198 }
193 } 199 }
194 Scope::GenericParams(gp) => { 200 Scope::GenericParams(gp) => {
195 for param in &gp.params { 201 for param in &gp.params {