@@ -21,7 +21,8 @@ use crate::{
21
21
// enum Action { Move { distance: u32 }, Stop }
22
22
//
23
23
// fn handle(action: Action) {
24
- // match action $0 {
24
+ // match action {
25
+ // $0
25
26
// }
26
27
// }
27
28
// ```
@@ -30,7 +31,7 @@ use crate::{
30
31
// enum Action { Move { distance: u32 }, Stop }
31
32
//
32
33
// fn handle(action: Action) {
33
- // match action {
34
+ // match action {
34
35
// $0Action::Move { distance } => todo!(),
35
36
// Action::Stop => todo!(),
36
37
// }
@@ -41,7 +42,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) ->
41
42
let match_arm_list = match_expr. match_arm_list ( ) ?;
42
43
let target_range : TextRange ;
43
44
44
- if let None = cursor_inside_simple_match_arm_list ( & ctx, & match_expr, & match_arm_list) {
45
+ if let None = trivial_match_arm_list_at_cursor ( & ctx, & match_expr, & match_arm_list) {
45
46
target_range = TextRange :: new (
46
47
ctx. sema . original_range ( match_expr. syntax ( ) ) . range . start ( ) ,
47
48
ctx. sema . original_range ( match_arm_list. syntax ( ) ) . range . start ( ) ,
@@ -192,12 +193,13 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext) ->
192
193
)
193
194
}
194
195
195
- fn cursor_inside_simple_match_arm_list ( ctx : & AssistContext , match_expr : & MatchExpr , match_arm_list : & MatchArmList ) -> Option < ( ) > {
196
- println ! ( "--- \n {:#?} \n {:#?} \n ---" , match_expr , match_arm_list ) ;
196
+ fn trivial_match_arm_list_at_cursor ( ctx : & AssistContext , match_expr : & MatchExpr , match_arm_list : & MatchArmList ) -> Option < ( ) > {
197
+ // match x { $0 }
197
198
if match_arm_list. arms ( ) . next ( ) == None {
198
199
return Some ( ( ) ) ;
199
200
}
200
201
202
+ // match { _$0 => {...} }
201
203
let wild_pat = ctx. find_node_at_offset_with_descend :: < ast:: WildcardPat > ( ) ?;
202
204
let arm = wild_pat. syntax ( ) . parent ( ) . and_then ( ast:: MatchArm :: cast) ?;
203
205
let arm_match_expr = arm. syntax ( ) . ancestors ( ) . nth ( 2 ) . and_then ( ast:: MatchExpr :: cast) ?;
@@ -973,6 +975,26 @@ fn main() {
973
975
) ;
974
976
}
975
977
978
+
979
+ #[ test]
980
+ fn wildcard_inside_expression_not_applicable ( ) {
981
+ check_assist_not_applicable (
982
+ add_missing_match_arms,
983
+ r#"
984
+ enum E { X, Y }
985
+
986
+ fn foo(e : E) {
987
+ match e {
988
+ _ => {
989
+ println!("1");$0
990
+ println!("2");
991
+ }
992
+ }
993
+ }
994
+ "# ,
995
+ ) ;
996
+ }
997
+
976
998
#[ test]
977
999
fn add_missing_match_arms_qualifies_path ( ) {
978
1000
check_assist (
0 commit comments