Unnamed repository; edit this file 'description' to name the repository.
Prefer `hir::SelfParam` and fix signature help of methods from macros
oxalica 2023-08-09
parent 6a2f83a · commit de86444
-rw-r--r--crates/hir/src/lib.rs7
-rw-r--r--crates/ide-ssr/src/matching.rs6
-rw-r--r--crates/ide/src/signature_help.rs21
3 files changed, 27 insertions, 7 deletions
diff --git a/crates/hir/src/lib.rs b/crates/hir/src/lib.rs
index 77cadfbae3..60ab0c267f 100644
--- a/crates/hir/src/lib.rs
+++ b/crates/hir/src/lib.rs
@@ -4406,14 +4406,13 @@ impl Callable {
Other => CallableKind::Other,
}
}
- pub fn receiver_param(&self, db: &dyn HirDatabase) -> Option<(ast::SelfParam, Type)> {
+ pub fn receiver_param(&self, db: &dyn HirDatabase) -> Option<(SelfParam, Type)> {
let func = match self.callee {
Callee::Def(CallableDefId::FunctionId(it)) if self.is_bound_method => it,
_ => return None,
};
- let src = func.lookup(db.upcast()).source(db.upcast());
- let param_list = src.value.param_list()?;
- Some((param_list.self_param()?, self.ty.derived(self.sig.params()[0].clone())))
+ let func = Function { id: func };
+ Some((func.self_param(db)?, self.ty.derived(self.sig.params()[0].clone())))
}
pub fn n_params(&self) -> usize {
self.sig.params().len() - if self.is_bound_method { 1 } else { 0 }
diff --git a/crates/ide-ssr/src/matching.rs b/crates/ide-ssr/src/matching.rs
index a8e8836908..60fcbbbd39 100644
--- a/crates/ide-ssr/src/matching.rs
+++ b/crates/ide-ssr/src/matching.rs
@@ -560,8 +560,10 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
placeholder_value.autoref_kind = self
.sema
.resolve_method_call_as_callable(code)
- .and_then(|callable| callable.receiver_param(self.sema.db))
- .map(|(self_param, _)| self_param.kind())
+ .and_then(|callable| {
+ let (self_param, _) = callable.receiver_param(self.sema.db)?;
+ Some(self_param.source(self.sema.db)?.value.kind())
+ })
.unwrap_or(ast::SelfParamKind::Owned);
}
}
diff --git a/crates/ide/src/signature_help.rs b/crates/ide/src/signature_help.rs
index 7795be54e2..e3ad817e06 100644
--- a/crates/ide/src/signature_help.rs
+++ b/crates/ide/src/signature_help.rs
@@ -202,7 +202,7 @@ fn signature_help_for_call(
res.signature.push('(');
{
if let Some((self_param, _)) = callable.receiver_param(db) {
- format_to!(res.signature, "{}", self_param)
+ format_to!(res.signature, "{}", self_param.display(db))
}
let mut buf = String::new();
for (idx, (pat, ty)) in callable.params(db).into_iter().enumerate() {
@@ -1315,6 +1315,25 @@ id! {
}
#[test]
+ fn fn_signature_for_method_call_defined_in_macro() {
+ check(
+ r#"
+macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
+struct S;
+id! {
+ impl S {
+ fn foo<'a>(&'a mut self) {}
+ }
+}
+fn test() { S.foo($0); }
+"#,
+ expect![[r#"
+ fn foo(&'a mut self)
+ "#]],
+ );
+ }
+
+ #[test]
fn call_info_for_lambdas() {
check(
r#"