From 92b2b3d26bffdd95bd7f000c1708020e8880d75a Mon Sep 17 00:00:00 2001 From: Giga Bowser <45986823+Giga-Bowser@users.noreply.github.com> Date: Fri, 1 Nov 2024 12:35:01 -0400 Subject: [PATCH 1/2] Use snippet placeholders for generated match arms --- .../src/handlers/add_missing_match_arms.rs | 218 +++++++++--------- crates/ide-assists/src/tests/generated.rs | 4 +- 2 files changed, 114 insertions(+), 108 deletions(-) diff --git a/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/crates/ide-assists/src/handlers/add_missing_match_arms.rs index a211ca8f2d..71756def14 100644 --- a/crates/ide-assists/src/handlers/add_missing_match_arms.rs +++ b/crates/ide-assists/src/handlers/add_missing_match_arms.rs @@ -30,8 +30,8 @@ use crate::{utils, AssistContext, AssistId, AssistKind, Assists}; // // fn handle(action: Action) { // match action { -// $0Action::Move { distance } => todo!(), -// Action::Stop => todo!(), +// Action::Move { distance } => ${1:todo!()}, +// Action::Stop => ${0:todo!()}, // } // } // ``` @@ -234,8 +234,10 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) } } + let mut todo_placeholders = Vec::new(); let mut first_new_arm = None; for arm in missing_arms { + todo_placeholders.push(arm.expr().unwrap()); first_new_arm.get_or_insert_with(|| arm.clone()); new_match_arm_list.add_arm(arm); } @@ -248,14 +250,18 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) make::ext::expr_todo(), ) .clone_for_update(); + todo_placeholders.push(arm.expr().unwrap()); first_new_arm.get_or_insert_with(|| arm.clone()); new_match_arm_list.add_arm(arm); } if let (Some(first_new_arm), Some(cap)) = (first_new_arm, ctx.config.snippet_cap) { - match first_new_arm.syntax().descendants().find_map(ast::WildcardPat::cast) { - Some(it) => edit.add_placeholder_snippet(cap, it), - None => edit.add_tabstop_before(cap, first_new_arm), + if let Some(it) = first_new_arm.syntax().descendants().find_map(ast::WildcardPat::cast) { + edit.add_placeholder_snippet(cap, it); + } + + for placeholder in todo_placeholders { + edit.add_placeholder_snippet(cap, placeholder); } } @@ -581,8 +587,8 @@ fn foo(a: bool) { r#" fn foo(a: bool) { match a { - $0true => todo!(), - false => todo!(), + true => ${1:todo!()}, + false => ${0:todo!()}, } } "#, @@ -604,7 +610,7 @@ fn foo(a: bool) { fn foo(a: bool) { match a { true => {} - $0false => todo!(), + false => ${0:todo!()}, } } "#, @@ -654,10 +660,10 @@ fn foo(a: bool) { r#" fn foo(a: bool) { match (a, a) { - $0(true, true) => todo!(), - (true, false) => todo!(), - (false, true) => todo!(), - (false, false) => todo!(), + (true, true) => ${1:todo!()}, + (true, false) => ${2:todo!()}, + (false, true) => ${3:todo!()}, + (false, false) => ${0:todo!()}, } } "#, @@ -677,8 +683,8 @@ fn foo(a: bool) { r#" fn foo(a: bool) { match [a] { - $0[true] => todo!(), - [false] => todo!(), + [true] => ${1:todo!()}, + [false] => ${0:todo!()}, } } "#, @@ -695,8 +701,8 @@ fn foo(a: bool) { r#" fn foo(a: bool) { match [a,] { - $0[true] => todo!(), - [false] => todo!(), + [true] => ${1:todo!()}, + [false] => ${0:todo!()}, } } "#, @@ -715,9 +721,9 @@ fn foo(a: bool) { fn foo(a: bool) { match [a, a] { [true, true] => todo!(), - $0[true, false] => todo!(), - [false, true] => todo!(), - [false, false] => todo!(), + [true, false] => ${1:todo!()}, + [false, true] => ${2:todo!()}, + [false, false] => ${0:todo!()}, } } "#, @@ -734,10 +740,10 @@ fn foo(a: bool) { r#" fn foo(a: bool) { match [a, a] { - $0[true, true] => todo!(), - [true, false] => todo!(), - [false, true] => todo!(), - [false, false] => todo!(), + [true, true] => ${1:todo!()}, + [true, false] => ${2:todo!()}, + [false, true] => ${3:todo!()}, + [false, false] => ${0:todo!()}, } } "#, @@ -759,8 +765,8 @@ fn foo(a: bool) { fn foo(a: bool) { match (a, a) { (true | false, true) => {} - $0(true, false) => todo!(), - (false, false) => todo!(), + (true, false) => ${1:todo!()}, + (false, false) => ${0:todo!()}, } } "#, @@ -779,9 +785,9 @@ fn foo(a: bool) { fn foo(a: bool) { match (a, a) { (false, true) => {} - $0(true, true) => todo!(), - (true, false) => todo!(), - (false, false) => todo!(), + (true, true) => ${1:todo!()}, + (true, false) => ${2:todo!()}, + (false, false) => ${0:todo!()}, } } "#, @@ -815,7 +821,7 @@ fn main() { match A::As { A::Bs { x, y: Some(_) } => {} A::Cs(_, Some(_)) => {} - $0A::As => todo!(), + A::As => ${0:todo!()}, } } "#, @@ -838,7 +844,7 @@ fn main() { fn main() { match None { None => {} - Some(${0:_}) => todo!(), + Some(${1:_}) => ${0:todo!()}, } } "#, @@ -862,7 +868,7 @@ enum A { As, Bs, Cs(Option) } fn main() { match A::As { A::Cs(_) | A::Bs => {} - $0A::As => todo!(), + A::As => ${0:todo!()}, } } "#, @@ -892,8 +898,8 @@ fn main() { A::Bs if 0 < 1 => {} A::Ds(_value) => { let x = 1; } A::Es(B::Xs) => (), - $0A::As => todo!(), - A::Cs => todo!(), + A::As => ${1:todo!()}, + A::Cs => ${0:todo!()}, } } "#, @@ -919,7 +925,7 @@ fn main() { match A::As { A::As(_) => {} a @ A::Bs(_) => {} - A::Cs(${0:_}) => todo!(), + A::Cs(${1:_}) => ${0:todo!()}, } } "#, @@ -945,11 +951,11 @@ enum A { As, Bs, Cs(String), Ds(String, String), Es { x: usize, y: usize } } fn main() { let a = A::As; match a { - $0A::As => todo!(), - A::Bs => todo!(), - A::Cs(_) => todo!(), - A::Ds(_, _) => todo!(), - A::Es { x, y } => todo!(), + A::As => ${1:todo!()}, + A::Bs => ${2:todo!()}, + A::Cs(_) => ${3:todo!()}, + A::Ds(_, _) => ${4:todo!()}, + A::Es { x, y } => ${0:todo!()}, } } "#, @@ -982,9 +988,9 @@ fn main() { let b = B::One; match (a, b) { (A::Two, B::One) => {}, - $0(A::One, B::One) => todo!(), - (A::One, B::Two) => todo!(), - (A::Two, B::Two) => todo!(), + (A::One, B::One) => ${1:todo!()}, + (A::One, B::Two) => ${2:todo!()}, + (A::Two, B::Two) => ${0:todo!()}, } } "#, @@ -1013,10 +1019,10 @@ fn main() { let a = A::One; let b = B::One; match (a, b) { - $0(A::One, B::One) => todo!(), - (A::One, B::Two) => todo!(), - (A::Two, B::One) => todo!(), - (A::Two, B::Two) => todo!(), + (A::One, B::One) => ${1:todo!()}, + (A::One, B::Two) => ${2:todo!()}, + (A::Two, B::One) => ${3:todo!()}, + (A::Two, B::Two) => ${0:todo!()}, } } "#, @@ -1045,10 +1051,10 @@ fn main() { let a = A::One; let b = B::One; match (&a, &b) { - $0(A::One, B::One) => todo!(), - (A::One, B::Two) => todo!(), - (A::Two, B::One) => todo!(), - (A::Two, B::Two) => todo!(), + (A::One, B::One) => ${1:todo!()}, + (A::One, B::Two) => ${2:todo!()}, + (A::Two, B::One) => ${3:todo!()}, + (A::Two, B::Two) => ${0:todo!()}, } } "#, @@ -1080,9 +1086,9 @@ fn main() { let b = B::One; match (a, b) { (A::Two, B::One) => {} - $0(A::One, B::One) => todo!(), - (A::One, B::Two) => todo!(), - (A::Two, B::Two) => todo!(), + (A::One, B::One) => ${1:todo!()}, + (A::One, B::Two) => ${2:todo!()}, + (A::Two, B::Two) => ${0:todo!()}, } } "#, @@ -1107,9 +1113,9 @@ fn main() { match (A, B, C) { (A | B , A, A | B | C) => (), (A | B | C , B | C, A | B | C) => (), - $0(C, A, A) => todo!(), - (C, A, B) => todo!(), - (C, A, C) => todo!(), + (C, A, A) => ${1:todo!()}, + (C, A, B) => ${2:todo!()}, + (C, A, C) => ${0:todo!()}, } } "#, @@ -1138,7 +1144,7 @@ fn main() { match (a, b) { (Some(_), _) => {} (None, Some(_)) => {} - $0(None, None) => todo!(), + (None, None) => ${0:todo!()}, } } "#, @@ -1203,8 +1209,8 @@ enum A { One, Two } fn main() { let a = A::One; match (a, ) { - $0(A::One,) => todo!(), - (A::Two,) => todo!(), + (A::One,) => ${1:todo!()}, + (A::Two,) => ${0:todo!()}, } } "#, @@ -1228,7 +1234,7 @@ enum A { As } fn foo(a: &A) { match a { - $0A::As => todo!(), + A::As => ${0:todo!()}, } } "#, @@ -1253,7 +1259,7 @@ enum A { fn foo(a: &mut A) { match a { - $0A::Es { x, y } => todo!(), + A::Es { x, y } => ${0:todo!()}, } } "#, @@ -1313,8 +1319,8 @@ enum E { X, Y } fn main() { match E::X { - $0E::X => todo!(), - E::Y => todo!(), + E::X => ${1:todo!()}, + E::Y => ${0:todo!()}, } } "#, @@ -1360,8 +1366,8 @@ use foo::E::X; fn main() { match X { - $0X => todo!(), - foo::E::Y => todo!(), + X => ${1:todo!()}, + foo::E::Y => ${0:todo!()}, } } "#, @@ -1388,7 +1394,7 @@ fn foo(a: A) { match a { // foo bar baz A::One => {} - $0A::Two => todo!(), + A::Two => ${0:todo!()}, // This is where the rest should be } } @@ -1412,8 +1418,8 @@ fn foo(a: A) { enum A { One, Two } fn foo(a: A) { match a { - $0A::One => todo!(), - A::Two => todo!(), + A::One => ${1:todo!()}, + A::Two => ${0:todo!()}, // foo bar baz } } @@ -1437,8 +1443,8 @@ fn foo(a: A) { enum A { One, Two, } fn foo(a: A) { match a { - $0A::One => todo!(), - A::Two => todo!(), + A::One => ${1:todo!()}, + A::Two => ${0:todo!()}, } } "#, @@ -1460,8 +1466,8 @@ fn foo(opt: Option) { r#" fn foo(opt: Option) { match opt { - Some(${0:_}) => todo!(), - None => todo!(), + Some(${1:_}) => ${2:todo!()}, + None => ${0:todo!()}, } } "#, @@ -1493,9 +1499,9 @@ enum Test { fn foo(t: Test) { m!(match t { - $0Test::A => todo!(), - Test::B => todo!(), - Test::C => todo!(), + Test::A => ${1:todo!()}, + Test::B => ${2:todo!()}, + Test::C => ${0:todo!()}, }); }"#, ); @@ -1530,7 +1536,7 @@ fn foo(t: bool) { fn foo(t: bool) { match t { true => 1 + 2, - $0false => todo!(), + false => ${0:todo!()}, } }"#, ); @@ -1550,7 +1556,7 @@ fn foo(t: bool) { fn foo(t: bool) { match t { true => 1 + 2, - $0false => todo!(), + false => ${0:todo!()}, } }"#, ); @@ -1571,8 +1577,8 @@ fn foo(t: bool) { fn foo(t: bool) { match t { _ => 1 + 2, - $0true => todo!(), - false => todo!(), + true => ${1:todo!()}, + false => ${0:todo!()}, } }"#, ); @@ -1595,8 +1601,8 @@ pub enum E { A, #[doc(hidden)] B, } r#" fn foo(t: ::e::E) { match t { - $0e::E::A => todo!(), - _ => todo!(), + e::E::A => ${1:todo!()}, + _ => ${0:todo!()}, } } "#, @@ -1620,9 +1626,9 @@ pub enum E { A, #[doc(hidden)] B, } r#" fn foo(t: (bool, ::e::E)) { match t { - $0(true, e::E::A) => todo!(), - (false, e::E::A) => todo!(), - _ => todo!(), + (true, e::E::A) => ${1:todo!()}, + (false, e::E::A) => ${2:todo!()}, + _ => ${0:todo!()}, } } "#, @@ -1646,7 +1652,7 @@ pub enum E { #[doc(hidden)] A, } r#" fn foo(t: ::e::E) { match t { - ${0:_} => todo!(), + ${1:_} => ${0:todo!()}, } } "#, @@ -1707,7 +1713,7 @@ pub enum E { A, } fn foo(t: ::e::E) { match t { e::E::A => todo!(), - ${0:_} => todo!(), + ${1:_} => ${0:todo!()}, } } "#, @@ -1732,8 +1738,8 @@ pub enum E { A, } r#" fn foo(t: ::e::E) { match t { - $0e::E::A => todo!(), - _ => todo!(), + e::E::A => ${1:todo!()}, + _ => ${0:todo!()}, } } "#, @@ -1757,8 +1763,8 @@ pub enum E { A, #[doc(hidden)] B }"#, r#" fn foo(t: ::e::E) { match t { - $0e::E::A => todo!(), - _ => todo!(), + e::E::A => ${1:todo!()}, + _ => ${0:todo!()}, } } "#, @@ -1784,7 +1790,7 @@ pub enum E { A, #[doc(hidden)] B }"#, fn foo(t: ::e::E) { match t { e::E::A => todo!(), - ${0:_} => todo!(), + ${1:_} => ${0:todo!()}, } } "#, @@ -1809,7 +1815,7 @@ pub enum E { #[doc(hidden)] A, }"#, fn foo(t: ::e::E, b: bool) { match t { _ if b => todo!(), - ${0:_} => todo!(), + ${1:_} => ${0:todo!()}, } } "#, @@ -1850,8 +1856,8 @@ pub enum E { A, #[doc(hidden)] B, }"#, r#" fn foo(t: ::e::E) { match t { - $0e::E::A => todo!(), - _ => todo!(), + e::E::A => ${1:todo!()}, + _ => ${0:todo!()}, } } "#, @@ -1874,8 +1880,8 @@ enum E { A, #[doc(hidden)] B, } fn foo(t: E) { match t { - $0E::A => todo!(), - E::B => todo!(), + E::A => ${1:todo!()}, + E::B => ${0:todo!()}, } }"#, ); @@ -1899,8 +1905,8 @@ enum E { A, B, } fn foo(t: E) { match t { - $0E::A => todo!(), - E::B => todo!(), + E::A => ${1:todo!()}, + E::B => ${0:todo!()}, } }"#, ); @@ -1924,8 +1930,8 @@ enum E { A, #[doc(hidden)] B, } fn foo(t: E) { match t { - $0E::A => todo!(), - E::B => todo!(), + E::A => ${1:todo!()}, + E::B => ${0:todo!()}, } }"#, ); @@ -1975,8 +1981,8 @@ enum A { fn a() { let b = A::A; match b { - $0A::A => todo!(), - A::Missing { a, u32, c } => todo!(), + A::A => ${1:todo!()}, + A::Missing { a, u32, c } => ${0:todo!()}, } }"#, ) @@ -2013,8 +2019,8 @@ pub enum E { fn f() { let value = E::A; match value { - $0E::A => todo!(), - E::B(s) => todo!(), + E::A => ${1:todo!()}, + E::B(s) => ${0:todo!()}, } } "#, @@ -2051,8 +2057,8 @@ pub enum E { fn f() { let value = E::A; match value { - $0E::A => todo!(), - E::B(s1, s2) => todo!(), + E::A => ${1:todo!()}, + E::B(s1, s2) => ${0:todo!()}, } } "#, diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index 64b7ab1a12..8fffe7713f 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -187,8 +187,8 @@ enum Action { Move { distance: u32 }, Stop } fn handle(action: Action) { match action { - $0Action::Move { distance } => todo!(), - Action::Stop => todo!(), + Action::Move { distance } => ${1:todo!()}, + Action::Stop => ${0:todo!()}, } } "#####, From 494bde3c13379b04580332a70fdc52bf6147f2b8 Mon Sep 17 00:00:00 2001 From: Giga Bowser <45986823+Giga-Bowser@users.noreply.github.com> Date: Tue, 5 Nov 2024 12:13:42 -0500 Subject: [PATCH 2/2] Properly use final tabstop when adding missing match arms --- .../src/handlers/add_missing_match_arms.rs | 121 ++++++++++-------- crates/ide-assists/src/tests/generated.rs | 2 +- 2 files changed, 66 insertions(+), 57 deletions(-) diff --git a/crates/ide-assists/src/handlers/add_missing_match_arms.rs b/crates/ide-assists/src/handlers/add_missing_match_arms.rs index 71756def14..236d33878e 100644 --- a/crates/ide-assists/src/handlers/add_missing_match_arms.rs +++ b/crates/ide-assists/src/handlers/add_missing_match_arms.rs @@ -31,7 +31,7 @@ use crate::{utils, AssistContext, AssistId, AssistKind, Assists}; // fn handle(action: Action) { // match action { // Action::Move { distance } => ${1:todo!()}, -// Action::Stop => ${0:todo!()}, +// Action::Stop => ${2:todo!()},$0 // } // } // ``` @@ -234,12 +234,11 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) } } + let mut added_arms = Vec::new(); let mut todo_placeholders = Vec::new(); - let mut first_new_arm = None; for arm in missing_arms { todo_placeholders.push(arm.expr().unwrap()); - first_new_arm.get_or_insert_with(|| arm.clone()); - new_match_arm_list.add_arm(arm); + added_arms.push(arm); } if needs_catch_all_arm && !has_catch_all_arm { @@ -251,18 +250,28 @@ pub(crate) fn add_missing_match_arms(acc: &mut Assists, ctx: &AssistContext<'_>) ) .clone_for_update(); todo_placeholders.push(arm.expr().unwrap()); - first_new_arm.get_or_insert_with(|| arm.clone()); + added_arms.push(arm); + } + + let first_new_arm = added_arms.first().cloned(); + let last_new_arm = added_arms.last().cloned(); + + for arm in added_arms { new_match_arm_list.add_arm(arm); } - if let (Some(first_new_arm), Some(cap)) = (first_new_arm, ctx.config.snippet_cap) { - if let Some(it) = first_new_arm.syntax().descendants().find_map(ast::WildcardPat::cast) { + if let Some(cap) = ctx.config.snippet_cap { + if let Some(it) = first_new_arm.and_then(|arm| arm.syntax().descendants().find_map(ast::WildcardPat::cast)) { edit.add_placeholder_snippet(cap, it); } for placeholder in todo_placeholders { edit.add_placeholder_snippet(cap, placeholder); } + + if let Some(arm) = last_new_arm { + edit.add_tabstop_after(cap, arm); + } } // FIXME: Hack for mutable syntax trees not having great support for macros @@ -588,7 +597,7 @@ fn foo(a: bool) { fn foo(a: bool) { match a { true => ${1:todo!()}, - false => ${0:todo!()}, + false => ${2:todo!()},$0 } } "#, @@ -610,7 +619,7 @@ fn foo(a: bool) { fn foo(a: bool) { match a { true => {} - false => ${0:todo!()}, + false => ${1:todo!()},$0 } } "#, @@ -663,7 +672,7 @@ fn foo(a: bool) { (true, true) => ${1:todo!()}, (true, false) => ${2:todo!()}, (false, true) => ${3:todo!()}, - (false, false) => ${0:todo!()}, + (false, false) => ${4:todo!()},$0 } } "#, @@ -684,7 +693,7 @@ fn foo(a: bool) { fn foo(a: bool) { match [a] { [true] => ${1:todo!()}, - [false] => ${0:todo!()}, + [false] => ${2:todo!()},$0 } } "#, @@ -702,7 +711,7 @@ fn foo(a: bool) { fn foo(a: bool) { match [a,] { [true] => ${1:todo!()}, - [false] => ${0:todo!()}, + [false] => ${2:todo!()},$0 } } "#, @@ -723,7 +732,7 @@ fn foo(a: bool) { [true, true] => todo!(), [true, false] => ${1:todo!()}, [false, true] => ${2:todo!()}, - [false, false] => ${0:todo!()}, + [false, false] => ${3:todo!()},$0 } } "#, @@ -743,7 +752,7 @@ fn foo(a: bool) { [true, true] => ${1:todo!()}, [true, false] => ${2:todo!()}, [false, true] => ${3:todo!()}, - [false, false] => ${0:todo!()}, + [false, false] => ${4:todo!()},$0 } } "#, @@ -766,7 +775,7 @@ fn foo(a: bool) { match (a, a) { (true | false, true) => {} (true, false) => ${1:todo!()}, - (false, false) => ${0:todo!()}, + (false, false) => ${2:todo!()},$0 } } "#, @@ -787,7 +796,7 @@ fn foo(a: bool) { (false, true) => {} (true, true) => ${1:todo!()}, (true, false) => ${2:todo!()}, - (false, false) => ${0:todo!()}, + (false, false) => ${3:todo!()},$0 } } "#, @@ -821,7 +830,7 @@ fn main() { match A::As { A::Bs { x, y: Some(_) } => {} A::Cs(_, Some(_)) => {} - A::As => ${0:todo!()}, + A::As => ${1:todo!()},$0 } } "#, @@ -844,7 +853,7 @@ fn main() { fn main() { match None { None => {} - Some(${1:_}) => ${0:todo!()}, + Some(${1:_}) => ${2:todo!()},$0 } } "#, @@ -868,7 +877,7 @@ enum A { As, Bs, Cs(Option) } fn main() { match A::As { A::Cs(_) | A::Bs => {} - A::As => ${0:todo!()}, + A::As => ${1:todo!()},$0 } } "#, @@ -899,7 +908,7 @@ fn main() { A::Ds(_value) => { let x = 1; } A::Es(B::Xs) => (), A::As => ${1:todo!()}, - A::Cs => ${0:todo!()}, + A::Cs => ${2:todo!()},$0 } } "#, @@ -925,7 +934,7 @@ fn main() { match A::As { A::As(_) => {} a @ A::Bs(_) => {} - A::Cs(${1:_}) => ${0:todo!()}, + A::Cs(${1:_}) => ${2:todo!()},$0 } } "#, @@ -955,7 +964,7 @@ fn main() { A::Bs => ${2:todo!()}, A::Cs(_) => ${3:todo!()}, A::Ds(_, _) => ${4:todo!()}, - A::Es { x, y } => ${0:todo!()}, + A::Es { x, y } => ${5:todo!()},$0 } } "#, @@ -990,7 +999,7 @@ fn main() { (A::Two, B::One) => {}, (A::One, B::One) => ${1:todo!()}, (A::One, B::Two) => ${2:todo!()}, - (A::Two, B::Two) => ${0:todo!()}, + (A::Two, B::Two) => ${3:todo!()},$0 } } "#, @@ -1022,7 +1031,7 @@ fn main() { (A::One, B::One) => ${1:todo!()}, (A::One, B::Two) => ${2:todo!()}, (A::Two, B::One) => ${3:todo!()}, - (A::Two, B::Two) => ${0:todo!()}, + (A::Two, B::Two) => ${4:todo!()},$0 } } "#, @@ -1054,7 +1063,7 @@ fn main() { (A::One, B::One) => ${1:todo!()}, (A::One, B::Two) => ${2:todo!()}, (A::Two, B::One) => ${3:todo!()}, - (A::Two, B::Two) => ${0:todo!()}, + (A::Two, B::Two) => ${4:todo!()},$0 } } "#, @@ -1088,7 +1097,7 @@ fn main() { (A::Two, B::One) => {} (A::One, B::One) => ${1:todo!()}, (A::One, B::Two) => ${2:todo!()}, - (A::Two, B::Two) => ${0:todo!()}, + (A::Two, B::Two) => ${3:todo!()},$0 } } "#, @@ -1115,7 +1124,7 @@ fn main() { (A | B | C , B | C, A | B | C) => (), (C, A, A) => ${1:todo!()}, (C, A, B) => ${2:todo!()}, - (C, A, C) => ${0:todo!()}, + (C, A, C) => ${3:todo!()},$0 } } "#, @@ -1144,7 +1153,7 @@ fn main() { match (a, b) { (Some(_), _) => {} (None, Some(_)) => {} - (None, None) => ${0:todo!()}, + (None, None) => ${1:todo!()},$0 } } "#, @@ -1210,7 +1219,7 @@ fn main() { let a = A::One; match (a, ) { (A::One,) => ${1:todo!()}, - (A::Two,) => ${0:todo!()}, + (A::Two,) => ${2:todo!()},$0 } } "#, @@ -1234,7 +1243,7 @@ enum A { As } fn foo(a: &A) { match a { - A::As => ${0:todo!()}, + A::As => ${1:todo!()},$0 } } "#, @@ -1259,7 +1268,7 @@ enum A { fn foo(a: &mut A) { match a { - A::Es { x, y } => ${0:todo!()}, + A::Es { x, y } => ${1:todo!()},$0 } } "#, @@ -1320,7 +1329,7 @@ enum E { X, Y } fn main() { match E::X { E::X => ${1:todo!()}, - E::Y => ${0:todo!()}, + E::Y => ${2:todo!()},$0 } } "#, @@ -1367,7 +1376,7 @@ use foo::E::X; fn main() { match X { X => ${1:todo!()}, - foo::E::Y => ${0:todo!()}, + foo::E::Y => ${2:todo!()},$0 } } "#, @@ -1394,7 +1403,7 @@ fn foo(a: A) { match a { // foo bar baz A::One => {} - A::Two => ${0:todo!()}, + A::Two => ${1:todo!()},$0 // This is where the rest should be } } @@ -1419,7 +1428,7 @@ enum A { One, Two } fn foo(a: A) { match a { A::One => ${1:todo!()}, - A::Two => ${0:todo!()}, + A::Two => ${2:todo!()},$0 // foo bar baz } } @@ -1444,7 +1453,7 @@ enum A { One, Two, } fn foo(a: A) { match a { A::One => ${1:todo!()}, - A::Two => ${0:todo!()}, + A::Two => ${2:todo!()},$0 } } "#, @@ -1467,7 +1476,7 @@ fn foo(opt: Option) { fn foo(opt: Option) { match opt { Some(${1:_}) => ${2:todo!()}, - None => ${0:todo!()}, + None => ${3:todo!()},$0 } } "#, @@ -1501,7 +1510,7 @@ fn foo(t: Test) { m!(match t { Test::A => ${1:todo!()}, Test::B => ${2:todo!()}, - Test::C => ${0:todo!()}, + Test::C => ${3:todo!()},$0 }); }"#, ); @@ -1536,7 +1545,7 @@ fn foo(t: bool) { fn foo(t: bool) { match t { true => 1 + 2, - false => ${0:todo!()}, + false => ${1:todo!()},$0 } }"#, ); @@ -1556,7 +1565,7 @@ fn foo(t: bool) { fn foo(t: bool) { match t { true => 1 + 2, - false => ${0:todo!()}, + false => ${1:todo!()},$0 } }"#, ); @@ -1578,7 +1587,7 @@ fn foo(t: bool) { match t { _ => 1 + 2, true => ${1:todo!()}, - false => ${0:todo!()}, + false => ${2:todo!()},$0 } }"#, ); @@ -1602,7 +1611,7 @@ pub enum E { A, #[doc(hidden)] B, } fn foo(t: ::e::E) { match t { e::E::A => ${1:todo!()}, - _ => ${0:todo!()}, + _ => ${2:todo!()},$0 } } "#, @@ -1628,7 +1637,7 @@ fn foo(t: (bool, ::e::E)) { match t { (true, e::E::A) => ${1:todo!()}, (false, e::E::A) => ${2:todo!()}, - _ => ${0:todo!()}, + _ => ${3:todo!()},$0 } } "#, @@ -1652,7 +1661,7 @@ pub enum E { #[doc(hidden)] A, } r#" fn foo(t: ::e::E) { match t { - ${1:_} => ${0:todo!()}, + ${1:_} => ${2:todo!()},$0 } } "#, @@ -1713,7 +1722,7 @@ pub enum E { A, } fn foo(t: ::e::E) { match t { e::E::A => todo!(), - ${1:_} => ${0:todo!()}, + ${1:_} => ${2:todo!()},$0 } } "#, @@ -1739,7 +1748,7 @@ pub enum E { A, } fn foo(t: ::e::E) { match t { e::E::A => ${1:todo!()}, - _ => ${0:todo!()}, + _ => ${2:todo!()},$0 } } "#, @@ -1764,7 +1773,7 @@ pub enum E { A, #[doc(hidden)] B }"#, fn foo(t: ::e::E) { match t { e::E::A => ${1:todo!()}, - _ => ${0:todo!()}, + _ => ${2:todo!()},$0 } } "#, @@ -1790,7 +1799,7 @@ pub enum E { A, #[doc(hidden)] B }"#, fn foo(t: ::e::E) { match t { e::E::A => todo!(), - ${1:_} => ${0:todo!()}, + ${1:_} => ${2:todo!()},$0 } } "#, @@ -1815,7 +1824,7 @@ pub enum E { #[doc(hidden)] A, }"#, fn foo(t: ::e::E, b: bool) { match t { _ if b => todo!(), - ${1:_} => ${0:todo!()}, + ${1:_} => ${2:todo!()},$0 } } "#, @@ -1857,7 +1866,7 @@ pub enum E { A, #[doc(hidden)] B, }"#, fn foo(t: ::e::E) { match t { e::E::A => ${1:todo!()}, - _ => ${0:todo!()}, + _ => ${2:todo!()},$0 } } "#, @@ -1881,7 +1890,7 @@ enum E { A, #[doc(hidden)] B, } fn foo(t: E) { match t { E::A => ${1:todo!()}, - E::B => ${0:todo!()}, + E::B => ${2:todo!()},$0 } }"#, ); @@ -1906,7 +1915,7 @@ enum E { A, B, } fn foo(t: E) { match t { E::A => ${1:todo!()}, - E::B => ${0:todo!()}, + E::B => ${2:todo!()},$0 } }"#, ); @@ -1931,7 +1940,7 @@ enum E { A, #[doc(hidden)] B, } fn foo(t: E) { match t { E::A => ${1:todo!()}, - E::B => ${0:todo!()}, + E::B => ${2:todo!()},$0 } }"#, ); @@ -1982,7 +1991,7 @@ fn a() { let b = A::A; match b { A::A => ${1:todo!()}, - A::Missing { a, u32, c } => ${0:todo!()}, + A::Missing { a, u32, c } => ${2:todo!()},$0 } }"#, ) @@ -2020,7 +2029,7 @@ fn f() { let value = E::A; match value { E::A => ${1:todo!()}, - E::B(s) => ${0:todo!()}, + E::B(s) => ${2:todo!()},$0 } } "#, @@ -2058,7 +2067,7 @@ fn f() { let value = E::A; match value { E::A => ${1:todo!()}, - E::B(s1, s2) => ${0:todo!()}, + E::B(s1, s2) => ${2:todo!()},$0 } } "#, diff --git a/crates/ide-assists/src/tests/generated.rs b/crates/ide-assists/src/tests/generated.rs index 8fffe7713f..eef4da55e9 100644 --- a/crates/ide-assists/src/tests/generated.rs +++ b/crates/ide-assists/src/tests/generated.rs @@ -188,7 +188,7 @@ enum Action { Move { distance: u32 }, Stop } fn handle(action: Action) { match action { Action::Move { distance } => ${1:todo!()}, - Action::Stop => ${0:todo!()}, + Action::Stop => ${2:todo!()},$0 } } "#####,