diff options
author | Manmeet <[email protected]> | 2021-01-10 14:42:17 +0000 |
---|---|---|
committer | Manmeet <[email protected]> | 2021-01-10 14:42:17 +0000 |
commit | 0d84adad353a09b8b29e862e80bf68da49c4481b (patch) | |
tree | 3b87cb7430095433a3bb7b56d8da18d09fde5326 /crates/completion | |
parent | 8e54fa67cc4cc7460cc346283f96983d38b9e790 (diff) |
Postfix like ifl now works with references
Diffstat (limited to 'crates/completion')
-rw-r--r-- | crates/completion/src/completions/postfix.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/crates/completion/src/completions/postfix.rs b/crates/completion/src/completions/postfix.rs index 87f0c0b2a..ec91f87f2 100644 --- a/crates/completion/src/completions/postfix.rs +++ b/crates/completion/src/completions/postfix.rs | |||
@@ -30,11 +30,17 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
30 | let receiver_text = | 30 | let receiver_text = |
31 | get_receiver_text(dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal); | 31 | get_receiver_text(dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal); |
32 | 32 | ||
33 | let receiver_ty = match ctx.sema.type_of_expr(&dot_receiver) { | 33 | let mut receiver_ty = match ctx.sema.type_of_expr(&dot_receiver) { |
34 | Some(it) => it, | 34 | Some(it) => it, |
35 | None => return, | 35 | None => return, |
36 | }; | 36 | }; |
37 | 37 | ||
38 | let mut ref_removed = false; | ||
39 | if let Some(removed) = receiver_ty.remove_ref() { | ||
40 | receiver_ty = removed; | ||
41 | ref_removed = true; | ||
42 | } | ||
43 | |||
38 | let cap = match ctx.config.snippet_cap { | 44 | let cap = match ctx.config.snippet_cap { |
39 | Some(it) => it, | 45 | Some(it) => it, |
40 | None => return, | 46 | None => return, |
@@ -85,7 +91,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
85 | .add_to(acc); | 91 | .add_to(acc); |
86 | } | 92 | } |
87 | } | 93 | } |
88 | } else if receiver_ty.is_bool() || receiver_ty.is_unknown() { | 94 | } else if !ref_removed && (receiver_ty.is_bool() || receiver_ty.is_unknown()) { |
89 | postfix_snippet( | 95 | postfix_snippet( |
90 | ctx, | 96 | ctx, |
91 | cap, | 97 | cap, |
@@ -496,6 +502,27 @@ fn main() { | |||
496 | fn postfix_completion_for_references() { | 502 | fn postfix_completion_for_references() { |
497 | check_edit("dbg", r#"fn main() { &&42.$0 }"#, r#"fn main() { dbg!(&&42) }"#); | 503 | check_edit("dbg", r#"fn main() { &&42.$0 }"#, r#"fn main() { dbg!(&&42) }"#); |
498 | check_edit("refm", r#"fn main() { &&42.$0 }"#, r#"fn main() { &&&mut 42 }"#); | 504 | check_edit("refm", r#"fn main() { &&42.$0 }"#, r#"fn main() { &&&mut 42 }"#); |
505 | check_edit( | ||
506 | "ifl", | ||
507 | r#" | ||
508 | enum Option<T> { Some(T), None } | ||
509 | |||
510 | fn main() { | ||
511 | let bar = &Option::Some(true); | ||
512 | bar.$0 | ||
513 | } | ||
514 | "#, | ||
515 | r#" | ||
516 | enum Option<T> { Some(T), None } | ||
517 | |||
518 | fn main() { | ||
519 | let bar = &Option::Some(true); | ||
520 | if let Some($1) = bar { | ||
521 | $0 | ||
522 | } | ||
523 | } | ||
524 | "#, | ||
525 | ) | ||
499 | } | 526 | } |
500 | 527 | ||
501 | #[test] | 528 | #[test] |