More useful fn detail in completion

Detail should be rendered as shtort one line, just dumping fn header
there is not useful, despite the fact that TS does this.

The fact that this is a function should be indicated by the icon, the
same goes for pub/const/async etc qualitfiers

name is already present in the lable (and arg list should be a part of
that, as in idea)

But the return type is the small genuinerlly useful bit of info we can show here
This commit is contained in:
Aleksey Kladov 2021-01-22 18:59:22 +03:00
parent 02a17cdffc
commit a40f78f92a
9 changed files with 85 additions and 93 deletions

View file

@ -83,7 +83,7 @@ fn foo(s: S) { s.$0 }
"#, "#,
expect![[r#" expect![[r#"
fd foo u32 fd foo u32
me bar() fn bar(&self) me bar() -> ()
"#]], "#]],
); );
} }
@ -99,7 +99,7 @@ impl S {
"#, "#,
expect![[r#" expect![[r#"
fd the_field (u32,) fd the_field (u32,)
me foo() fn foo(self) me foo() -> ()
"#]], "#]],
) )
} }
@ -115,7 +115,7 @@ impl A {
"#, "#,
expect![[r#" expect![[r#"
fd the_field (u32, i32) fd the_field (u32, i32)
me foo() fn foo(&self) me foo() -> ()
"#]], "#]],
) )
} }
@ -165,7 +165,7 @@ mod m {
fn foo(a: A) { a.$0 } fn foo(a: A) { a.$0 }
"#, "#,
expect![[r#" expect![[r#"
me the_method() pub(crate) fn the_method(&self) me the_method() -> ()
"#]], "#]],
); );
} }
@ -198,7 +198,7 @@ impl A<i32> {
fn foo(a: A<u32>) { a.$0 } fn foo(a: A<u32>) { a.$0 }
"#, "#,
expect![[r#" expect![[r#"
me the_method() fn the_method(&self) me the_method() -> ()
"#]], "#]],
) )
} }
@ -213,7 +213,7 @@ impl Trait for A {}
fn foo(a: A) { a.$0 } fn foo(a: A) { a.$0 }
"#, "#,
expect![[r#" expect![[r#"
me the_method() fn the_method(&self) me the_method() -> ()
"#]], "#]],
); );
} }
@ -228,7 +228,7 @@ impl<T> Trait for T {}
fn foo(a: &A) { a.$0 } fn foo(a: &A) { a.$0 }
", ",
expect![[r#" expect![[r#"
me the_method() fn the_method(&self) me the_method() -> ()
"#]], "#]],
); );
} }
@ -246,7 +246,7 @@ impl Trait for A {}
fn foo(a: A) { a.$0 } fn foo(a: A) { a.$0 }
", ",
expect![[r#" expect![[r#"
me the_method() fn the_method(&self) me the_method() -> ()
"#]], "#]],
); );
} }
@ -300,7 +300,7 @@ impl T {
} }
"#, "#,
expect![[r#" expect![[r#"
me blah() pub fn blah(&self) me blah() -> ()
"#]], "#]],
); );
} }
@ -409,7 +409,7 @@ fn foo() {
} }
"#, "#,
expect![[r#" expect![[r#"
me the_method() pub fn the_method(&self) me the_method() -> ()
"#]], "#]],
); );
} }
@ -424,7 +424,7 @@ macro_rules! make_s { () => { S }; }
fn main() { make_s!().f$0; } fn main() { make_s!().f$0; }
"#, "#,
expect![[r#" expect![[r#"
me foo() fn foo(&self) me foo() -> ()
"#]], "#]],
) )
} }

View file

