From 6da22ed9752b239fcd4e7c75673907ceb1ac6b65 Mon Sep 17 00:00:00 2001
From: Aleksey Kladov <aleksey.kladov@gmail.com>
Date: Thu, 16 Jul 2020 18:24:26 +0200
Subject: Redner self as param for call infor for assoc fn call

---
 crates/ra_hir/src/code_model.rs | 14 ++++++++++++--
 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 {
         let param_list = src.value.param_list()?;
         param_list.self_param()
     }
-    pub fn params(&self, db: &dyn HirDatabase) -> Vec<(Option<ast::Pat>, Type)> {
+    pub fn params(
+        &self,
+        db: &dyn HirDatabase,
+    ) -> Vec<(Option<Either<ast::SelfParam, ast::Pat>>, Type)> {
         let types = self
             .sig
             .params()
@@ -1562,7 +1565,14 @@ impl Callable {
         let patterns = match self.id {
             CallableDefId::FunctionId(func) => {
                 let src = func.lookup(db.upcast()).source(db.upcast());
-                src.value.param_list().map(|it| it.params().map(|it| it.pat()))
+                src.value.param_list().map(|param_list| {
+                    param_list
+                        .self_param()
+                        .map(|it| Some(Either::Left(it)))
+                        .filter(|_| !self.is_bound_method)
+                        .into_iter()
+                        .chain(param_list.params().map(|it| it.pat().map(Either::Right)))
+                })
             }
             CallableDefId::StructId(_) => None,
             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 @@
 //! FIXME: write short doc here
+use either::Either;
 use hir::{Docs, HirDisplay, Semantics, Type};
 use ra_ide_db::RootDatabase;
 use ra_syntax::{
@@ -80,7 +81,10 @@ pub(crate) fn call_info(db: &RootDatabase, position: FilePosition) -> Option<Cal
         for (pat, ty) in callable.params(db) {
             buf.clear();
             if let Some(pat) = pat {
-                format_to!(buf, "{}: ", pat);
+                match pat {
+                    Either::Left(_self) => format_to!(buf, "self: "),
+                    Either::Right(pat) => format_to!(buf, "{}: ", pat),
+                }
             }
             format_to!(buf, "{}", ty.display(db));
             res.push_param(&buf);
@@ -383,20 +387,37 @@ fn bar() {
         check(
             r#"
 struct S;
-impl S { pub fn do_it(&self, x: i32) {} }
-
-fn bar() {
-    let s: S = S;
-    s.do_it(<|>);
+impl S {
+    fn foo(&self, x: i32) {}
 }
+
+fn main() { S.foo(<|>); }
 "#,
             expect![[r#"
-                fn do_it(&self, x: i32)
+                fn foo(&self, x: i32)
                 (<x: i32>)
             "#]],
         );
     }
 
+    #[test]
+    fn test_fn_signature_for_method_with_arg_as_assoc_fn() {
+        check(
+            r#"
+struct S;
+impl S {
+    fn foo(&self, x: i32) {}
+}
+
+fn main() { S::foo(<|>); }
+"#,
+            expect![[r#"
+                fn foo(self: &S, x: i32)
+                (<self: &S>, x: i32)
+            "#]],
+        );
+    }
+
     #[test]
     fn test_fn_signature_with_docs_simple() {
         check(
-- 
cgit v1.2.3