@@ -37,9 +37,9 @@ use crate::{utils, AssistContext, AssistId, AssistKind, Assists};
37
37
pub ( crate ) fn add_missing_match_arms ( acc : & mut Assists , ctx : & AssistContext < ' _ > ) -> Option < ( ) > {
38
38
let match_expr = ctx. find_node_at_offset_with_descend :: < ast:: MatchExpr > ( ) ?;
39
39
let match_arm_list = match_expr. match_arm_list ( ) ?;
40
- let target_range = ctx. sema . original_range ( match_expr . syntax ( ) ) . range ;
40
+ let arm_list_range = ctx. sema . original_range_opt ( match_arm_list . syntax ( ) ) ? ;
41
41
42
- if let None = cursor_at_trivial_match_arm_list ( ctx, & match_expr, & match_arm_list) {
42
+ if cursor_at_trivial_match_arm_list ( ctx, & match_expr, & match_arm_list) . is_none ( ) {
43
43
let arm_list_range = ctx. sema . original_range ( match_arm_list. syntax ( ) ) . range ;
44
44
let cursor_in_range = arm_list_range. contains_range ( ctx. selection_trimmed ( ) ) ;
45
45
if cursor_in_range {
@@ -198,7 +198,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
198
198
acc. add (
199
199
AssistId ( "add_missing_match_arms" , AssistKind :: QuickFix ) ,
200
200
"Fill match arms" ,
201
- target_range ,
201
+ ctx . sema . original_range ( match_expr . syntax ( ) ) . range ,
202
202
|edit| {
203
203
let new_match_arm_list = match_arm_list. clone_for_update ( ) ;
204
204
@@ -262,9 +262,8 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
262
262
// Just replace the element that the original range came from
263
263
let old_place = {
264
264
// Find the original element
265
- let old_file_range = ctx. sema . original_range ( match_arm_list. syntax ( ) ) ;
266
- let file = ctx. sema . parse ( old_file_range. file_id ) ;
267
- let old_place = file. syntax ( ) . covering_element ( old_file_range. range ) ;
265
+ let file = ctx. sema . parse ( arm_list_range. file_id ) ;
266
+ let old_place = file. syntax ( ) . covering_element ( arm_list_range. range ) ;
268
267
269
268
// Make `old_place` mut
270
269
match old_place {
@@ -1922,4 +1921,24 @@ fn foo(t: E) {
1922
1921
}"# ,
1923
1922
) ;
1924
1923
}
1924
+
1925
+ #[ test]
1926
+ fn not_applicable_when_match_arm_list_cannot_be_upmapped ( ) {
1927
+ check_assist_not_applicable (
1928
+ add_missing_match_arms,
1929
+ r#"
1930
+ macro_rules! foo {
1931
+ ($($t:tt)*) => {
1932
+ $($t)* {}
1933
+ }
1934
+ }
1935
+
1936
+ enum E { A }
1937
+
1938
+ fn main() {
1939
+ foo!(match E::A$0);
1940
+ }
1941
+ "# ,
1942
+ ) ;
1943
+ }
1925
1944
}
0 commit comments