@ -366,8 +366,8 @@ fn main() {
check( check(
fixture, fixture,
expect![[r#" expect![[r#"
fn weird_function() (dep::test_mod::TestTrait) fn weird_function() fn weird_function() (dep::test_mod::TestTrait) -> ()
"#]], "#]],
); );
check_edit( check_edit(
@ -459,8 +459,8 @@ fn main() {
check( check(
fixture, fixture,
expect![[r#" expect![[r#"
me random_method() (dep::test_mod::TestTrait) fn random_method(&self) me random_method() (dep::test_mod::TestTrait) -> ()
"#]], "#]],
); );
check_edit( check_edit(
@ -629,8 +629,8 @@ fn main() {
} }
"#, "#,
expect![[r#" expect![[r#"
me random_method() (dep::test_mod::TestTrait) fn random_method(&self) DEPRECATED me random_method() (dep::test_mod::TestTrait) -> () DEPRECATED
"#]], "#]],
); );
check( check(
@ -660,8 +660,8 @@ fn main() {
"#, "#,
expect![[r#" expect![[r#"
ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED ct SPECIAL_CONST (dep::test_mod::TestTrait) DEPRECATED
fn weird_function() (dep::test_mod::TestTrait) fn weird_function() DEPRECATED fn weird_function() (dep::test_mod::TestTrait) -> () DEPRECATED
"#]], "#]],
); );
} }
} }

View file

@ -359,8 +359,8 @@ impl S {
fn foo() { let _ = S::$0 } fn foo() { let _ = S::$0 }
"#, "#,
expect![[r#" expect![[r#"
fn a() fn a() fn a() -> ()
me b() fn b(&self) me b() -> ()
ct C const C: i32 = 42; ct C const C: i32 = 42;
ta T type T = i32; ta T type T = i32;
"#]], "#]],
@ -387,7 +387,7 @@ mod m {
fn foo() { let _ = S::$0 } fn foo() { let _ = S::$0 }
"#, "#,
expect![[r#" expect![[r#"
fn public_method() pub(crate) fn public_method() fn public_method() -> ()
ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1;
ta PublicType pub(crate) type PublicType = u32; ta PublicType pub(crate) type PublicType = u32;
"#]], "#]],
@ -404,7 +404,7 @@ impl E { fn m() { } }
fn foo() { let _ = E::$0 } fn foo() { let _ = E::$0 }
"#, "#,
expect![[r#" expect![[r#"
fn m() fn m() fn m() -> ()
"#]], "#]],
); );
} }
@ -419,7 +419,7 @@ impl U { fn m() { } }
fn foo() { let _ = U::$0 } fn foo() { let _ = U::$0 }
"#, "#,
expect![[r#" expect![[r#"
fn m() fn m() fn m() -> ()
"#]], "#]],
); );
} }
@ -449,7 +449,7 @@ trait Trait { fn m(); }
fn foo() { let _ = Trait::$0 } fn foo() { let _ = Trait::$0 }
"#, "#,
expect![[r#" expect![[r#"
fn m() fn m() fn m() -> ()
"#]], "#]],
); );
} }
@ -466,7 +466,7 @@ impl Trait for S {}
fn foo() { let _ = S::$0 } fn foo() { let _ = S::$0 }
"#, "#,
expect![[r#" expect![[r#"
fn m() fn m() fn m() -> ()
"#]], "#]],
); );
} }
@ -483,7 +483,7 @@ impl Trait for S {}
fn foo() { let _ = <S as Trait>::$0 } fn foo() { let _ = <S as Trait>::$0 }
"#, "#,
expect![[r#" expect![[r#"
fn m() fn m() fn m() -> ()
"#]], "#]],
); );
} }
@ -512,11 +512,11 @@ fn foo<T: Sub>() { T::$0 }
ta SubTy type SubTy; ta SubTy type SubTy;
ta Ty type Ty; ta Ty type Ty;
ct C2 const C2: (); ct C2 const C2: ();
fn subfunc() fn subfunc() fn subfunc() -> ()
me submethod() fn submethod(&self) me submethod() -> ()
ct CONST const CONST: u8; ct CONST const CONST: u8;
fn func() fn func() fn func() -> ()
me method() fn method(&self) me method() -> ()
"#]], "#]],
); );
} }
@ -552,11 +552,11 @@ impl<T> Sub for Wrap<T> {
ta SubTy type SubTy; ta SubTy type SubTy;
ta Ty type Ty; ta Ty type Ty;
ct CONST const CONST: u8 = 0; ct CONST const CONST: u8 = 0;
fn func() fn func() fn func() -> ()
me method() fn method(&self) me method() -> ()
ct C2 const C2: () = (); ct C2 const C2: () = ();
fn subfunc() fn subfunc() fn subfunc() -> ()
me submethod() fn submethod(&self) me submethod() -> ()
"#]], "#]],
); );
} }
@ -573,8 +573,8 @@ impl T { fn bar() {} }
fn main() { T::$0; } fn main() { T::$0; }
"#, "#,
expect![[r#" expect![[r#"
fn foo() fn foo() fn foo() -> ()
fn bar() fn bar() fn bar() -> ()
"#]], "#]],
); );
} }
@ -589,7 +589,7 @@ macro_rules! foo { () => {} }
fn main() { let _ = crate::$0 } fn main() { let _ = crate::$0 }
"#, "#,
expect![[r##" expect![[r##"
fn main() fn main() fn main() -> ()
ma foo!() #[macro_export] macro_rules! foo ma foo!() #[macro_export] macro_rules! foo
"##]], "##]],
); );
@ -633,7 +633,7 @@ mod p {
"#, "#,
expect![[r#" expect![[r#"
ct RIGHT_CONST ct RIGHT_CONST
fn right_fn() fn wrong_fn() fn right_fn() -> ()
st RightType st RightType
"#]], "#]],
); );
@ -680,8 +680,8 @@ fn main() { m!(self::f$0); }
fn foo() {} fn foo() {}
"#, "#,
expect![[r#" expect![[r#"
fn main() fn main() fn main() -> ()
fn foo() fn foo() fn foo() -> ()
"#]], "#]],
); );
} }
@ -699,7 +699,7 @@ mod m {
"#, "#,
expect![[r#" expect![[r#"
md z md z
fn z() pub fn z() fn z() -> ()
"#]], "#]],
); );
} }
@ -719,7 +719,7 @@ fn foo() {
} }
"#, "#,
expect![[r#" expect![[r#"
fn new() pub fn new() -> HashMap<K, V, RandomState> fn new() -> HashMap<K, V, RandomState>
"#]], "#]],
); );
} }
@ -752,8 +752,8 @@ fn main() {
} }
"#, "#,
expect![[r#" expect![[r#"
fn main() fn main() fn main() -> ()
fn foo() fn foo(a: i32, b: i32) fn foo() -> ()
"#]], "#]],
); );
} }
@ -776,7 +776,7 @@ impl Foo {
expect![[r#" expect![[r#"
ev Bar () ev Bar ()
ev Baz () ev Baz ()
me foo() fn foo(self) me foo() -> ()
"#]], "#]],
); );
} }

