From 4f8a49f43cad086a656626c43062ff89b46f505a Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 14 Apr 2019 16:08:10 +0200 Subject: Refactor method candidate generation a bit This fixes the order in which candidates are chosen a bit (not completely though, as the ignored test demonstrates), and makes autoderef work with trait methods. As a side effect, this also makes completion of trait methods work :) --- crates/ra_ide_api/src/completion/complete_dot.rs | 28 +++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'crates/ra_ide_api/src') diff --git a/crates/ra_ide_api/src/completion/complete_dot.rs b/crates/ra_ide_api/src/completion/complete_dot.rs index 4a111aba5..e34ddf24a 100644 --- a/crates/ra_ide_api/src/completion/complete_dot.rs +++ b/crates/ra_ide_api/src/completion/complete_dot.rs @@ -37,7 +37,7 @@ fn complete_fields(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) } fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { - receiver.iterate_methods(ctx.db, |_ty, func| { + ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { let sig = func.signature(ctx.db); if sig.has_self_param() { acc.add_function(ctx, func); @@ -195,6 +195,32 @@ mod tests { ); } + #[test] + fn test_trait_method_completion() { + assert_debug_snapshot_matches!( + do_ref_completion( + r" + struct A {} + trait Trait { fn the_method(&self); } + impl Trait for A {} + fn foo(a: A) { + a.<|> + } + ", + ), + @r###"[ + CompletionItem { + label: "the_method", + source_range: [151; 151), + delete: [151; 151), + insert: "the_method()$0", + kind: Method, + detail: "fn the_method(&self)" + } +]"### + ); + } + #[test] fn test_no_non_self_method() { assert_debug_snapshot_matches!( -- cgit v1.2.3