mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-28 21:05:02 +00:00
Implement methods to build a resolver
This commit is contained in:
parent
5208c2aa93
commit
758bc72873
5 changed files with 169 additions and 76 deletions
|
@ -184,9 +184,9 @@ impl Module {
|
|||
self.problems_impl(db)
|
||||
}
|
||||
|
||||
#[allow(unused_variables)]
|
||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||
unimplemented!()
|
||||
let item_map = db.item_map(self.krate);
|
||||
Resolver::default().push_module_scope(item_map, self.module_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -480,6 +480,24 @@ impl Function {
|
|||
pub fn generic_params(&self, db: &impl PersistentHirDatabase) -> Arc<GenericParams> {
|
||||
db.generic_params((*self).into())
|
||||
}
|
||||
|
||||
// TODO move to a more general type for 'body-having' items
|
||||
/// Builds a resolver for code inside this item.
|
||||
pub fn resolver(&self, db: &impl HirDatabase) -> Resolver {
|
||||
// take the outer scope...
|
||||
let r = self
|
||||
.impl_block(db)
|
||||
.map(|ib| ib.resolver(db))
|
||||
.unwrap_or_else(|| self.module(db).resolver(db));
|
||||
// ...and add generic params, if present
|
||||
let p = self.generic_params(db);
|
||||
let r = if !p.params.is_empty() {
|
||||
r.push_generic_params_scope(p)
|
||||
} else {
|
||||
r
|
||||
};
|
||||
r
|
||||
}
|
||||
}
|
||||
|
||||
impl Docs for Function {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue