diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-09 08:52:09 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2019-02-09 08:52:09 +0000 |
commit | 3e8351fb0607f8711749b00d80f68bf25de01a76 (patch) | |
tree | 97388dafe71ececcbaf97249021b9c8d49786ccf /crates/ra_assists/src/flip_comma.rs | |
parent | 12e3b4c70b5ef23b2fdfc197296d483680e125f9 (diff) | |
parent | 4fdeb54bb5c7ba0704839a65996766d223c51fc1 (diff) |
Merge #768
768: Sort assists by the range of the affected element r=matklad a=robojumper
Closes #763.
https://github.com/rust-analyzer/rust-analyzer/blob/3be98f2ac93b278828e76eb813bdd8033f647b12/crates/ra_assists/src/lib.rs#L233-L236
This could be made more robust by a) adding a way to identify actions by things other than their label and b) allowing arbitrary actions to appear in the list as long as the tested actions are there in the correct order. Let me know if I should do any of that.
Co-authored-by: robojumper <[email protected]>
Diffstat (limited to 'crates/ra_assists/src/flip_comma.rs')
-rw-r--r-- | crates/ra_assists/src/flip_comma.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/crates/ra_assists/src/flip_comma.rs b/crates/ra_assists/src/flip_comma.rs index a49820c29..33da58f17 100644 --- a/crates/ra_assists/src/flip_comma.rs +++ b/crates/ra_assists/src/flip_comma.rs | |||
@@ -11,6 +11,7 @@ pub(crate) fn flip_comma(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
11 | let prev = non_trivia_sibling(comma, Direction::Prev)?; | 11 | let prev = non_trivia_sibling(comma, Direction::Prev)?; |
12 | let next = non_trivia_sibling(comma, Direction::Next)?; | 12 | let next = non_trivia_sibling(comma, Direction::Next)?; |
13 | ctx.build("flip comma", |edit| { | 13 | ctx.build("flip comma", |edit| { |
14 | edit.target(comma.range()); | ||
14 | edit.replace(prev.range(), next.text()); | 15 | edit.replace(prev.range(), next.text()); |
15 | edit.replace(next.range(), prev.text()); | 16 | edit.replace(next.range(), prev.text()); |
16 | }) | 17 | }) |
@@ -20,7 +21,7 @@ pub(crate) fn flip_comma(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | |||
20 | mod tests { | 21 | mod tests { |
21 | use super::*; | 22 | use super::*; |
22 | 23 | ||
23 | use crate::helpers::check_assist; | 24 | use crate::helpers::{check_assist, check_assist_target}; |
24 | 25 | ||
25 | #[test] | 26 | #[test] |
26 | fn flip_comma_works_for_function_parameters() { | 27 | fn flip_comma_works_for_function_parameters() { |
@@ -30,4 +31,9 @@ mod tests { | |||
30 | "fn foo(y: Result<(), ()>,<|> x: i32) {}", | 31 | "fn foo(y: Result<(), ()>,<|> x: i32) {}", |
31 | ) | 32 | ) |
32 | } | 33 | } |
34 | |||
35 | #[test] | ||
36 | fn flip_comma_target() { | ||
37 | check_assist_target(flip_comma, "fn foo(x: i32,<|> y: Result<(), ()>) {}", ",") | ||
38 | } | ||
33 | } | 39 | } |