From 001a86dc03104b75df732d69257d22526cf422b7 Mon Sep 17 00:00:00 2001 From: Hasan Ali Date: Fri, 15 May 2020 22:23:49 +0100 Subject: Fix completion and hover for module and function of same name --- .../src/completion/complete_qualified_path.rs | 30 +++++++++++++++++++++- crates/ra_ide/src/hover.rs | 17 ++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide/src') diff --git a/crates/ra_ide/src/completion/complete_qualified_path.rs b/crates/ra_ide/src/completion/complete_qualified_path.rs index 7fcd22525..db7430454 100644 --- a/crates/ra_ide/src/completion/complete_qualified_path.rs +++ b/crates/ra_ide/src/completion/complete_qualified_path.rs @@ -20,7 +20,7 @@ pub(super) fn complete_qualified_path(acc: &mut Completions, ctx: &CompletionCon let scope = ctx.scope(); let context_module = scope.module(); - let res = match scope.resolve_hir_path(&path) { + let res = match scope.resolve_hir_path_qualifier(&path) { Some(res) => res, None => return, }; @@ -225,6 +225,34 @@ mod tests { ); } + #[test] + fn completes_mod_with_same_name_as_function() { + assert_debug_snapshot!( + do_reference_completion( + r" + use self::my::<|>; + + mod my { + pub struct Bar; + } + + fn my() {} + " + ), + @r###" + [ + CompletionItem { + label: "Bar", + source_range: 31..31, + delete: 31..31, + insert: "Bar", + kind: Struct, + }, + ] + "### + ); + } + #[test] fn path_visibility() { assert_debug_snapshot!( diff --git a/crates/ra_ide/src/hover.rs b/crates/ra_ide/src/hover.rs index 06d4f1c63..befa977c7 100644 --- a/crates/ra_ide/src/hover.rs +++ b/crates/ra_ide/src/hover.rs @@ -921,4 +921,21 @@ fn func(foo: i32) { if true { <|>foo; }; } &["unsafe trait foo"], ); } + + #[test] + fn test_hover_mod_with_same_name_as_function() { + check_hover_result( + " + //- /lib.rs + use self::m<|>y::Bar; + + mod my { + pub struct Bar; + } + + fn my() {} + ", + &["mod my"], + ); + } } -- cgit v1.2.3