Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit de86444

Browse files
committed
Prefer hir::SelfParam and fix signature help of methods from macros
1 parent 6a2f83a commit de86444

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

crates/hir/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,14 +4406,13 @@ impl Callable {
44064406
Other => CallableKind::Other,
44074407
}
44084408
}
4409-
pub fn receiver_param(&self, db: &dyn HirDatabase) -> Option<(ast::SelfParam, Type)> {
4409+
pub fn receiver_param(&self, db: &dyn HirDatabase) -> Option<(SelfParam, Type)> {
44104410
let func = match self.callee {
44114411
Callee::Def(CallableDefId::FunctionId(it)) if self.is_bound_method => it,
44124412
_ => return None,
44134413
};
4414-
let src = func.lookup(db.upcast()).source(db.upcast());
4415-
let param_list = src.value.param_list()?;
4416-
Some((param_list.self_param()?, self.ty.derived(self.sig.params()[0].clone())))
4414+
let func = Function { id: func };
4415+
Some((func.self_param(db)?, self.ty.derived(self.sig.params()[0].clone())))
44174416
}
44184417
pub fn n_params(&self) -> usize {
44194418
self.sig.params().len() - if self.is_bound_method { 1 } else { 0 }

crates/ide-ssr/src/matching.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,10 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
560560
placeholder_value.autoref_kind = self
561561
.sema
562562
.resolve_method_call_as_callable(code)
563-
.and_then(|callable| callable.receiver_param(self.sema.db))
564-
.map(|(self_param, _)| self_param.kind())
563+
.and_then(|callable| {
564+
let (self_param, _) = callable.receiver_param(self.sema.db)?;
565+
Some(self_param.source(self.sema.db)?.value.kind())
566+
})
565567
.unwrap_or(ast::SelfParamKind::Owned);
566568
}
567569
}

crates/ide/src/signature_help.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ fn signature_help_for_call(
202202
res.signature.push('(');
203203
{
204204
if let Some((self_param, _)) = callable.receiver_param(db) {
205-
format_to!(res.signature, "{}", self_param)
205+
format_to!(res.signature, "{}", self_param.display(db))
206206
}
207207
let mut buf = String::new();
208208
for (idx, (pat, ty)) in callable.params(db).into_iter().enumerate() {
@@ -1314,6 +1314,25 @@ id! {
13141314
);
13151315
}
13161316

1317+
#[test]
1318+
fn fn_signature_for_method_call_defined_in_macro() {
1319+
check(
1320+
r#"
1321+
macro_rules! id { ($($tt:tt)*) => { $($tt)* } }
1322+
struct S;
1323+
id! {
1324+
impl S {
1325+
fn foo<'a>(&'a mut self) {}
1326+
}
1327+
}
1328+
fn test() { S.foo($0); }
1329+
"#,
1330+
expect![[r#"
1331+
fn foo(&'a mut self)
1332+
"#]],
1333+
);
1334+
}
1335+
13171336
#[test]
13181337
fn call_info_for_lambdas() {
13191338
check(

0 commit comments

Comments
 (0)