@@ -38,8 +38,8 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
38
38
Some ( it) => it,
39
39
None => return ,
40
40
} ;
41
-
42
- if let Some ( try_enum) = TryEnum :: from_ty ( & ctx . sema , & receiver_ty ) {
41
+ let try_enum = TryEnum :: from_ty ( & ctx . sema , & receiver_ty ) ;
42
+ if let Some ( try_enum) = & try_enum {
43
43
match try_enum {
44
44
TryEnum :: Result => {
45
45
postfix_snippet (
@@ -104,7 +104,6 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
104
104
)
105
105
. add_to ( acc) ;
106
106
}
107
-
108
107
// !&&&42 is a compiler error, ergo process it before considering the references
109
108
postfix_snippet ( ctx, cap, & dot_receiver, "not" , "!expr" , & format ! ( "!{}" , receiver_text) )
110
109
. add_to ( acc) ;
@@ -126,16 +125,45 @@ pub(super) fn complete_postfix(acc: &mut Completions, ctx: &CompletionContext) {
126
125
let dot_receiver = include_references ( dot_receiver) ;
127
126
let receiver_text =
128
127
get_receiver_text ( & dot_receiver, ctx. dot_receiver_is_ambiguous_float_literal ) ;
129
-
130
- postfix_snippet (
131
- ctx,
132
- cap,
133
- & dot_receiver,
134
- "match" ,
135
- "match expr {}" ,
136
- & format ! ( "match {} {{\n ${{1:_}} => {{$0\\ }},\n }}" , receiver_text) ,
137
- )
138
- . add_to ( acc) ;
128
+ match try_enum {
129
+ Some ( try_enum) => {
130
+ match try_enum {
131
+ TryEnum :: Result => {
132
+ postfix_snippet (
133
+ ctx,
134
+ cap,
135
+ & dot_receiver,
136
+ "match" ,
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
168
postfix_snippet (
141
169
ctx,
@@ -324,7 +352,7 @@ mod tests {
324
352
label: "match",
325
353
source_range: 210..210,
326
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
356
detail: "match expr {}",
329
357
},
330
358
CompletionItem {
@@ -403,7 +431,7 @@ mod tests {
403
431
label: "match",
404
432
source_range: 211..211,
405
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
435
detail: "match expr {}",
408
436
},
409
437
CompletionItem {
0 commit comments