diff options
author | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
---|---|---|
committer | Zac Pullar-Strecker <[email protected]> | 2020-07-31 03:12:44 +0100 |
commit | f05d7b41a719d848844b054a16477b29d0f063c6 (patch) | |
tree | 0a8a0946e8aef2ce64d4c13d0035ba41cce2daf3 /crates/ra_assists/src/handlers/move_guard.rs | |
parent | 73ff610e41959e3e7c78a2b4b25b086883132956 (diff) | |
parent | 6b7cb8b5ab539fc4333ce34bc29bf77c976f232a (diff) |
Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links
Hasn't fixed tests yet.
Diffstat (limited to 'crates/ra_assists/src/handlers/move_guard.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/move_guard.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/crates/ra_assists/src/handlers/move_guard.rs b/crates/ra_assists/src/handlers/move_guard.rs index 7edcf0748..4060d34c6 100644 --- a/crates/ra_assists/src/handlers/move_guard.rs +++ b/crates/ra_assists/src/handlers/move_guard.rs | |||
@@ -3,7 +3,7 @@ use ra_syntax::{ | |||
3 | SyntaxKind::WHITESPACE, | 3 | SyntaxKind::WHITESPACE, |
4 | }; | 4 | }; |
5 | 5 | ||
6 | use crate::{AssistContext, AssistId, Assists}; | 6 | use crate::{AssistContext, AssistId, AssistKind, Assists}; |
7 | 7 | ||
8 | // Assist: move_guard_to_arm_body | 8 | // Assist: move_guard_to_arm_body |
9 | // | 9 | // |
@@ -40,17 +40,22 @@ pub(crate) fn move_guard_to_arm_body(acc: &mut Assists, ctx: &AssistContext) -> | |||
40 | let buf = format!("if {} {{ {} }}", guard_conditions.syntax().text(), arm_expr.syntax().text()); | 40 | let buf = format!("if {} {{ {} }}", guard_conditions.syntax().text(), arm_expr.syntax().text()); |
41 | 41 | ||
42 | let target = guard.syntax().text_range(); | 42 | let target = guard.syntax().text_range(); |
43 | acc.add(AssistId("move_guard_to_arm_body"), "Move guard to arm body", target, |edit| { | 43 | acc.add( |
44 | match space_before_guard { | 44 | AssistId("move_guard_to_arm_body", AssistKind::RefactorRewrite), |
45 | Some(element) if element.kind() == WHITESPACE => { | 45 | "Move guard to arm body", |
46 | edit.delete(element.text_range()); | 46 | target, |
47 | } | 47 | |edit| { |
48 | _ => (), | 48 | match space_before_guard { |
49 | }; | 49 | Some(element) if element.kind() == WHITESPACE => { |
50 | edit.delete(element.text_range()); | ||
51 | } | ||
52 | _ => (), | ||
53 | }; | ||
50 | 54 | ||
51 | edit.delete(guard.syntax().text_range()); | 55 | edit.delete(guard.syntax().text_range()); |
52 | edit.replace_node_and_indent(arm_expr.syntax(), buf); | 56 | edit.replace_node_and_indent(arm_expr.syntax(), buf); |
53 | }) | 57 | }, |
58 | ) | ||
54 | } | 59 | } |
55 | 60 | ||
56 | // Assist: move_arm_cond_to_match_guard | 61 | // Assist: move_arm_cond_to_match_guard |
@@ -100,7 +105,7 @@ pub(crate) fn move_arm_cond_to_match_guard(acc: &mut Assists, ctx: &AssistContex | |||
100 | 105 | ||
101 | let target = if_expr.syntax().text_range(); | 106 | let target = if_expr.syntax().text_range(); |
102 | acc.add( | 107 | acc.add( |
103 | AssistId("move_arm_cond_to_match_guard"), | 108 | AssistId("move_arm_cond_to_match_guard", AssistKind::RefactorRewrite), |
104 | "Move condition to match guard", | 109 | "Move condition to match guard", |
105 | target, | 110 | target, |
106 | |edit| { | 111 | |edit| { |