diff options
Diffstat (limited to 'crates/ra_assists/src/handlers/unwrap_block.rs')
-rw-r--r-- | crates/ra_assists/src/handlers/unwrap_block.rs | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/crates/ra_assists/src/handlers/unwrap_block.rs b/crates/ra_assists/src/handlers/unwrap_block.rs index b76182d79..8440c7d0f 100644 --- a/crates/ra_assists/src/handlers/unwrap_block.rs +++ b/crates/ra_assists/src/handlers/unwrap_block.rs | |||
@@ -62,7 +62,6 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
62 | let range_to_del_else_if = TextRange::new(ancestor_then_branch.syntax().text_range().end(), l_curly_token.text_range().start()); | 62 | let range_to_del_else_if = TextRange::new(ancestor_then_branch.syntax().text_range().end(), l_curly_token.text_range().start()); |
63 | let range_to_del_rest = TextRange::new(then_branch.syntax().text_range().end(), if_expr.syntax().text_range().end()); | 63 | let range_to_del_rest = TextRange::new(then_branch.syntax().text_range().end(), if_expr.syntax().text_range().end()); |
64 | 64 | ||
65 | edit.set_cursor(ancestor_then_branch.syntax().text_range().end()); | ||
66 | edit.delete(range_to_del_rest); | 65 | edit.delete(range_to_del_rest); |
67 | edit.delete(range_to_del_else_if); | 66 | edit.delete(range_to_del_else_if); |
68 | edit.replace(target, update_expr_string(then_branch.to_string(), &[' ', '{'])); | 67 | edit.replace(target, update_expr_string(then_branch.to_string(), &[' ', '{'])); |
@@ -79,7 +78,6 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
79 | return acc.add(assist_id, assist_label, target, |edit| { | 78 | return acc.add(assist_id, assist_label, target, |edit| { |
80 | let range_to_del = TextRange::new(then_branch.syntax().text_range().end(), l_curly_token.text_range().start()); | 79 | let range_to_del = TextRange::new(then_branch.syntax().text_range().end(), l_curly_token.text_range().start()); |
81 | 80 | ||
82 | edit.set_cursor(then_branch.syntax().text_range().end()); | ||
83 | edit.delete(range_to_del); | 81 | edit.delete(range_to_del); |
84 | edit.replace(target, update_expr_string(else_block.to_string(), &[' ', '{'])); | 82 | edit.replace(target, update_expr_string(else_block.to_string(), &[' ', '{'])); |
85 | }); | 83 | }); |
@@ -97,8 +95,6 @@ pub(crate) fn unwrap_block(acc: &mut Assists, ctx: &AssistContext) -> Option<()> | |||
97 | 95 | ||
98 | let target = expr_to_unwrap.syntax().text_range(); | 96 | let target = expr_to_unwrap.syntax().text_range(); |
99 | acc.add(assist_id, assist_label, target, |edit| { | 97 | acc.add(assist_id, assist_label, target, |edit| { |
100 | edit.set_cursor(expr.syntax().text_range().start()); | ||
101 | |||
102 | edit.replace( | 98 | edit.replace( |
103 | expr.syntax().text_range(), | 99 | expr.syntax().text_range(), |
104 | update_expr_string(expr_to_unwrap.to_string(), &[' ', '{', '\n']), | 100 | update_expr_string(expr_to_unwrap.to_string(), &[' ', '{', '\n']), |
@@ -154,7 +150,7 @@ mod tests { | |||
154 | r#" | 150 | r#" |
155 | fn main() { | 151 | fn main() { |
156 | bar(); | 152 | bar(); |
157 | <|>foo(); | 153 | foo(); |
158 | 154 | ||
159 | //comment | 155 | //comment |
160 | bar(); | 156 | bar(); |
@@ -188,7 +184,7 @@ mod tests { | |||
188 | 184 | ||
189 | //comment | 185 | //comment |
190 | bar(); | 186 | bar(); |
191 | }<|> | 187 | } |
192 | println!("bar"); | 188 | println!("bar"); |
193 | } | 189 | } |
194 | "#, | 190 | "#, |
@@ -222,7 +218,7 @@ mod tests { | |||
222 | 218 | ||
223 | //comment | 219 | //comment |
224 | //bar(); | 220 | //bar(); |
225 | }<|> | 221 | } |
226 | println!("bar"); | 222 | println!("bar"); |
227 | } | 223 | } |
228 | "#, | 224 | "#, |
@@ -258,7 +254,7 @@ mod tests { | |||
258 | //bar(); | 254 | //bar(); |
259 | } else if false { | 255 | } else if false { |
260 | println!("bar"); | 256 | println!("bar"); |
261 | }<|> | 257 | } |
262 | println!("foo"); | 258 | println!("foo"); |
263 | } | 259 | } |
264 | "#, | 260 | "#, |
@@ -298,7 +294,7 @@ mod tests { | |||
298 | println!("bar"); | 294 | println!("bar"); |
299 | } else if true { | 295 | } else if true { |
300 | println!("foo"); | 296 | println!("foo"); |
301 | }<|> | 297 | } |
302 | println!("else"); | 298 | println!("else"); |
303 | } | 299 | } |
304 | "#, | 300 | "#, |
@@ -336,7 +332,7 @@ mod tests { | |||
336 | //bar(); | 332 | //bar(); |
337 | } else if false { | 333 | } else if false { |
338 | println!("bar"); | 334 | println!("bar"); |
339 | }<|> | 335 | } |
340 | println!("foo"); | 336 | println!("foo"); |
341 | } | 337 | } |
342 | "#, | 338 | "#, |
@@ -383,7 +379,7 @@ mod tests { | |||
383 | "#, | 379 | "#, |
384 | r#" | 380 | r#" |
385 | fn main() { | 381 | fn main() { |
386 | <|>if true { | 382 | if true { |
387 | foo(); | 383 | foo(); |
388 | 384 | ||
389 | //comment | 385 | //comment |
@@ -417,7 +413,7 @@ mod tests { | |||
417 | r#" | 413 | r#" |
418 | fn main() { | 414 | fn main() { |
419 | for i in 0..5 { | 415 | for i in 0..5 { |
420 | <|>foo(); | 416 | foo(); |
421 | 417 | ||
422 | //comment | 418 | //comment |
423 | bar(); | 419 | bar(); |
@@ -447,7 +443,7 @@ mod tests { | |||
447 | "#, | 443 | "#, |
448 | r#" | 444 | r#" |
449 | fn main() { | 445 | fn main() { |
450 | <|>if true { | 446 | if true { |
451 | foo(); | 447 | foo(); |
452 | 448 | ||
453 | //comment | 449 | //comment |
@@ -480,7 +476,7 @@ mod tests { | |||
480 | "#, | 476 | "#, |
481 | r#" | 477 | r#" |
482 | fn main() { | 478 | fn main() { |
483 | <|>if true { | 479 | if true { |
484 | foo(); | 480 | foo(); |
485 | 481 | ||
486 | //comment | 482 | //comment |