Skip to content

Commit 6da22ed

Browse files
committed
Redner self as param for call infor for assoc fn call
1 parent a4e9681 commit 6da22ed

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

crates/ra_hir/src/code_model.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,7 +1552,10 @@ impl Callable {
15521552
let param_list = src.value.param_list()?;
15531553
param_list.self_param()
15541554
}
1555-
pub fn params(&self, db: &dyn HirDatabase) -> Vec<(Option<ast::Pat>, Type)> {
1555+
pub fn params(
1556+
&self,
1557+
db: &dyn HirDatabase,
1558+
) -> Vec<(Option<Either<ast::SelfParam, ast::Pat>>, Type)> {
15561559
let types = self
15571560
.sig
15581561
.params()
@@ -1562,7 +1565,14 @@ impl Callable {
15621565
let patterns = match self.id {
15631566
CallableDefId::FunctionId(func) => {
15641567
let src = func.lookup(db.upcast()).source(db.upcast());
1565-
src.value.param_list().map(|it| it.params().map(|it| it.pat()))
1568+
src.value.param_list().map(|param_list| {
1569+
param_list
1570+
.self_param()
1571+
.map(|it| Some(Either::Left(it)))
1572+
.filter(|_| !self.is_bound_method)
1573+
.into_iter()
1574+
.chain(param_list.params().map(|it| it.pat().map(Either::Right)))
1575+
})
15661576
}
15671577
CallableDefId::StructId(_) => None,
15681578
CallableDefId::EnumVariantId(_) => None,

crates/ra_ide/src/call_info.rs

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
//! FIXME: write short doc here
2+
use either::Either;
23
use hir::{Docs, HirDisplay, Semantics, Type};
34
use ra_ide_db::RootDatabase;
45
use ra_syntax::{
@@ -80,7 +81,10 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
8081
for (pat, ty) in callable.params(db) {
8182
buf.clear();
8283
if let Some(pat) = pat {
83-
format_to!(buf, "{}: ", pat);
84+
match pat {
85+
Either::Left(_self) => format_to!(buf, "self: "),
86+
Either::Right(pat) => format_to!(buf, "{}: ", pat),
87+
}
8488
}
8589
format_to!(buf, "{}", ty.display(db));
8690
res.push_param(&buf);
@@ -383,20 +387,37 @@ fn bar() {
383387
check(
384388
r#"
385389
struct S;
386-
impl S { pub fn do_it(&self, x: i32) {} }
387-
388-
fn bar() {
389-
let s: S = S;
390-
s.do_it(<|>);
390+
impl S {
391+
fn foo(&self, x: i32) {}
391392
}
393+
394+
fn main() { S.foo(<|>); }
392395
"#,
393396
expect![[r#"
394-
fn do_it(&self, x: i32)
397+
fn foo(&self, x: i32)
395398
(<x: i32>)
396399
"#]],
397400
);
398401
}
399402

403+
#[test]
404+
fn test_fn_signature_for_method_with_arg_as_assoc_fn() {
405+
check(
406+
r#"
407+
struct S;
408+
impl S {
409+
fn foo(&self, x: i32) {}
410+
}
411+
412+
fn main() { S::foo(<|>); }
413+
"#,
414+
expect![[r#"
415+
fn foo(self: &S, x: i32)
416+
(<self: &S>, x: i32)
417+
"#]],
418+
);
419+
}
420+
400421
#[test]
401422
fn test_fn_signature_with_docs_simple() {
402423
check(

0 commit comments

Comments
 (0)