From 8baa05666c455b4dd6333fd5ac1a694136039f43 Mon Sep 17 00:00:00 2001 From: Matthias Einwag Date: Sat, 9 Nov 2019 17:38:08 -0800 Subject: Add tests for resolving types in core and std preludes --- crates/ra_hir_def/src/nameres/tests.rs | 31 +++++++++++ crates/ra_ide_api/src/completion/complete_scope.rs | 62 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) diff --git a/crates/ra_hir_def/src/nameres/tests.rs b/crates/ra_hir_def/src/nameres/tests.rs index 52bd0aa91..256f7d4be 100644 --- a/crates/ra_hir_def/src/nameres/tests.rs +++ b/crates/ra_hir_def/src/nameres/tests.rs @@ -463,6 +463,37 @@ fn values_dont_shadow_extern_crates() { "###); } +#[test] +fn std_prelude_takes_precedence_above_core_prelude() { + let map = def_map( + r#" + //- /main.rs crate:main deps:core,std + use {Foo, Bar}; + + //- /std.rs crate:std deps:core + #[prelude_import] + pub use self::prelude::*; + mod prelude { + pub struct Foo; + pub use core::prelude::Bar; + } + + //- /core.rs crate:core + #[prelude_import] + pub use self::prelude::*; + mod prelude { + pub struct Bar; + } + "#, + ); + + assert_snapshot!(map, @r###" + ⋮crate + ⋮Bar: t v + ⋮Foo: t v + "###); +} + #[test] fn cfg_not_test() { let map = def_map( diff --git a/crates/ra_ide_api/src/completion/complete_scope.rs b/crates/ra_ide_api/src/completion/complete_scope.rs index 4e56de3f5..3e205efd1 100644 --- a/crates/ra_ide_api/src/completion/complete_scope.rs +++ b/crates/ra_ide_api/src/completion/complete_scope.rs @@ -597,6 +597,68 @@ mod tests { ); } + #[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, + }, + ] + "### + ); + } + #[test] fn completes_macros_as_value() { assert_debug_snapshot!( -- cgit v1.2.3