From 0d84adad353a09b8b29e862e80bf68da49c4481b Mon Sep 17 00:00:00 2001 From: Manmeet Date: Sun, 10 Jan 2021 20:12:17 +0530 Subject: Postfix like ifl now works with references --- crates/completion/src/completions/postfix.rs | 31 ++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'crates/completion') 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) { let receiver_text = get_receiver_text(dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal); - let receiver_ty = match ctx.sema.type_of_expr(&dot_receiver) { + let mut receiver_ty = match ctx.sema.type_of_expr(&dot_receiver) { Some(it) => it, None => return, }; + let mut ref_removed = false; + if let Some(removed) = receiver_ty.remove_ref() { + receiver_ty = removed; + ref_removed = true; + } + let cap = match ctx.config.snippet_cap { Some(it) => it, None => return, @@ -85,7 +91,7 @@ pub(crate) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { .add_to(acc); } } - } else if receiver_ty.is_bool() || receiver_ty.is_unknown() { + } else if !ref_removed && (receiver_ty.is_bool() || receiver_ty.is_unknown()) { postfix_snippet( ctx, cap, @@ -496,6 +502,27 @@ fn main() { fn postfix_completion_for_references() { check_edit("dbg", r#"fn main() { &&42.$0 }"#, r#"fn main() { dbg!(&&42) }"#); check_edit("refm", r#"fn main() { &&42.$0 }"#, r#"fn main() { &&&mut 42 }"#); + check_edit( + "ifl", + r#" +enum Option { Some(T), None } + +fn main() { + let bar = &Option::Some(true); + bar.$0 +} +"#, + r#" +enum Option { Some(T), None } + +fn main() { + let bar = &Option::Some(true); + if let Some($1) = bar { + $0 +} +} +"#, + ) } #[test] -- cgit v1.2.3