View file

@ -679,11 +679,6 @@ impl Test for () {
#[test] #[test]
fn complete_without_name() { fn complete_without_name() {
let test = |completion: &str, hint: &str, completed: &str, next_sibling: &str| { let test = |completion: &str, hint: &str, completed: &str, next_sibling: &str| {
println!(
"completion='{}', hint='{}', next_sibling='{}'",
completion, hint, next_sibling
);
check_edit( check_edit(
completion, completion,
&format!( &format!(

View file

@ -167,7 +167,7 @@ fn quux(x: i32) {
expect![[r#" expect![[r#"
lc y i32 lc y i32
lc x i32 lc x i32
fn quux() fn quux(x: i32) fn quux() -> ()
"#]], "#]],
); );
} }
@ -189,7 +189,7 @@ fn quux() {
expect![[r#" expect![[r#"
lc b i32 lc b i32
lc a lc a
fn quux() fn quux() fn quux() -> ()
"#]], "#]],
); );
} }
@ -204,7 +204,7 @@ fn quux() {
"#, "#,
expect![[r#" expect![[r#"
lc x lc x
fn quux() fn quux() fn quux() -> ()
"#]], "#]],
); );
} }
@ -235,14 +235,14 @@ fn main() {
r#"fn quux<T>() { $0 }"#, r#"fn quux<T>() { $0 }"#,
expect![[r#" expect![[r#"
tp T tp T
fn quux() fn quux<T>() fn quux() -> ()
"#]], "#]],
); );
check( check(
r#"fn quux<const C: usize>() { $0 }"#, r#"fn quux<const C: usize>() { $0 }"#,
expect![[r#" expect![[r#"
cp C cp C
fn quux() fn quux<const C: usize>() fn quux() -> ()
"#]], "#]],
); );
} }
@ -253,7 +253,7 @@ fn main() {
check( check(
r#"fn quux<'a>() { $0 }"#, r#"fn quux<'a>() { $0 }"#,
expect![[r#" expect![[r#"
fn quux() fn quux<'a>() fn quux() -> ()
"#]], "#]],
); );
} }
@ -291,7 +291,7 @@ fn quux() { $0 }
"#, "#,
expect![[r#" expect![[r#"
st S st S
fn quux() fn quux() fn quux() -> ()
en E en E
"#]], "#]],
); );
@ -344,7 +344,7 @@ mod m {
} }
"#, "#,
expect![[r#" expect![[r#"
fn quux() fn quux() fn quux() -> ()
st Bar st Bar
"#]], "#]],
); );
@ -359,7 +359,7 @@ fn x() -> $0
"#, "#,
expect![[r#" expect![[r#"
st Foo st Foo
fn x() fn x() fn x() -> ()
"#]], "#]],
); );
} }
@ -380,7 +380,7 @@ fn foo() {
expect![[r#" expect![[r#"
lc bar i32 lc bar i32
lc bar i32 lc bar i32
fn foo() fn foo() fn foo() -> ()
"#]], "#]],
); );
} }
@ -410,7 +410,7 @@ use prelude::*;
mod prelude { struct Option; } mod prelude { struct Option; }
"#, "#,
expect![[r#" expect![[r#"
fn foo() fn foo() fn foo() -> ()
md std md std
st Option st Option
"#]], "#]],
@ -440,7 +440,7 @@ mod macros {
} }
"#, "#,
expect![[r##" expect![[r##"
fn f() fn f() fn f() -> ()
ma concat!() #[macro_export] macro_rules! concat ma concat!() #[macro_export] macro_rules! concat
md std md std
"##]], "##]],
@ -467,7 +467,7 @@ use prelude::*;
mod prelude { struct String; } mod prelude { struct String; }
"#, "#,
expect![[r#" expect![[r#"
fn foo() fn foo() fn foo() -> ()
md std md std
md core md core
st String st String
@ -498,7 +498,7 @@ fn main() { let v = $0 }
expect![[r##" expect![[r##"
md m1 md m1
ma baz!() #[macro_export] macro_rules! baz ma baz!() #[macro_export] macro_rules! baz
fn main() fn main() fn main() -> ()
md m2 md m2
ma bar!() macro_rules! bar ma bar!() macro_rules! bar
ma foo!() macro_rules! foo ma foo!() macro_rules! foo
@ -514,7 +514,7 @@ macro_rules! foo { () => {} }
fn foo() { $0 } fn foo() { $0 }
"#, "#,
expect![[r#" expect![[r#"
fn foo() fn foo() fn foo() -> ()
ma foo!() macro_rules! foo ma foo!() macro_rules! foo
"#]], "#]],
); );
@ -528,7 +528,7 @@ macro_rules! foo { () => {} }
fn main() { let x: $0 } fn main() { let x: $0 }
"#, "#,
expect![[r#" expect![[r#"
fn main() fn main() fn main() -> ()
ma foo!() macro_rules! foo ma foo!() macro_rules! foo
"#]], "#]],
); );
@ -542,7 +542,7 @@ macro_rules! foo { () => {} }
fn main() { $0 } fn main() { $0 }
"#, "#,
expect![[r#" expect![[r#"
fn main() fn main() fn main() -> ()
ma foo!() macro_rules! foo ma foo!() macro_rules! foo
"#]], "#]],
); );
@ -558,8 +558,8 @@ fn main() {
} }
"#, "#,
expect![[r#" expect![[r#"
fn frobnicate() fn frobnicate() fn frobnicate() -> ()
fn main() fn main() fn main() -> ()
"#]], "#]],
); );
} }
@ -577,7 +577,7 @@ fn quux(x: i32) {
expect![[r#" expect![[r#"
lc y i32 lc y i32
lc x i32 lc x i32
fn quux() fn quux(x: i32) fn quux() -> ()
ma m!() macro_rules! m ma m!() macro_rules! m
"#]], "#]],
); );
@ -596,7 +596,7 @@ fn quux(x: i32) {
expect![[r#" expect![[r#"
lc y i32 lc y i32
lc x i32 lc x i32
fn quux() fn quux(x: i32) fn quux() -> ()
ma m!() macro_rules! m ma m!() macro_rules! m
"#]], "#]],
); );
@ -615,7 +615,7 @@ fn quux(x: i32) {
expect![[r#" expect![[r#"
lc y i32 lc y i32
lc x i32 lc x i32
fn quux() fn quux(x: i32) fn quux() -> ()
ma m!() macro_rules! m ma m!() macro_rules! m
"#]], "#]],
); );
@ -630,7 +630,7 @@ use spam::Quux;
fn main() { $0 } fn main() { $0 }
"#, "#,
expect![[r#" expect![[r#"
fn main() fn main() fn main() -> ()
?? Quux ?? Quux
"#]], "#]],
); );
@ -708,7 +708,7 @@ fn main() { let foo: Foo = Q$0 }
ev Foo::Baz () ev Foo::Baz ()
ev Foo::Quux () ev Foo::Quux ()
en Foo en Foo
fn main() fn main() fn main() -> ()
"#]], "#]],
) )
} }
@ -723,7 +723,7 @@ fn f() -> m::E { V$0 }
expect![[r#" expect![[r#"
ev m::E::V () ev m::E::V ()
md m md m
fn f() fn f() -> m::E fn f() -> E
"#]], "#]],
) )
} }

View file

@ -398,14 +398,13 @@ impl Builder {
self.insert_text_format = InsertTextFormat::Snippet; self.insert_text_format = InsertTextFormat::Snippet;
self.text_edit(edit) self.text_edit(edit)
} }
#[allow(unused)]
pub(crate) fn detail(self, detail: impl Into<String>) -> Builder { pub(crate) fn detail(self, detail: impl Into<String>) -> Builder {
self.set_detail(Some(detail)) self.set_detail(Some(detail))
} }
pub(crate) fn set_detail(mut self, detail: Option<impl Into<String>>) -> Builder { pub(crate) fn set_detail(mut self, detail: Option<impl Into<String>>) -> Builder {
self.detail = detail.map(Into::into); self.detail = detail.map(Into::into);
if let Some(detail) = &self.detail { if let Some(detail) = &self.detail {
if assert_never!(detail.contains('\n'), "multiline detail: {}", detail) { if assert_never!(detail.contains('\n'), "multiline detail:\n{}", detail) {
self.detail = Some(detail.splitn(2, '\n').next().unwrap().to_string()); self.detail = Some(detail.splitn(2, '\n').next().unwrap().to_string());
} }
} }

View file

@ -227,7 +227,7 @@ mod tests {
bar.fo$0; bar.fo$0;
} }
"#, "#,
DetailAndDocumentation { detail: "fn foo(&self)", documentation: "Do the foo" }, DetailAndDocumentation { detail: "-> ()", documentation: "Do the foo" },
); );
} }
@ -253,7 +253,7 @@ mod tests {
bar.fo$0; bar.fo$0;
} }
"#, "#,
DetailAndDocumentation { detail: "fn foo(&self)", documentation: " Do the foo" }, DetailAndDocumentation { detail: "-> ()", documentation: " Do the foo" },
); );
} }
@ -277,10 +277,7 @@ mod tests {
for c in fo$0 for c in fo$0
} }
"#, "#,
DetailAndDocumentation { DetailAndDocumentation { detail: "-> &str", documentation: "Do the foo" },
detail: "fn foo() -> &'static str",
documentation: "Do the foo",
},
); );
} }
} }

