From 9b2847885de551cb83feaa31356b85e4e53dcda5 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 Jul 2020 11:44:16 +0200 Subject: cleanup --- crates/ra_ide/src/completion/complete_unqualified_path.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'crates/ra_ide/src/completion/complete_unqualified_path.rs') diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index 0d1e9f8ea..790179e5b 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs @@ -1,11 +1,10 @@ //! Completion of names from the current scope, e.g. locals and imported items. -use hir::ScopeDef; +use hir::{Adt, ModuleDef, ScopeDef, Type}; +use ra_syntax::AstNode; use test_utils::mark; use crate::completion::{CompletionContext, Completions}; -use hir::{Adt, ModuleDef, Type}; -use ra_syntax::AstNode; pub(super) fn complete_unqualified_path(acc: &mut Completions, ctx: &CompletionContext) { if !(ctx.is_trivial_path || ctx.is_pat_binding_or_const) { -- cgit v1.2.3 From 5b8a5bfb1528409075438a7259017a0b97515694 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 7 Jul 2020 12:52:09 +0200 Subject: Modernize unqualified reference completion tests --- .../src/completion/complete_unqualified_path.rs | 1598 +++++--------------- 1 file changed, 403 insertions(+), 1195 deletions(-) (limited to 'crates/ra_ide/src/completion/complete_unqualified_path.rs') diff --git a/crates/ra_ide/src/completion/complete_unqualified_path.rs b/crates/ra_ide/src/completion/complete_unqualified_path.rs index 790179e5b..72ff82e66 100644 --- a/crates/ra_ide/src/completion/complete_unqualified_path.rs +++ b/crates/ra_ide/src/completion/complete_unqualified_path.rs @@ -64,1370 +64,578 @@ fn complete_enum_variants(acc: &mut Completions, ctx: &CompletionContext, ty: &T #[cfg(test)] mod tests { - use insta::assert_debug_snapshot; + use expect::{expect, Expect}; use test_utils::mark; - use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; + use crate::completion::{ + test_utils::{check_edit, completion_list}, + CompletionKind, + }; - fn do_reference_completion(ra_fixture: &str) -> Vec { - do_completion(ra_fixture, CompletionKind::Reference) + fn check(ra_fixture: &str, expect: Expect) { + let actual = completion_list(ra_fixture, CompletionKind::Reference); + expect.assert_eq(&actual) } #[test] fn self_fulfilling_completion() { mark::check!(self_fulfilling_completion); - assert_debug_snapshot!( - do_reference_completion( - r#" - use foo<|> - use std::collections; - "#, - ), - @r###" - [ - CompletionItem { - label: "collections", - source_range: 4..7, - delete: 4..7, - insert: "collections", - }, - ] - "### + check( + r#" +use foo<|> +use std::collections; +"#, + expect![[r#" + ?? collections + "#]], ); } #[test] fn bind_pat_and_path_ignore_at() { - assert_debug_snapshot!( - do_reference_completion( - r" - enum Enum { - A, - B, - } - fn quux(x: Option) { - match x { - None => (), - Some(en<|> @ Enum::A) => (), - } - } - " - ), - @"[]" + check( + r#" +enum Enum { A, B } +fn quux(x: Option) { + match x { + None => (), + Some(en<|> @ Enum::A) => (), + } +} +"#, + expect![[""]], ); } #[test] fn bind_pat_and_path_ignore_ref() { - assert_debug_snapshot!( - do_reference_completion( - r" - enum Enum { - A, - B, - } - fn quux(x: Option) { - match x { - None => (), - Some(ref en<|>) => (), - } - } - " - ), - @r###"[]"### + check( + r#" +enum Enum { A, B } +fn quux(x: Option) { + match x { + None => (), + Some(ref en<|>) => (), + } +} +"#, + expect![[""]], ); } #[test] fn bind_pat_and_path() { - assert_debug_snapshot!( - do_reference_completion( - r" - enum Enum { - A, - B, - } - fn quux(x: Option) { - match x { - None => (), - Some(En<|>) => (), - } - } - " - ), - @r###" - [ - CompletionItem { - label: "Enum", - source_range: 102..104, - delete: 102..104, - insert: "Enum", - kind: Enum, - }, - ] - "### + check( + r#" +enum Enum { A, B } +fn quux(x: Option) { + match x { + None => (), + Some(En<|>) => (), + } +} +"#, + expect![[r#" + en Enum + "#]], ); } #[test] fn completes_bindings_from_let() { - assert_debug_snapshot!( - do_reference_completion( - r" - fn quux(x: i32) { - let y = 92; - 1 + <|>; - let z = (); - } - " - ), - @r###" - [ - CompletionItem { - label: "quux(…)", - source_range: 42..42, - delete: 42..42, - insert: "quux(${1:x})$0", - kind: Function, - lookup: "quux", - detail: "fn quux(x: i32)", - trigger_call_info: true, - }, - CompletionItem { - label: "x", - source_range: 42..42, - delete: 42..42, - insert: "x", - kind: Binding, - detail: "i32", - }, - CompletionItem { - label: "y", - source_range: 42..42, - delete: 42..42, - insert: "y", - kind: Binding, - detail: "i32", - }, - ] - "### + check( + r#" +fn quux(x: i32) { + let y = 92; + 1 + <|>; + let z = (); +} +"#, + expect![[r#" + fn quux(…) fn quux(x: i32) + bn x i32 + bn y i32 + "#]], ); } #[test] fn completes_bindings_from_if_let() { - assert_debug_snapshot!( - do_reference_completion( - r" - fn quux() { - if let Some(x) = foo() { - let y = 92; - }; - if let Some(a) = bar() { - let b = 62; - 1 + <|> - } - } - " - ), - @r###" - [ - CompletionItem { - label: "a", - source_range: 129..129, - delete: 129..129, - insert: "a", - kind: Binding, - }, - CompletionItem { - label: "b", - source_range: 129..129, - delete: 129..129, - insert: "b", - kind: Binding, - detail: "i32", - }, - CompletionItem { - label: "quux()", - source_range: 129..129, - delete: 129..129, - insert: "quux()$0", - kind: Function, - lookup: "quux", - detail: "fn quux()", - }, - ] - "### + check( + r#" +fn quux() { + if let Some(x) = foo() { + let y = 92; + }; + if let Some(a) = bar() { + let b = 62; + 1 + <|> + } +} +"#, + expect![[r#" + bn a + bn b i32 + fn quux() fn quux() + "#]], ); } #[test] fn completes_bindings_from_for() { - assert_debug_snapshot!( - do_reference_completion( - r" - fn quux() { - for x in &[1, 2, 3] { - <|> - } - } - " - ), - @r###" - [ - CompletionItem { - label: "quux()", - source_range: 46..46, - delete: 46..46, - insert: "quux()$0", - kind: Function, - lookup: "quux", - detail: "fn quux()", - }, - CompletionItem { - label: "x", - source_range: 46..46, - delete: 46..46, - insert: "x", - kind: Binding, - }, - ] - "### + check( + r#" +fn quux() { + for x in &[1, 2, 3] { <|> } +} +"#, + expect![[r#" + fn quux() fn quux() + bn x + "#]], ); } #[test] - fn completes_bindings_from_for_with_in_prefix() { - mark::check!(completes_bindings_from_for_with_in_prefix); - assert_debug_snapshot!( - do_reference_completion( - r" - fn test() { - for index in &[1, 2, 3] { - let t = in<|> - } - } - " - ), - @r###" - [ - CompletionItem { - label: "index", - source_range: 58..58, - delete: 58..58, - insert: "index", - kind: Binding, - }, - CompletionItem { - label: "test()", - source_range: 58..58, - delete: 58..58, - insert: "test()$0", - kind: Function, - lookup: "test", - detail: "fn test()", - }, - ] - "### - ); + fn completes_if_prefix_is_keyword() { + mark::check!(completes_if_prefix_is_keyword); + check_edit( + "wherewolf", + r#" +fn main() { + let wherewolf = 92; + drop(where<|>) +} +"#, + r#" +fn main() { + let wherewolf = 92; + drop(wherewolf) +} +"#, + ) } #[test] fn completes_generic_params() { - assert_debug_snapshot!( - do_reference_completion( - r" - fn quux() { - <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "T", - source_range: 19..19, - delete: 19..19, - insert: "T", - kind: TypeParam, - }, - CompletionItem { - label: "quux()", - source_range: 19..19, - delete: 19..19, - insert: "quux()$0", - kind: Function, - lookup: "quux", - detail: "fn quux()", - }, - ] - "### + check( + r#"fn quux() { <|> }"#, + expect![[r#" + tp T + fn quux() fn quux() + "#]], ); } #[test] fn completes_generic_params_in_struct() { - assert_debug_snapshot!( - do_reference_completion( - r" - struct X { - x: <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "Self", - source_range: 21..21, - delete: 21..21, - insert: "Self", - kind: TypeParam, - }, - CompletionItem { - label: "T", - source_range: 21..21, - delete: 21..21, - insert: "T", - kind: TypeParam, - }, - CompletionItem { - label: "X<…>", - source_range: 21..21, - delete: 21..21, - insert: "X<$0>", - kind: Struct, - lookup: "X", - }, - ] - "### + check( + r#"struct S { x: <|>}"#, + expect![[r#" + st S<…> + tp Self + tp T + "#]], ); } #[test] fn completes_self_in_enum() { - assert_debug_snapshot!( - do_reference_completion( - r" - enum X { - Y(<|>) - } - " - ), - @r###" - [ - CompletionItem { - label: "Self", - source_range: 15..15, - delete: 15..15, - insert: "Self", - kind: TypeParam, - }, - CompletionItem { - label: "X", - source_range: 15..15, - delete: 15..15, - insert: "X", - kind: Enum, - }, - ] - "### + check( + r#"enum X { Y(<|>) }"#, + expect![[r#" + tp Self + en X + "#]], ); } #[test] fn completes_module_items() { - assert_debug_snapshot!( - do_reference_completion( - r" - struct Foo; - enum Baz {} - fn quux() { - <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "Baz", - source_range: 40..40, - delete: 40..40, - insert: "Baz", - kind: Enum, - }, - CompletionItem { - label: "Foo", - source_range: 40..40, - delete: 40..40, - insert: "Foo", - kind: Struct, - }, - CompletionItem { - label: "quux()", - source_range: 40..40, - delete: 40..40, - insert: "quux()$0", - kind: Function, - lookup: "quux", - detail: "fn quux()", - }, - ] - "### - ); + check( + r#" +struct S; +enum E {} +fn quux() { <|> } +"#, + expect![[r#" + en E + st S + fn quux() fn quux() + "#]], + ); } #[test] fn completes_extern_prelude() { - assert_debug_snapshot!( - do_reference_completion( - r" - //- /lib.rs - use <|>; - - //- /other_crate/lib.rs - // nothing here - " - ), - @r###" - [ - CompletionItem { - label: "other_crate", - source_range: 4..4, - delete: 4..4, - insert: "other_crate", - kind: Module, - }, - ] - "### + check( + r#" +//- /lib.rs +use <|>; + +//- /other_crate/lib.rs +// nothing here +"#, + expect![[r#" + md other_crate + "#]], ); } #[test] fn completes_module_items_in_nested_modules() { - assert_debug_snapshot!( - do_reference_completion( - r" - struct Foo; - mod m { - struct Bar; - fn quux() { <|> } - } - " - ), - @r###" - [ - CompletionItem { - label: "Bar", - source_range: 52..52, - delete: 52..52, - insert: "Bar", - kind: Struct, - }, - CompletionItem { - label: "quux()", - source_range: 52..52, - delete: 52..52, - insert: "quux()$0", - kind: Function, - lookup: "quux", - detail: "fn quux()", - }, - ] - "### + check( + r#" +struct Foo; +mod m { + struct Bar; + fn quux() { <|> } +} +"#, + expect![[r#" + st Bar + fn quux() fn quux() + "#]], ); } #[test] fn completes_return_type() { - assert_debug_snapshot!( - do_reference_completion( - r" - struct Foo; - fn x() -> <|> - " - ), - @r###" - [ - CompletionItem { - label: "Foo", - source_range: 22..22, - delete: 22..22, - insert: "Foo", - kind: Struct, - }, - CompletionItem { - label: "x()", - source_range: 22..22, - delete: 22..22, - insert: "x()$0", - kind: Function, - lookup: "x", - detail: "fn x()", - }, - ] - "### + check( + r#" +struct Foo; +fn x() -> <|> +"#, + expect![[r#" + st Foo + fn x() fn x() + "#]], ); } #[test] fn dont_show_both_completions_for_shadowing() { - assert_debug_snapshot!( - do_reference_completion( - r" - fn foo() { - let bar = 92; - { - let bar = 62; - <|> - } - } - " - ), - @r###" - [ - CompletionItem { - label: "bar", - source_range: 65..65, - delete: 65..65, - insert: "bar", - kind: Binding, - detail: "i32", - }, - CompletionItem { - label: "foo()", - source_range: 65..65, - delete: 65..65, - insert: "foo()$0", - kind: Function, - lookup: "foo", - detail: "fn foo()", - }, - ] - "### + check( + r#" +fn foo() { + let bar = 92; + { + let bar = 62; + drop(<|>) + } +} +"#, + // FIXME: should be only one bar here + expect![[r#" + bn bar i32 + bn bar i32 + fn foo() fn foo() + "#]], ); } #[test] fn completes_self_in_methods() { - assert_debug_snapshot!( - do_reference_completion(r"impl S { fn foo(&self) { <|> } }"), - @r###" - [ - CompletionItem { - label: "Self", - source_range: 25..25, - delete: 25..25, - insert: "Self", - kind: TypeParam, - }, - CompletionItem { - label: "self", - source_range: 25..25, - delete: 25..25, - insert: "self", - kind: Binding, - detail: "&{unknown}", - }, - ] - "### + check( + r#"impl S { fn foo(&self) { <|> } }"#, + expect![[r#" + tp Self + bn self &{unknown} + "#]], ); } #[test] fn completes_prelude() { - assert_debug_snapshot!( - do_reference_completion( - " - //- /main.rs - fn foo() { let x: <|> } - - //- /std/lib.rs - #[prelude_import] - use prelude::*; - - mod prelude { - struct Option; - } - " - ), - @r###" - [ - CompletionItem { - label: "Option", - source_range: 18..18, - delete: 18..18, - insert: "Option", - kind: Struct, - }, - CompletionItem { - label: "foo()", - source_range: 18..18, - delete: 18..18, - insert: "foo()$0", - kind: Function, - lookup: "foo", - detail: "fn foo()", - }, - CompletionItem { - label: "std", - source_range: 18..18, - delete: 18..18, - insert: "std", - kind: Module, - }, - ] - "### + check( + r#" +//- /main.rs +fn foo() { let x: <|> } + +//- /std/lib.rs +#[prelude_import] +use prelude::*; + +mod prelude { struct Option; } +"#, + expect![[r#" + st Option + fn foo() fn foo() + md std + "#]], ); } #[test] fn completes_std_prelude_if_core_is_defined() { - assert_debug_snapshot!( - do_reference_completion( - " - //- /main.rs - fn foo() { let x: <|> } - - //- /core/lib.rs - #[prelude_import] - use prelude::*; - - mod prelude { - struct Option; - } - - //- /std/lib.rs - #[prelude_import] - use prelude::*; - - mod prelude { - struct String; - } - " - ), - @r###" - [ - CompletionItem { - label: "String", - source_range: 18..18, - delete: 18..18, - insert: "String", - kind: Struct, - }, - CompletionItem { - label: "core", - source_range: 18..18, - delete: 18..18, - insert: "core", - kind: Module, - }, - CompletionItem { - label: "foo()", - source_range: 18..18, - delete: 18..18, - insert: "foo()$0", - kind: Function, - lookup: "foo", - detail: "fn foo()", - }, - CompletionItem { - label: "std", - source_range: 18..18, - delete: 18..18, - insert: "std", - kind: Module, - }, - ] - "### + check( + r#" +//- /main.rs +fn foo() { let x: <|> } + +//- /core/lib.rs +#[prelude_import] +use prelude::*; + +mod prelude { struct Option; } + +//- /std/lib.rs +#[prelude_import] +use prelude::*; + +mod prelude { struct String; } +"#, + expect![[r#" + st String + md core + fn foo() fn foo() + md std + "#]], ); } #[test] fn completes_macros_as_value() { - assert_debug_snapshot!( - do_reference_completion( - " - //- /main.rs - macro_rules! foo { - () => {} - } + check( + r#" +macro_rules! foo { () => {} } - #[macro_use] - mod m1 { - macro_rules! bar { - () => {} - } - } +#[macro_use] +mod m1 { + macro_rules! bar { () => {} } +} - mod m2 { - macro_rules! nope { - () => {} - } +mod m2 { + macro_rules! nope { () => {} } - #[macro_export] - macro_rules! baz { - () => {} - } - } + #[macro_export] + macro_rules! baz { () => {} } +} - fn main() { - let v = <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "bar!(…)", - source_range: 256..256, - delete: 256..256, - insert: "bar!($0)", - kind: Macro, - lookup: "bar!", - detail: "macro_rules! bar", - }, - CompletionItem { - label: "baz!(…)", - source_range: 256..256, - delete: 256..256, - insert: "baz!($0)", - kind: Macro, - lookup: "baz!", - detail: "#[macro_export]\nmacro_rules! baz", - }, - CompletionItem { - label: "foo!(…)", - source_range: 256..256, - delete: 256..256, - insert: "foo!($0)", - kind: Macro, - lookup: "foo!", - detail: "macro_rules! foo", - }, - CompletionItem { - label: "m1", - source_range: 256..256, - delete: 256..256, - insert: "m1", - kind: Module, - }, - CompletionItem { - label: "m2", - source_range: 256..256, - delete: 256..256, - insert: "m2", - kind: Module, - }, - CompletionItem { - label: "main()", - source_range: 256..256, - delete: 256..256, - insert: "main()$0", - kind: Function, - lookup: "main", - detail: "fn main()", - }, - ] - "### +fn main() { let v = <|> } +"#, + expect![[r##" + ma bar!(…) macro_rules! bar + ma baz!(…) #[macro_export] + macro_rules! baz + ma foo!(…) macro_rules! foo + md m1 + md m2 + fn main() fn main() + "##]], ); } #[test] fn completes_both_macro_and_value() { - assert_debug_snapshot!( - do_reference_completion( - " - //- /main.rs - macro_rules! foo { - () => {} - } - - fn foo() { - <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "foo!(…)", - source_range: 50..50, - delete: 50..50, - insert: "foo!($0)", - kind: Macro, - lookup: "foo!", - detail: "macro_rules! foo", - }, - CompletionItem { - label: "foo()", - source_range: 50..50, - delete: 50..50, - insert: "foo()$0", - kind: Function, - lookup: "foo", - detail: "fn foo()", - }, - ] - "### + check( + r#" +macro_rules! foo { () => {} } +fn foo() { <|> } +"#, + expect![[r#" + ma foo!(…) macro_rules! foo + fn foo() fn foo() + "#]], ); } #[test] fn completes_macros_as_type() { - assert_debug_snapshot!( - do_reference_completion( - " - //- /main.rs - macro_rules! foo { - () => {} - } - - fn main() { - let x: <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "foo!(…)", - source_range: 58..58, - delete: 58..58, - insert: "foo!($0)", - kind: Macro, - lookup: "foo!", - detail: "macro_rules! foo", - }, - CompletionItem { - label: "main()", - source_range: 58..58, - delete: 58..58, - insert: "main()$0", - kind: Function, - lookup: "main", - detail: "fn main()", - }, - ] - "### + check( + r#" +macro_rules! foo { () => {} } +fn main() { let x: <|> } +"#, + expect![[r#" + ma foo!(…) macro_rules! foo + fn main() fn main() + "#]], ); } #[test] fn completes_macros_as_stmt() { - assert_debug_snapshot!( - do_reference_completion( - " - //- /main.rs - macro_rules! foo { - () => {} - } - - fn main() { - <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "foo!(…)", - source_range: 51..51, - delete: 51..51, - insert: "foo!($0)", - kind: Macro, - lookup: "foo!", - detail: "macro_rules! foo", - }, - CompletionItem { - label: "main()", - source_range: 51..51, - delete: 51..51, - insert: "main()$0", - kind: Function, - lookup: "main", - detail: "fn main()", - }, - ] - "### + check( + r#" +macro_rules! foo { () => {} } +fn main() { <|> } +"#, + expect![[r#" + ma foo!(…) macro_rules! foo + fn main() fn main() + "#]], ); } #[test] fn completes_local_item() { - assert_debug_snapshot!( - do_reference_completion( - " - //- /main.rs - fn main() { - return f<|>; - fn frobnicate() {} - } - " - ), - @r###" - [ - CompletionItem { - label: "frobnicate()", - source_range: 23..24, - delete: 23..24, - insert: "frobnicate()$0", - kind: Function, - lookup: "frobnicate", - detail: "fn frobnicate()", - }, - CompletionItem { - label: "main()", - source_range: 23..24, - delete: 23..24, - insert: "main()$0", - kind: Function, - lookup: "main", - detail: "fn main()", - }, - ] - "### - ) + check( + r#" +fn main() { + return f<|>; + fn frobnicate() {} +} +"#, + expect![[r#" + fn frobnicate() fn frobnicate() + fn main() fn main() + "#]], + ); } #[test] fn completes_in_simple_macro_1() { - assert_debug_snapshot!( - do_reference_completion( - r" - macro_rules! m { ($e:expr) => { $e } } - fn quux(x: i32) { - let y = 92; - m!(<|>); - } - " - ), - @r###" - [ - CompletionItem { - label: "m!(…)", - source_range: 80..80, - delete: 80..80, - insert: "m!($0)", - kind: Macro, - lookup: "m!", - detail: "macro_rules! m", - }, - CompletionItem { - label: "quux(…)", - source_range: 80..80, - delete: 80..80, - insert: "quux(${1:x})$0", - kind: Function, - lookup: "quux", - detail: "fn quux(x: i32)", - trigger_call_info: true, - }, - CompletionItem { - label: "x", - source_range: 80..80, - delete: 80..80, - insert: "x", - kind: Binding, - detail: "i32", - }, - CompletionItem { - label: "y", - source_range: 80..80, - delete: 80..80, - insert: "y", - kind: Binding, - detail: "i32", - }, - ] - "### + check( + r#" +macro_rules! m { ($e:expr) => { $e } } +fn quux(x: i32) { + let y = 92; + m!(<|>); +} +"#, + expect![[r#" + ma m!(…) macro_rules! m + fn quux(…) fn quux(x: i32) + bn x i32 + bn y i32 + "#]], ); } #[test] fn completes_in_simple_macro_2() { - assert_debug_snapshot!( - do_reference_completion( - r" - macro_rules! m { ($e:expr) => { $e } } - fn quux(x: i32) { - let y = 92; - m!(x<|>); - } - " - ), - @r###" - [ - CompletionItem { - label: "m!(…)", - source_range: 80..81, - delete: 80..81, - insert: "m!($0)", - kind: Macro, - lookup: "m!", - detail: "macro_rules! m", - }, - CompletionItem { - label: "quux(…)", - source_range: 80..81, - delete: 80..81, - insert: "quux(${1:x})$0", - kind: Function, - lookup: "quux", - detail: "fn quux(x: i32)", - trigger_call_info: true, - }, - CompletionItem { - label: "x", - source_range: 80..81, - delete: 80..81, - insert: "x", - kind: Binding, - detail: "i32", - }, - CompletionItem { - label: "y", - source_range: 80..81, - delete: 80..81, - insert: "y", - kind: Binding, - detail: "i32", - }, - ] - "### + check( + r" +macro_rules! m { ($e:expr) => { $e } } +fn quux(x: i32) { + let y = 92; + m!(x<|>); +} +", + expect![[r#" + ma m!(…) macro_rules! m + fn quux(…) fn quux(x: i32) + bn x i32 + bn y i32 + "#]], ); } #[test] fn completes_in_simple_macro_without_closing_parens() { - assert_debug_snapshot!( - do_reference_completion( - r" - macro_rules! m { ($e:expr) => { $e } } - fn quux(x: i32) { - let y = 92; - m!(x<|> - } - " - ), - @r###" - [ - CompletionItem { - label: "m!(…)", - source_range: 80..81, - delete: 80..81, - insert: "m!($0)", - kind: Macro, - lookup: "m!", - detail: "macro_rules! m", - }, - CompletionItem { - label: "quux(…)", - source_range: 80..81, - delete: 80..81, - insert: "quux(${1:x})$0", - kind: Function, - lookup: "quux", - detail: "fn quux(x: i32)", - trigger_call_info: true, - }, - CompletionItem { - label: "x", - source_range: 80..81, - delete: 80..81, - insert: "x", - kind: Binding, - detail: "i32", - }, - CompletionItem { - label: "y", - source_range: 80..81, - delete: 80..81, - insert: "y", - kind: Binding, - detail: "i32", - }, - ] - "### + check( + r#" +macro_rules! m { ($e:expr) => { $e } } +fn quux(x: i32) { + let y = 92; + m!(x<|> +} +"#, + expect![[r#" + ma m!(…) macro_rules! m + fn quux(…) fn quux(x: i32) + bn x i32 + bn y i32 + "#]], ); } #[test] fn completes_unresolved_uses() { - assert_debug_snapshot!( - do_reference_completion( - r" - use spam::Quux; - - fn main() { - <|> - } - " - ), - @r###" - [ - CompletionItem { - label: "Quux", - source_range: 33..33, - delete: 33..33, - insert: "Quux", - }, - CompletionItem { - label: "main()", - source_range: 33..33, - delete: 33..33, - insert: "main()$0", - kind: Function, - lookup: "main", - detail: "fn main()", - }, - ] - "### + check( + r#" +use spam::Quux; + +fn main() { <|> } +"#, + expect![[r#" + ?? Quux + fn main() fn main() + "#]], ); } #[test] fn completes_enum_variant_matcharm() { - assert_debug_snapshot!( - do_reference_completion( - r" - enum Foo { - Bar, - Baz, - Quux - } + check( + r#" +enum Foo { Bar, Baz, Quux } - fn main() { - let foo = Foo::Quux; - - match foo { - Qu<|> - } - } - " - ), - @r###" - [ - CompletionItem { - label: "Foo", - source_range: 103..105, - delete: 103..105, - insert: "Foo", - kind: Enum, - }, - CompletionItem { - label: "Foo::Bar", - source_range: 103..105, - delete: 103..105, - insert: "Foo::Bar", - kind: EnumVariant, - lookup: "Bar", - detail: "()", - }, - CompletionItem { - label: "Foo::Baz", - source_range: 103..105, - delete: 103..105, - insert: "Foo::Baz", - kind: EnumVariant, - lookup: "Baz", - detail: "()", - }, - CompletionItem { - label: "Foo::Quux", - source_range: 103..105, - delete: 103..105, - insert: "Foo::Quux", - kind: EnumVariant, - lookup: "Quux", - detail: "()", - }, - ] - "### +fn main() { + let foo = Foo::Quux; + match foo { Qu<|> } +} +"#, + expect![[r#" + en Foo + ev Foo::Bar () + ev Foo::Baz () + ev Foo::Quux () + "#]], ) } #[test] fn completes_enum_variant_iflet() { - assert_debug_snapshot!( - do_reference_completion( - r" - enum Foo { - Bar, - Baz, - Quux - } - - fn main() { - let foo = Foo::Quux; + check( + r#" +enum Foo { Bar, Baz, Quux } - if let Qu<|> = foo { - - } - } - " - ), - @r###" - [ - CompletionItem { - label: "Foo", - source_range: 90..92, - delete: 90..92, - insert: "Foo", - kind: Enum, - }, - CompletionItem { - label: "Foo::Bar", - source_range: 90..92, - delete: 90..92, - insert: "Foo::Bar", - kind: EnumVariant, - lookup: "Bar", - detail: "()", - }, - CompletionItem { - label: "Foo::Baz", - source_range: 90..92, - delete: 90..92, - insert: "Foo::Baz", - kind: EnumVariant, - lookup: "Baz", - detail: "()", - }, - CompletionItem { - label: "Foo::Quux", - source_range: 90..92, - delete: 90..92, - insert: "Foo::Quux", - kind: EnumVariant, - lookup: "Quux", - detail: "()", - }, - ] - "### +fn main() { + let foo = Foo::Quux; + if let Qu<|> = foo { } +} +"#, + expect![[r#" + en Foo + ev Foo::Bar () + ev Foo::Baz () + ev Foo::Quux () + "#]], ) } #[test] fn completes_enum_variant_basic_expr() { - assert_debug_snapshot!( - do_reference_completion( - r" - enum Foo { - Bar, - Baz, - Quux - } - - fn main() { - let foo: Foo = Q<|> - } - " - ), - @r###" - [ - CompletionItem { - label: "Foo", - source_range: 72..73, - delete: 72..73, - insert: "Foo", - kind: Enum, - }, - CompletionItem { - label: "Foo::Bar", - source_range: 72..73, - delete: 72..73, - insert: "Foo::Bar", - kind: EnumVariant, - lookup: "Bar", - detail: "()", - }, - CompletionItem { - label: "Foo::Baz", - source_range: 72..73, - delete: 72..73, - insert: "Foo::Baz", - kind: EnumVariant, - lookup: "Baz", - detail: "()", - }, - CompletionItem { - label: "Foo::Quux", - source_range: 72..73, - delete: 72..73, - insert: "Foo::Quux", - kind: EnumVariant, - lookup: "Quux", - detail: "()", - }, - CompletionItem { - label: "main()", - source_range: 72..73, - delete: 72..73, - insert: "main()$0", - kind: Function, - lookup: "main", - detail: "fn main()", - }, - ] - "### + check( + r#" +enum Foo { Bar, Baz, Quux } +fn main() { let foo: Foo = Q<|> } +"#, + expect![[r#" + en Foo + ev Foo::Bar () + ev Foo::Baz () + ev Foo::Quux () + fn main() fn main() + "#]], ) } #[test] fn completes_enum_variant_from_module() { - assert_debug_snapshot!( - do_reference_completion( - r" - mod m { pub enum E { V } } - - fn f() -> m::E { - V<|> - } - " - ), - @r###" - [ - CompletionItem { - label: "f()", - source_range: 49..50, - delete: 49..50, - insert: "f()$0", - kind: Function, - lookup: "f", - detail: "fn f() -> m::E", - }, - CompletionItem { - label: "m", - source_range: 49..50, - delete: 49..50, - insert: "m", - kind: Module, - }, - CompletionItem { - label: "m::E::V", - source_range: 49..50, - delete: 49..50, - insert: "m::E::V", - kind: EnumVariant, - lookup: "V", - detail: "()", - }, - ] - "### + check( + r#" +mod m { pub enum E { V } } +fn f() -> m::E { V<|> } +"#, + expect![[r#" + fn f() fn f() -> m::E + md m + ev m::E::V () + "#]], ) } #[test] fn dont_complete_attr() { - assert_debug_snapshot!( - do_reference_completion( - r" - struct Foo; - #[<|>] - fn f() {} - " - ), - @r###"[]"### + check( + r#" +struct Foo; +#[<|>] +fn f() {} +"#, + expect![[""]], ) } } -- cgit v1.2.3