From 734e68da4ceb1b15b3430302f233d4700d694728 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sat, 7 Mar 2020 23:03:56 +0100 Subject: Handle visibility in method call completion --- crates/ra_ide/src/completion/complete_dot.rs | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide') diff --git a/crates/ra_ide/src/completion/complete_dot.rs b/crates/ra_ide/src/completion/complete_dot.rs index 9145aa183..acada48ae 100644 --- a/crates/ra_ide/src/completion/complete_dot.rs +++ b/crates/ra_ide/src/completion/complete_dot.rs @@ -57,7 +57,10 @@ fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: &T let mut seen_methods = FxHashSet::default(); let traits_in_scope = ctx.scope().traits_in_scope(); receiver.iterate_method_candidates(ctx.db, krate, &traits_in_scope, None, |_ty, func| { - if func.has_self_param(ctx.db) && seen_methods.insert(func.name(ctx.db)) { + if func.has_self_param(ctx.db) + && ctx.scope().module().map_or(true, |m| func.is_visible_from(ctx.db, m)) + && seen_methods.insert(func.name(ctx.db)) + { acc.add_function(ctx, func); } None::<()> @@ -307,6 +310,39 @@ mod tests { ); } + #[test] + fn test_method_completion_private() { + assert_debug_snapshot!( + do_ref_completion( + r" + struct A {} + mod m { + impl super::A { + fn private_method(&self) {} + pub(super) fn the_method(&self) {} + } + } + fn foo(a: A) { + a.<|> + } + ", + ), + @r###" + [ + CompletionItem { + label: "the_method()", + source_range: [256; 256), + delete: [256; 256), + insert: "the_method()$0", + kind: Method, + lookup: "the_method", + detail: "pub(super) fn the_method(&self)", + }, + ] + "### + ); + } + #[test] fn test_trait_method_completion() { assert_debug_snapshot!( -- cgit v1.2.3