View file

@ -523,7 +523,7 @@ fn main() { let _: m::Spam = S$0 }
Function, Function,
), ),
lookup: "main", lookup: "main",
detail: "fn main()", detail: "-> ()",
}, },
] ]
"#]], "#]],
@ -552,7 +552,7 @@ fn main() { som$0 }
Function, Function,
), ),
lookup: "main", lookup: "main",
detail: "fn main()", detail: "-> ()",
}, },
CompletionItem { CompletionItem {
label: "something_deprecated()", label: "something_deprecated()",
@ -563,7 +563,7 @@ fn main() { som$0 }
Function, Function,
), ),
lookup: "something_deprecated", lookup: "something_deprecated",
detail: "fn something_deprecated()", detail: "-> ()",
deprecated: true, deprecated: true,
}, },
CompletionItem { CompletionItem {
@ -575,7 +575,7 @@ fn main() { som$0 }
Function, Function,
), ),
lookup: "something_else_deprecated", lookup: "something_else_deprecated",
detail: "fn something_else_deprecated()", detail: "-> ()",
deprecated: true, deprecated: true,
}, },
] ]
@ -626,7 +626,7 @@ impl S {
insert: "bar()$0", insert: "bar()$0",
kind: Method, kind: Method,
lookup: "bar", lookup: "bar",
detail: "fn bar(self)", detail: "-> ()",
documentation: Documentation( documentation: Documentation(
"Method docs", "Method docs",
), ),
@ -726,7 +726,7 @@ fn foo(s: S) { s.$0 }
insert: "the_method()$0", insert: "the_method()$0",
kind: Method, kind: Method,
lookup: "the_method", lookup: "the_method",
detail: "fn the_method(&self)", detail: "-> ()",
}, },
] ]
"#]], "#]],

View file

@ -1,8 +1,8 @@
//! Renderer for function calls. //! Renderer for function calls.
use hir::{HasSource, Type}; use hir::{HasSource, HirDisplay, Type};
use ide_db::SymbolKind; use ide_db::SymbolKind;
use syntax::{ast::Fn, display::function_declaration}; use syntax::ast::Fn;
use test_utils::mark; use test_utils::mark;
use crate::{ use crate::{
@ -55,7 +55,8 @@ impl<'a> FunctionRender<'a> {
} }
fn detail(&self) -> String { fn detail(&self) -> String {
function_declaration(&self.ast_node) let ty = self.func.ret_type(self.ctx.db());
format!("-> {}", ty.display(self.ctx.db()))
} }
fn add_arg(&self, arg: &str, ty: &Type) -> String { fn add_arg(&self, arg: &str, ty: &Type) -> String {