diff options
author | Florian Diebold <[email protected]> | 2019-01-23 22:08:41 +0000 |
---|---|---|
committer | Florian Diebold <[email protected]> | 2019-02-01 21:17:48 +0000 |
commit | 758bc72873efe36f579236d1abf240d14866fd82 (patch) | |
tree | a8c416c5c2c3dfb834bf29ed2ca4fae666048a59 /crates/ra_hir/src/code_model_api.rs | |
parent | 5208c2aa930ae452e062dcdc2563c1bbb67d2e4a (diff) |
Implement methods to build a resolver
Diffstat (limited to 'crates/ra_hir/src/code_model_api.rs')
-rw-r--r-- | crates/ra_hir/src/code_model_api.rs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/crates/ra_hir/src/code_model_api.rs b/crates/ra_hir/src/code_model_api.rs index 73541a8c3..b8ca04c5c 100644 --- a/crates/ra_hir/src/code_model_api.rs +++ b/crates/ra_hir/src/code_model_api.rs | |||
@@ -184,9 +184,9 @@ impl Module { | |||
184 | self.problems_impl(db) | 184 | self.problems_impl(db) |
185 | } | 185 | } |
186 | 186 | ||
187 | #[allow(unused_variables)] | ||
188 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { | 187 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { |
189 | unimplemented!() | 188 | let item_map = db.item_map(self.krate); |
189 | Resolver::default().push_module_scope(item_map, self.module_id) | ||
190 | } | 190 | } |
191 | } | 191 | } |
192 | 192 | ||
@@ -480,6 +480,24 @@ impl Function { | |||
480 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { | 480 | pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> { |
481 | db.generic_params((*self).into()) | 481 | db.generic_params((*self).into()) |
482 | } | 482 | } |
483 | |||
484 | // TODO move to a more general type for 'body-having' items | ||
485 | /// Builds a resolver for code inside this item. | ||
486 | pub fn resolver(&self, db: &impl HirDatabase) -> Resolver { | ||
487 | // take the outer scope... | ||
488 | let r = self | ||
489 | .impl_block(db) | ||
490 | .map(|ib| ib.resolver(db)) | ||
491 | .unwrap_or_else(|| self.module(db).resolver(db)); | ||
492 | // ...and add generic params, if present | ||
493 | let p = self.generic_params(db); | ||
494 | let r = if !p.params.is_empty() { | ||
495 | r.push_generic_params_scope(p) | ||
496 | } else { | ||
497 | r | ||
498 | }; | ||
499 | r | ||
500 | } | ||
483 | } | 501 | } |
484 | 502 | ||
485 | impl Docs for Function { | 503 | impl Docs for Function { |