diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-14 20:55:18 +0100 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-04-14 20:55:18 +0100 |
commit | e1a2649aff0a9387fb14646a56cb652061bc42ec (patch) | |
tree | b8275843aa56b922b6325b50be2aae063234cc2a /crates/ra_ide_api/src | |
parent | 88be6f32172813f53dae60d73c9f5deb0c3fb29f (diff) | |
parent | 4f8a49f43cad086a656626c43062ff89b46f505a (diff) |
Merge #1144
1144: Refactor method candidate generation a bit r=flodiebold a=flodiebold
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 :)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_ide_api/src')
-rw-r--r-- | crates/ra_ide_api/src/completion/complete_dot.rs | 28 |
1 files changed, 27 insertions, 1 deletions
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) | |||
37 | } | 37 | } |
38 | 38 | ||
39 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { | 39 | fn complete_methods(acc: &mut Completions, ctx: &CompletionContext, receiver: Ty) { |
40 | receiver.iterate_methods(ctx.db, |_ty, func| { | 40 | ctx.analyzer.iterate_method_candidates(ctx.db, receiver, None, |_ty, func| { |
41 | let sig = func.signature(ctx.db); | 41 | let sig = func.signature(ctx.db); |
42 | if sig.has_self_param() { | 42 | if sig.has_self_param() { |
43 | acc.add_function(ctx, func); | 43 | acc.add_function(ctx, func); |
@@ -196,6 +196,32 @@ mod tests { | |||
196 | } | 196 | } |
197 | 197 | ||
198 | #[test] | 198 | #[test] |
199 | fn test_trait_method_completion() { | ||
200 | assert_debug_snapshot_matches!( | ||
201 | do_ref_completion( | ||
202 | r" | ||
203 | struct A {} | ||
204 | trait Trait { fn the_method(&self); } | ||
205 | impl Trait for A {} | ||
206 | fn foo(a: A) { | ||
207 | a.<|> | ||
208 | } | ||
209 | ", | ||
210 | ), | ||
211 | @r###"[ | ||
212 | CompletionItem { | ||
213 | label: "the_method", | ||
214 | source_range: [151; 151), | ||
215 | delete: [151; 151), | ||
216 | insert: "the_method()$0", | ||
217 | kind: Method, | ||
218 | detail: "fn the_method(&self)" | ||
219 | } | ||
220 | ]"### | ||
221 | ); | ||
222 | } | ||
223 | |||
224 | #[test] | ||
199 | fn test_no_non_self_method() { | 225 | fn test_no_non_self_method() { |
200 | assert_debug_snapshot_matches!( | 226 | assert_debug_snapshot_matches!( |
201 | do_ref_completion( | 227 | do_ref_completion( |