aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/source_binder.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/source_binder.rs')
-rw-r--r--crates/ra_hir/src/source_binder.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/crates/ra_hir/src/source_binder.rs b/crates/ra_hir/src/source_binder.rs
index 998158b3e..621215bfb 100644
--- a/crates/ra_hir/src/source_binder.rs
+++ b/crates/ra_hir/src/source_binder.rs
@@ -229,3 +229,31 @@ pub fn resolver_for_position(db: &impl HirDatabase, position: FilePosition) -> R
229 }) 229 })
230 .unwrap_or_default() 230 .unwrap_or_default()
231} 231}
232
233pub fn resolver_for_node(
234 db: &impl HirDatabase,
235 file_id: FileId,
236 node: &SyntaxNode,
237) -> Resolver<'static> {
238 node.ancestors()
239 .find_map(|node| {
240 if ast::Expr::cast(node).is_some() || ast::Block::cast(node).is_some() {
241 if let Some(func) = function_from_child_node(db, file_id, node) {
242 let scopes = func.scopes(db);
243 let scope = scopes.scope_for(&node);
244 Some(expr::resolver_for_scope(func.body(db), db, scope))
245 } else {
246 // TODO const/static/array length
247 None
248 }
249 } else if let Some(module) = ast::Module::cast(node) {
250 Some(module_from_declaration(db, file_id, module)?.resolver(db))
251 } else if let Some(_) = ast::SourceFile::cast(node) {
252 Some(module_from_source(db, file_id.into(), None)?.resolver(db))
253 } else {
254 // TODO add missing cases
255 None
256 }
257 })
258 .unwrap_or_default()
259}