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/fill_match_arms.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/fill_match_arms.rs')
-rw-r--r-- | crates/ra_assists/src/fill_match_arms.rs | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/crates/ra_assists/src/fill_match_arms.rs b/crates/ra_assists/src/fill_match_arms.rs index 741f75e2a..69b535a27 100644 --- a/crates/ra_assists/src/fill_match_arms.rs +++ b/crates/ra_assists/src/fill_match_arms.rs | |||
@@ -65,6 +65,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist | |||
65 | buf.push_str(" => (),\n"); | 65 | buf.push_str(" => (),\n"); |
66 | } | 66 | } |
67 | buf.push_str("}"); | 67 | buf.push_str("}"); |
68 | edit.target(match_expr.syntax().range()); | ||
68 | edit.set_cursor(expr.syntax().range().start()); | 69 | edit.set_cursor(expr.syntax().range().start()); |
69 | edit.replace_node_and_indent(match_expr.syntax(), buf); | 70 | edit.replace_node_and_indent(match_expr.syntax(), buf); |
70 | }) | 71 | }) |
@@ -72,7 +73,7 @@ pub(crate) fn fill_match_arms(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist | |||
72 | 73 | ||
73 | #[cfg(test)] | 74 | #[cfg(test)] |
74 | mod tests { | 75 | mod tests { |
75 | use crate::helpers::check_assist; | 76 | use crate::helpers::{check_assist, check_assist_target}; |
76 | 77 | ||
77 | use super::fill_match_arms; | 78 | use super::fill_match_arms; |
78 | 79 | ||
@@ -139,4 +140,19 @@ mod tests { | |||
139 | "#, | 140 | "#, |
140 | ); | 141 | ); |
141 | } | 142 | } |
143 | |||
144 | #[test] | ||
145 | fn fill_match_arms_target() { | ||
146 | check_assist_target( | ||
147 | fill_match_arms, | ||
148 | r#" | ||
149 | enum E { X, Y} | ||
150 | |||
151 | fn main() { | ||
152 | match E::X<|> {} | ||
153 | } | ||
154 | "#, | ||
155 | "match E::X {}", | ||
156 | ); | ||
157 | } | ||
142 | } | 158 | } |