From 02a17cdffcfdea49981b4642be3027e564d28d9b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Jan 2021 18:58:50 +0300 Subject: Make assertion failures more annoying for maintainers --- crates/rust-analyzer/src/bin/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/crates/rust-analyzer/src/bin/main.rs b/crates/rust-analyzer/src/bin/main.rs index 2f7f94a39..1d6e5478b 100644 --- a/crates/rust-analyzer/src/bin/main.rs +++ b/crates/rust-analyzer/src/bin/main.rs @@ -76,7 +76,12 @@ fn setup_logging(log_file: Option) -> Result<()> { profile::init(); if !cfg!(debug_assertions) { - stdx::set_assert_hook(|loc, args| log::error!("assertion failed at {}: {}", loc, args)); + stdx::set_assert_hook(|loc, args| { + if env::var("RA_PROFILE").is_ok() { + panic!("assertion failed at {}: {}", loc, args) + } + log::error!("assertion failed at {}: {}", loc, args) + }); } Ok(()) -- cgit v1.2.3 From a40f78f92ad2050d6178dfd70374701c6bc826ae Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Jan 2021 18:59:22 +0300 Subject: 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 --- crates/completion/src/completions/dot.rs | 22 ++++----- crates/completion/src/completions/flyimport.rs | 16 +++---- .../completion/src/completions/qualified_path.rs | 54 +++++++++++----------- crates/completion/src/completions/trait_impl.rs | 5 -- .../completion/src/completions/unqualified_path.rs | 50 ++++++++++---------- crates/completion/src/item.rs | 3 +- crates/completion/src/lib.rs | 9 ++-- crates/completion/src/render.rs | 12 ++--- crates/completion/src/render/function.rs | 7 +-- 9 files changed, 85 insertions(+), 93 deletions(-) diff --git a/crates/completion/src/completions/dot.rs b/crates/completion/src/completions/dot.rs index d04eef65a..0880a3830 100644 --- a/crates/completion/src/completions/dot.rs +++ b/crates/completion/src/completions/dot.rs @@ -83,7 +83,7 @@ fn foo(s: S) { s.$0 } "#, expect![[r#" fd foo u32 - me bar() fn bar(&self) + me bar() -> () "#]], ); } @@ -99,7 +99,7 @@ impl S { "#, expect![[r#" fd the_field (u32,) - me foo() fn foo(self) + me foo() -> () "#]], ) } @@ -115,7 +115,7 @@ impl A { "#, expect![[r#" fd the_field (u32, i32) - me foo() fn foo(&self) + me foo() -> () "#]], ) } @@ -165,7 +165,7 @@ mod m { fn foo(a: A) { a.$0 } "#, expect![[r#" - me the_method() pub(crate) fn the_method(&self) + me the_method() -> () "#]], ); } @@ -198,7 +198,7 @@ impl A { fn foo(a: A) { a.$0 } "#, 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 } "#, expect![[r#" - me the_method() fn the_method(&self) + me the_method() -> () "#]], ); } @@ -228,7 +228,7 @@ impl Trait for T {} fn foo(a: &A) { a.$0 } ", 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 } ", expect![[r#" - me the_method() fn the_method(&self) + me the_method() -> () "#]], ); } @@ -300,7 +300,7 @@ impl T { } "#, expect![[r#" - me blah() pub fn blah(&self) + me blah() -> () "#]], ); } @@ -409,7 +409,7 @@ fn foo() { } "#, 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; } "#, expect![[r#" - me foo() fn foo(&self) + me foo() -> () "#]], ) } diff --git a/crates/completion/src/completions/flyimport.rs b/crates/completion/src/completions/flyimport.rs index dc0b38a16..6591127b1 100644 --- a/crates/completion/src/completions/flyimport.rs +++ b/crates/completion/src/completions/flyimport.rs @@ -366,8 +366,8 @@ fn main() { check( fixture, expect![[r#" - fn weird_function() (dep::test_mod::TestTrait) fn weird_function() - "#]], + fn weird_function() (dep::test_mod::TestTrait) -> () + "#]], ); check_edit( @@ -459,8 +459,8 @@ fn main() { check( fixture, expect![[r#" - me random_method() (dep::test_mod::TestTrait) fn random_method(&self) - "#]], + me random_method() (dep::test_mod::TestTrait) -> () + "#]], ); check_edit( @@ -629,8 +629,8 @@ fn main() { } "#, expect![[r#" - me random_method() (dep::test_mod::TestTrait) fn random_method(&self) DEPRECATED - "#]], + me random_method() (dep::test_mod::TestTrait) -> () DEPRECATED + "#]], ); check( @@ -660,8 +660,8 @@ fn main() { "#, expect![[r#" 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 + "#]], ); } } diff --git a/crates/completion/src/completions/qualified_path.rs b/crates/completion/src/completions/qualified_path.rs index 33df26761..bbeaab496 100644 --- a/crates/completion/src/completions/qualified_path.rs +++ b/crates/completion/src/completions/qualified_path.rs @@ -359,8 +359,8 @@ impl S { fn foo() { let _ = S::$0 } "#, expect![[r#" - fn a() fn a() - me b(…) fn b(&self) + fn a() -> () + me b(…) -> () ct C const C: i32 = 42; ta T type T = i32; "#]], @@ -387,7 +387,7 @@ mod m { fn foo() { let _ = S::$0 } "#, expect![[r#" - fn public_method() pub(crate) fn public_method() + fn public_method() -> () ct PUBLIC_CONST pub(crate) const PUBLIC_CONST: u32 = 1; ta PublicType pub(crate) type PublicType = u32; "#]], @@ -404,7 +404,7 @@ impl E { fn m() { } } fn foo() { let _ = E::$0 } "#, expect![[r#" - fn m() fn m() + fn m() -> () "#]], ); } @@ -419,7 +419,7 @@ impl U { fn m() { } } fn foo() { let _ = U::$0 } "#, expect![[r#" - fn m() fn m() + fn m() -> () "#]], ); } @@ -449,7 +449,7 @@ trait Trait { fn m(); } fn foo() { let _ = Trait::$0 } "#, expect![[r#" - fn m() fn m() + fn m() -> () "#]], ); } @@ -466,7 +466,7 @@ impl Trait for S {} fn foo() { let _ = S::$0 } "#, expect![[r#" - fn m() fn m() + fn m() -> () "#]], ); } @@ -483,7 +483,7 @@ impl Trait for S {} fn foo() { let _ = ::$0 } "#, expect![[r#" - fn m() fn m() + fn m() -> () "#]], ); } @@ -512,11 +512,11 @@ fn foo() { T::$0 } ta SubTy type SubTy; ta Ty type Ty; ct C2 const C2: (); - fn subfunc() fn subfunc() - me submethod(…) fn submethod(&self) + fn subfunc() -> () + me submethod(…) -> () ct CONST const CONST: u8; - fn func() fn func() - me method(…) fn method(&self) + fn func() -> () + me method(…) -> () "#]], ); } @@ -552,11 +552,11 @@ impl Sub for Wrap { ta SubTy type SubTy; ta Ty type Ty; ct CONST const CONST: u8 = 0; - fn func() fn func() - me method(…) fn method(&self) + fn func() -> () + me method(…) -> () ct C2 const C2: () = (); - fn subfunc() fn subfunc() - me submethod(…) fn submethod(&self) + fn subfunc() -> () + me submethod(…) -> () "#]], ); } @@ -573,8 +573,8 @@ impl T { fn bar() {} } fn main() { T::$0; } "#, expect![[r#" - fn foo() fn foo() - fn bar() fn bar() + fn foo() -> () + fn bar() -> () "#]], ); } @@ -589,7 +589,7 @@ macro_rules! foo { () => {} } fn main() { let _ = crate::$0 } "#, expect![[r##" - fn main() fn main() + fn main() -> () ma foo!(…) #[macro_export] macro_rules! foo "##]], ); @@ -633,7 +633,7 @@ mod p { "#, expect![[r#" ct RIGHT_CONST - fn right_fn() fn wrong_fn() + fn right_fn() -> () st RightType "#]], ); @@ -680,8 +680,8 @@ fn main() { m!(self::f$0); } fn foo() {} "#, expect![[r#" - fn main() fn main() - fn foo() fn foo() + fn main() -> () + fn foo() -> () "#]], ); } @@ -699,7 +699,7 @@ mod m { "#, expect![[r#" md z - fn z() pub fn z() + fn z() -> () "#]], ); } @@ -719,7 +719,7 @@ fn foo() { } "#, expect![[r#" - fn new() pub fn new() -> HashMap + fn new() -> HashMap "#]], ); } @@ -752,8 +752,8 @@ fn main() { } "#, expect![[r#" - fn main() fn main() - fn foo(…) fn foo(a: i32, b: i32) + fn main() -> () + fn foo(…) -> () "#]], ); } @@ -776,7 +776,7 @@ impl Foo { expect![[r#" ev Bar () ev Baz () - me foo(…) fn foo(self) + me foo(…) -> () "#]], ); } diff --git a/crates/completion/src/completions/trait_impl.rs b/crates/completion/src/completions/trait_impl.rs index f258ad9c3..b999540b8 100644 --- a/crates/completion/src/completions/trait_impl.rs +++ b/crates/completion/src/completions/trait_impl.rs @@ -679,11 +679,6 @@ impl Test for () { #[test] fn complete_without_name() { let test = |completion: &str, hint: &str, completed: &str, next_sibling: &str| { - println!( - "completion='{}', hint='{}', next_sibling='{}'", - completion, hint, next_sibling - ); - check_edit( completion, &format!( diff --git a/crates/completion/src/completions/unqualified_path.rs b/crates/completion/src/completions/unqualified_path.rs index a289efc34..5d62fab97 100644 --- a/crates/completion/src/completions/unqualified_path.rs +++ b/crates/completion/src/completions/unqualified_path.rs @@ -167,7 +167,7 @@ fn quux(x: i32) { expect![[r#" lc y i32 lc x i32 - fn quux(…) fn quux(x: i32) + fn quux(…) -> () "#]], ); } @@ -189,7 +189,7 @@ fn quux() { expect![[r#" lc b i32 lc a - fn quux() fn quux() + fn quux() -> () "#]], ); } @@ -204,7 +204,7 @@ fn quux() { "#, expect![[r#" lc x - fn quux() fn quux() + fn quux() -> () "#]], ); } @@ -235,14 +235,14 @@ fn main() { r#"fn quux() { $0 }"#, expect![[r#" tp T - fn quux() fn quux() + fn quux() -> () "#]], ); check( r#"fn quux() { $0 }"#, expect![[r#" cp C - fn quux() fn quux() + fn quux() -> () "#]], ); } @@ -253,7 +253,7 @@ fn main() { check( r#"fn quux<'a>() { $0 }"#, expect![[r#" - fn quux() fn quux<'a>() + fn quux() -> () "#]], ); } @@ -291,7 +291,7 @@ fn quux() { $0 } "#, expect![[r#" st S - fn quux() fn quux() + fn quux() -> () en E "#]], ); @@ -344,7 +344,7 @@ mod m { } "#, expect![[r#" - fn quux() fn quux() + fn quux() -> () st Bar "#]], ); @@ -359,7 +359,7 @@ fn x() -> $0 "#, expect![[r#" st Foo - fn x() fn x() + fn x() -> () "#]], ); } @@ -380,7 +380,7 @@ fn foo() { expect![[r#" lc bar i32 lc bar i32 - fn foo() fn foo() + fn foo() -> () "#]], ); } @@ -410,7 +410,7 @@ use prelude::*; mod prelude { struct Option; } "#, expect![[r#" - fn foo() fn foo() + fn foo() -> () md std st Option "#]], @@ -440,7 +440,7 @@ mod macros { } "#, expect![[r##" - fn f() fn f() + fn f() -> () ma concat!(…) #[macro_export] macro_rules! concat md std "##]], @@ -467,7 +467,7 @@ use prelude::*; mod prelude { struct String; } "#, expect![[r#" - fn foo() fn foo() + fn foo() -> () md std md core st String @@ -498,7 +498,7 @@ fn main() { let v = $0 } expect![[r##" md m1 ma baz!(…) #[macro_export] macro_rules! baz - fn main() fn main() + fn main() -> () md m2 ma bar!(…) macro_rules! bar ma foo!(…) macro_rules! foo @@ -514,7 +514,7 @@ macro_rules! foo { () => {} } fn foo() { $0 } "#, expect![[r#" - fn foo() fn foo() + fn foo() -> () ma foo!(…) macro_rules! foo "#]], ); @@ -528,7 +528,7 @@ macro_rules! foo { () => {} } fn main() { let x: $0 } "#, expect![[r#" - fn main() fn main() + fn main() -> () ma foo!(…) macro_rules! foo "#]], ); @@ -542,7 +542,7 @@ macro_rules! foo { () => {} } fn main() { $0 } "#, expect![[r#" - fn main() fn main() + fn main() -> () ma foo!(…) macro_rules! foo "#]], ); @@ -558,8 +558,8 @@ fn main() { } "#, expect![[r#" - fn frobnicate() fn frobnicate() - fn main() fn main() + fn frobnicate() -> () + fn main() -> () "#]], ); } @@ -577,7 +577,7 @@ fn quux(x: i32) { expect![[r#" lc y i32 lc x i32 - fn quux(…) fn quux(x: i32) + fn quux(…) -> () ma m!(…) macro_rules! m "#]], ); @@ -596,7 +596,7 @@ fn quux(x: i32) { expect![[r#" lc y i32 lc x i32 - fn quux(…) fn quux(x: i32) + fn quux(…) -> () ma m!(…) macro_rules! m "#]], ); @@ -615,7 +615,7 @@ fn quux(x: i32) { expect![[r#" lc y i32 lc x i32 - fn quux(…) fn quux(x: i32) + fn quux(…) -> () ma m!(…) macro_rules! m "#]], ); @@ -630,7 +630,7 @@ use spam::Quux; fn main() { $0 } "#, expect![[r#" - fn main() fn main() + fn main() -> () ?? Quux "#]], ); @@ -708,7 +708,7 @@ fn main() { let foo: Foo = Q$0 } ev Foo::Baz () ev Foo::Quux () en Foo - fn main() fn main() + fn main() -> () "#]], ) } @@ -723,7 +723,7 @@ fn f() -> m::E { V$0 } expect![[r#" ev m::E::V () md m - fn f() fn f() -> m::E + fn f() -> E "#]], ) } diff --git a/crates/completion/src/item.rs b/crates/completion/src/item.rs index d2e6a6aeb..eeb952ec3 100644 --- a/crates/completion/src/item.rs +++ b/crates/completion/src/item.rs @@ -398,14 +398,13 @@ impl Builder { self.insert_text_format = InsertTextFormat::Snippet; self.text_edit(edit) } - #[allow(unused)] pub(crate) fn detail(self, detail: impl Into) -> Builder { self.set_detail(Some(detail)) } pub(crate) fn set_detail(mut self, detail: Option>) -> Builder { self.detail = detail.map(Into::into); 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()); } } diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index 2c4e54524..50329b499 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs @@ -227,7 +227,7 @@ mod tests { 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; } "#, - 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 } "#, - DetailAndDocumentation { - detail: "fn foo() -> &'static str", - documentation: "Do the foo", - }, + DetailAndDocumentation { detail: "-> &str", documentation: "Do the foo" }, ); } } diff --git a/crates/completion/src/render.rs b/crates/completion/src/render.rs index fa594b5e5..6eb20df2b 100644 --- a/crates/completion/src/render.rs +++ b/crates/completion/src/render.rs @@ -523,7 +523,7 @@ fn main() { let _: m::Spam = S$0 } Function, ), lookup: "main", - detail: "fn main()", + detail: "-> ()", }, ] "#]], @@ -552,7 +552,7 @@ fn main() { som$0 } Function, ), lookup: "main", - detail: "fn main()", + detail: "-> ()", }, CompletionItem { label: "something_deprecated()", @@ -563,7 +563,7 @@ fn main() { som$0 } Function, ), lookup: "something_deprecated", - detail: "fn something_deprecated()", + detail: "-> ()", deprecated: true, }, CompletionItem { @@ -575,7 +575,7 @@ fn main() { som$0 } Function, ), lookup: "something_else_deprecated", - detail: "fn something_else_deprecated()", + detail: "-> ()", deprecated: true, }, ] @@ -626,7 +626,7 @@ impl S { insert: "bar()$0", kind: Method, lookup: "bar", - detail: "fn bar(self)", + detail: "-> ()", documentation: Documentation( "Method docs", ), @@ -726,7 +726,7 @@ fn foo(s: S) { s.$0 } insert: "the_method()$0", kind: Method, lookup: "the_method", - detail: "fn the_method(&self)", + detail: "-> ()", }, ] "#]], diff --git a/crates/completion/src/render/function.rs b/crates/completion/src/render/function.rs index 2d616b1fb..e46e21d24 100644 --- a/crates/completion/src/render/function.rs +++ b/crates/completion/src/render/function.rs @@ -1,8 +1,8 @@ //! Renderer for function calls. -use hir::{HasSource, Type}; +use hir::{HasSource, HirDisplay, Type}; use ide_db::SymbolKind; -use syntax::{ast::Fn, display::function_declaration}; +use syntax::ast::Fn; use test_utils::mark; use crate::{ @@ -55,7 +55,8 @@ impl<'a> FunctionRender<'a> { } 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 { -- cgit v1.2.3 From 96197e08730a74bb8d5c724968c99d22aa0ca17a Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 22 Jan 2021 19:05:28 +0300 Subject: Normalize tests --- crates/completion/src/lib.rs | 82 ++++++++++++++++++++------------------------ 1 file changed, 37 insertions(+), 45 deletions(-) diff --git a/crates/completion/src/lib.rs b/crates/completion/src/lib.rs index 50329b499..db8bfbbc3 100644 --- a/crates/completion/src/lib.rs +++ b/crates/completion/src/lib.rs @@ -209,24 +209,23 @@ mod tests { fn test_completion_detail_from_macro_generated_struct_fn_doc_attr() { check_detail_and_documentation( r#" - //- /lib.rs - macro_rules! bar { - () => { - struct Bar; - impl Bar { - #[doc = "Do the foo"] - fn foo(&self) {} - } - } - } +macro_rules! bar { + () => { + struct Bar; + impl Bar { + #[doc = "Do the foo"] + fn foo(&self) {} + } + } +} - bar!(); +bar!(); - fn foo() { - let bar = Bar; - bar.fo$0; - } - "#, +fn foo() { + let bar = Bar; + bar.fo$0; +} +"#, DetailAndDocumentation { detail: "-> ()", documentation: "Do the foo" }, ); } @@ -235,24 +234,23 @@ mod tests { fn test_completion_detail_from_macro_generated_struct_fn_doc_comment() { check_detail_and_documentation( r#" - //- /lib.rs - macro_rules! bar { - () => { - struct Bar; - impl Bar { - /// Do the foo - fn foo(&self) {} - } - } - } +macro_rules! bar { + () => { + struct Bar; + impl Bar { + /// Do the foo + fn foo(&self) {} + } + } +} - bar!(); +bar!(); - fn foo() { - let bar = Bar; - bar.fo$0; - } - "#, +fn foo() { + let bar = Bar; + bar.fo$0; +} +"#, DetailAndDocumentation { detail: "-> ()", documentation: " Do the foo" }, ); } @@ -260,23 +258,17 @@ mod tests { #[test] fn test_no_completions_required() { // There must be no hint for 'in' keyword. - check_no_completion( - r#" - fn foo() { - for i i$0 - } - "#, - ); + check_no_completion(r#"fn foo() { for i i$0 }"#); // After 'in' keyword hints may be spawned. check_detail_and_documentation( r#" - /// Do the foo - fn foo() -> &'static str { "foo" } +/// Do the foo +fn foo() -> &'static str { "foo" } - fn bar() { - for c in fo$0 - } - "#, +fn bar() { + for c in fo$0 +} +"#, DetailAndDocumentation { detail: "-> &str", documentation: "Do the foo" }, ); } -- cgit v1.2.3