diff options
-rw-r--r-- | crates/ra_ide/src/completion/complete_postfix.rs | 58 |
1 files changed, 43 insertions, 15 deletions
diff --git a/crates/ra_ide/src/completion/complete_postfix.rs b/crates/ra_ide/src/completion/complete_postfix.rs index c5c4426cc..f2a52a407 100644 --- a/crates/ra_ide/src/completion/complete_postfix.rs +++ b/crates/ra_ide/src/completion/complete_postfix.rs | |||
@@ -38,8 +38,8 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
38 | Some(it) => it, | 38 | Some(it) => it, |
39 | None => return, | 39 | None => return, |
40 | }; | 40 | }; |
41 | 41 | let try_enum = TryEnum::from_ty(&ctx.sema, &receiver_ty); | |
42 | if let Some(try_enum) = TryEnum::from_ty(&ctx.sema, &receiver_ty) { | 42 | if let Some(try_enum) = &try_enum { |
43 | match try_enum { | 43 | match try_enum { |
44 | TryEnum::Result => { | 44 | TryEnum::Result => { |
45 | postfix_snippet( | 45 | postfix_snippet( |
@@ -104,7 +104,6 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
104 | ) | 104 | ) |
105 | .add_to(acc); | 105 | .add_to(acc); |
106 | } | 106 | } |
107 | |||
108 | // !&&&42 is a compiler error, ergo process it before considering the references | 107 | // !&&&42 is a compiler error, ergo process it before considering the references |
109 | postfix_snippet(ctx, cap, &dot_receiver, "not", "!expr", &format!("!{}", receiver_text)) | 108 | postfix_snippet(ctx, cap, &dot_receiver, "not", "!expr", &format!("!{}", receiver_text)) |
110 | .add_to(acc); | 109 | .add_to(acc); |
@@ -126,16 +125,45 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) { | |||
126 | let dot_receiver = include_references(dot_receiver); | 125 | let dot_receiver = include_references(dot_receiver); |
127 | let receiver_text = | 126 | let receiver_text = |
128 | get_receiver_text(&dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal); | 127 | get_receiver_text(&dot_receiver, ctx.dot_receiver_is_ambiguous_float_literal); |
129 | 128 | match try_enum { | |
130 | postfix_snippet( | 129 | Some(try_enum) => { |
131 | ctx, | 130 | match try_enum { |
132 | cap, | 131 | TryEnum::Result => { |
133 | &dot_receiver, | 132 | postfix_snippet( |
134 | "match", | 133 | ctx, |
135 | "match expr {}", | 134 | cap, |
136 | &format!("match {} {{\n ${{1:_}} => {{$0\\}},\n}}", receiver_text), | 135 | &dot_receiver, |
137 | ) | 136 | "match", |
138 | .add_to(acc); | 137 | "match expr {}", |
138 | &format!("match {} {{\n Ok(${{1:_}}) => {{$2\\}},\n Err(${{3:_}}) => {{$0\\}},\n}}", receiver_text), | ||
139 | ) | ||
140 | .add_to(acc); | ||
141 | } | ||
142 | TryEnum::Option => { | ||
143 | postfix_snippet( | ||
144 | ctx, | ||
145 | cap, | ||
146 | &dot_receiver, | ||
147 | "match", | ||
148 | "match expr {}", | ||
149 | &format!("match {} {{\n Some(${{1:_}}) => {{$2\\}},\n None => {{$0\\}},\n}}", receiver_text), | ||
150 | ) | ||
151 | .add_to(acc); | ||
152 | } | ||
153 | } | ||
154 | } | ||
155 | None => { | ||
156 | postfix_snippet( | ||
157 | ctx, | ||
158 | cap, | ||
159 | &dot_receiver, | ||
160 | "match", | ||
161 | "match expr {}", | ||
162 | &format!("match {} {{\n ${{1:_}} => {{$0\\}},\n}}", receiver_text), | ||
163 | ) | ||
164 | .add_to(acc); | ||
165 | } | ||
166 | } | ||
139 | 167 | ||
140 | postfix_snippet( | 168 | postfix_snippet( |
141 | ctx, | 169 | ctx, |
@@ -324,7 +352,7 @@ mod tests { | |||
324 | label: "match", | 352 | label: "match", |
325 | source_range: 210..210, | 353 | source_range: 210..210, |
326 | delete: 206..210, | 354 | delete: 206..210, |
327 | insert: "match bar {\n ${1:_} => {$0\\},\n}", | 355 | insert: "match bar {\n Some(${1:_}) => {$2\\},\n None => {$0\\},\n}", |
328 | detail: "match expr {}", | 356 | detail: "match expr {}", |
329 | }, | 357 | }, |
330 | CompletionItem { | 358 | CompletionItem { |
@@ -403,7 +431,7 @@ mod tests { | |||
403 | label: "match", | 431 | label: "match", |
404 | source_range: 211..211, | 432 | source_range: 211..211, |
405 | delete: 207..211, | 433 | delete: 207..211, |
406 | insert: "match bar {\n ${1:_} => {$0\\},\n}", | 434 | insert: "match bar {\n Ok(${1:_}) => {$2\\},\n Err(${3:_}) => {$0\\},\n}", |
407 | detail: "match expr {}", | 435 | detail: "match expr {}", |
408 | }, | 436 | }, |
409 | CompletionItem { | 437 | CompletionItem { |