mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 05:15:04 +00:00
Redner self as param for call infor for assoc fn call
This commit is contained in:
parent
a4e9681c79
commit
6da22ed975
2 changed files with 40 additions and 9 deletions
|
@ -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,
|
||||
|
|
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue