mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
Prefer hir::SelfParam
and fix signature help of methods from macros
This commit is contained in:
parent
6a2f83a8a2
commit
de86444756
3 changed files with 27 additions and 7 deletions
|
@ -4406,14 +4406,13 @@ impl Callable {
|
||||||
Other => CallableKind::Other,
|
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 {
|
let func = match self.callee {
|
||||||
Callee::Def(CallableDefId::FunctionId(it)) if self.is_bound_method => it,
|
Callee::Def(CallableDefId::FunctionId(it)) if self.is_bound_method => it,
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
let src = func.lookup(db.upcast()).source(db.upcast());
|
let func = Function { id: func };
|
||||||
let param_list = src.value.param_list()?;
|
Some((func.self_param(db)?, self.ty.derived(self.sig.params()[0].clone())))
|
||||||
Some((param_list.self_param()?, self.ty.derived(self.sig.params()[0].clone())))
|
|
||||||
}
|
}
|
||||||
pub fn n_params(&self) -> usize {
|
pub fn n_params(&self) -> usize {
|
||||||
self.sig.params().len() - if self.is_bound_method { 1 } else { 0 }
|
self.sig.params().len() - if self.is_bound_method { 1 } else { 0 }
|
||||||
|
|
|
@ -560,8 +560,10 @@ impl<'db, 'sema> Matcher<'db, 'sema> {
|
||||||
placeholder_value.autoref_kind = self
|
placeholder_value.autoref_kind = self
|
||||||
.sema
|
.sema
|
||||||
.resolve_method_call_as_callable(code)
|
.resolve_method_call_as_callable(code)
|
||||||
.and_then(|callable| callable.receiver_param(self.sema.db))
|
.and_then(|callable| {
|
||||||
.map(|(self_param, _)| self_param.kind())
|
let (self_param, _) = callable.receiver_param(self.sema.db)?;
|
||||||
|
Some(self_param.source(self.sema.db)?.value.kind())
|
||||||
|
})
|
||||||
.unwrap_or(ast::SelfParamKind::Owned);
|
.unwrap_or(ast::SelfParamKind::Owned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -202,7 +202,7 @@ fn signature_help_for_call(
|
||||||
res.signature.push('(');
|
res.signature.push('(');
|
||||||
{
|
{
|
||||||
if let Some((self_param, _)) = callable.receiver_param(db) {
|
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();
|
let mut buf = String::new();
|
||||||
for (idx, (pat, ty)) in callable.params(db).into_iter().enumerate() {
|
for (idx, (pat, ty)) in callable.params(db).into_iter().enumerate() {
|
||||||
|
@ -1314,6 +1314,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]
|
#[test]
|
||||||
fn call_info_for_lambdas() {
|
fn call_info_for_lambdas() {
|
||||||
check(
|
check(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue