From ed3497883ca2d6767453fc02cb817b2d56547d95 Mon Sep 17 00:00:00 2001 From: Vincent Esche Date: Wed, 28 Feb 2024 15:14:05 +0100 Subject: [PATCH] Add public function for resolving `ast::Expr` to `hir::Callable` --- crates/hir/src/semantics.rs | 4 ++++ crates/hir/src/source_analyzer.rs | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/crates/hir/src/semantics.rs b/crates/hir/src/semantics.rs index 1fb6570b6a4..cfda8d4f937 100644 --- a/crates/hir/src/semantics.rs +++ b/crates/hir/src/semantics.rs @@ -1120,6 +1120,10 @@ pub fn binding_mode_of_pat(&self, pat: &ast::IdentPat) -> Option { self.analyze(pat.syntax())?.binding_mode_of_pat(self.db, pat) } + pub fn resolve_expr_as_callable(&self, call: &ast::Expr) -> Option { + self.analyze(call.syntax())?.resolve_expr_as_callable(self.db, call) + } + pub fn resolve_method_call(&self, call: &ast::MethodCallExpr) -> Option { self.analyze(call.syntax())?.resolve_method_call(self.db, call) } diff --git a/crates/hir/src/source_analyzer.rs b/crates/hir/src/source_analyzer.rs index bcc9111f2ba..ffec4c21497 100644 --- a/crates/hir/src/source_analyzer.rs +++ b/crates/hir/src/source_analyzer.rs @@ -303,6 +303,14 @@ pub(crate) fn resolve_method_call_fallback( } } + pub(crate) fn resolve_expr_as_callable( + &self, + db: &dyn HirDatabase, + call: &ast::Expr, + ) -> Option { + self.type_of_expr(db, &call.clone())?.0.as_callable(db) + } + pub(crate) fn resolve_field( &self, db: &dyn HirDatabase,