diff options
Diffstat (limited to 'crates')
-rw-r--r-- | crates/ra_hir/src/code_model.rs | 14 | ||||
-rw-r--r-- | crates/ra_ide/src/call_info.rs | 35 |
2 files changed, 40 insertions, 9 deletions
diff --git a/crates/ra_hir/src/code_model.rs b/crates/ra_hir/src/code_model.rs index 057dfb82a..eb6a14eda 100644 --- a/crates/ra_hir/src/code_model.rs +++ b/crates/ra_hir/src/code_model.rs | |||
@@ -1552,7 +1552,10 @@ impl Callable { | |||
1552 | let param_list = src.value.param_list()?; | 1552 | let param_list = src.value.param_list()?; |
1553 | param_list.self_param() | 1553 | param_list.self_param() |
1554 | } | 1554 | } |
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)> { | ||
1556 | let types = self | 1559 | let types = self |
1557 | .sig | 1560 | .sig |
1558 | .params() | 1561 | .params() |
@@ -1562,7 +1565,14 @@ impl Callable { | |||
1562 | let patterns = match self.id { | 1565 | let patterns = match self.id { |
1563 | CallableDefId::FunctionId(func) => { | 1566 | CallableDefId::FunctionId(func) => { |
1564 | let src = func.lookup(db.upcast()).source(db.upcast()); | 1567 | 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 | }) | ||
1566 | } | 1576 | } |
1567 | CallableDefId::StructId(_) => None, | 1577 | CallableDefId::StructId(_) => None, |
1568 | CallableDefId::EnumVariantId(_) => None, | 1578 | CallableDefId::EnumVariantId(_) => None, |
diff --git a/crates/ra_ide/src/call_info.rs b/crates/ra_ide/src/call_info.rs index a2d23b2ec..35a8a0dc5 100644 --- a/crates/ra_ide/src/call_info.rs +++ b/crates/ra_ide/src/call_info.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | //! FIXME: write short doc here | 1 | //! FIXME: write short doc here |
2 | use either::Either; | ||
2 | use hir::{Docs, HirDisplay, Semantics, Type}; | 3 | use hir::{Docs, HirDisplay, Semantics, Type}; |
3 | use ra_ide_db::RootDatabase; | 4 | use ra_ide_db::RootDatabase; |
4 | use ra_syntax::{ | 5 | use ra_syntax::{ |
@@ -80,7 +81,10 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal | |||
80 | for (pat, ty) in callable.params(db) { | 81 | for (pat, ty) in callable.params(db) { |
81 | buf.clear(); | 82 | buf.clear(); |
82 | if let Some(pat) = pat { | 83 | 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 | } | ||
84 | } | 88 | } |
85 | format_to!(buf, "{}", ty.display(db)); | 89 | format_to!(buf, "{}", ty.display(db)); |
86 | res.push_param(&buf); | 90 | res.push_param(&buf); |
@@ -383,21 +387,38 @@ fn bar() { | |||
383 | check( | 387 | check( |
384 | r#" | 388 | r#" |
385 | struct S; | 389 | struct S; |
386 | impl S { pub fn do_it(&self, x: i32) {} } | 390 | impl S { |
387 | 391 | fn foo(&self, x: i32) {} | |
388 | fn bar() { | ||
389 | let s: S = S; | ||
390 | s.do_it(<|>); | ||
391 | } | 392 | } |
393 | |||
394 | fn main() { S.foo(<|>); } | ||
392 | "#, | 395 | "#, |
393 | expect![[r#" | 396 | expect![[r#" |
394 | fn do_it(&self, x: i32) | 397 | fn foo(&self, x: i32) |
395 | (<x: i32>) | 398 | (<x: i32>) |
396 | "#]], | 399 | "#]], |
397 | ); | 400 | ); |
398 | } | 401 | } |
399 | 402 | ||
400 | #[test] | 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 | |||
421 | #[test] | ||
401 | fn test_fn_signature_with_docs_simple() { | 422 | fn test_fn_signature_with_docs_simple() { |
402 | check( | 423 | check( |
403 | r#" | 424 | r#" |