@@ -37,9 +37,9 @@ use crate::{utils, AssistContext, AssistId, AssistKind, Assists};
3737pub ( crate ) fn add_missing_match_arms ( acc : & mut Assists , ctx : & AssistContext < ' _ > ) -> Option < ( ) > {
3838 let match_expr = ctx. find_node_at_offset_with_descend :: < ast:: MatchExpr > ( ) ?;
3939 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 ( ) ) ? ;
4141
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 ( ) {
4343 let arm_list_range = ctx. sema . original_range ( match_arm_list. syntax ( ) ) . range ;
4444 let cursor_in_range = arm_list_range. contains_range ( ctx. selection_trimmed ( ) ) ;
4545 if cursor_in_range {
@@ -198,7 +198,7 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
198198 acc. add (
199199 AssistId ( "add_missing_match_arms" , AssistKind :: QuickFix ) ,
200200 "Fill match arms" ,
201- target_range ,
201+ ctx . sema . original_range ( match_expr . syntax ( ) ) . range ,
202202 |edit| {
203203 let new_match_arm_list = match_arm_list. clone_for_update ( ) ;
204204
@@ -262,9 +262,8 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>)
262262 // Just replace the element that the original range came from
263263 let old_place = {
264264 // 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 ) ;
268267
269268 // Make `old_place` mut
270269 match old_place {
@@ -1922,4 +1921,24 @@ fn foo(t: E) {
19221921}"# ,
19231922 ) ;
19241923 }
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+ }
19251944}
0 commit comments