aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/add_derive.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-02-09 08:52:09 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-02-09 08:52:09 +0000
commit3e8351fb0607f8711749b00d80f68bf25de01a76 (patch)
tree97388dafe71ececcbaf97249021b9c8d49786ccf /crates/ra_assists/src/add_derive.rs
parent12e3b4c70b5ef23b2fdfc197296d483680e125f9 (diff)
parent4fdeb54bb5c7ba0704839a65996766d223c51fc1 (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/add_derive.rs')
-rw-r--r--crates/ra_assists/src/add_derive.rs20
1 files changed, 19 insertions, 1 deletions
diff --git a/crates/ra_assists/src/add_derive.rs b/crates/ra_assists/src/add_derive.rs
index caf21e079..ea9707631 100644
--- a/crates/ra_assists/src/add_derive.rs
+++ b/crates/ra_assists/src/add_derive.rs
@@ -24,6 +24,7 @@ pub(crate) fn add_derive(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
24 } 24 }
25 Some(tt) => tt.syntax().range().end() - TextUnit::of_char(')'), 25 Some(tt) => tt.syntax().range().end() - TextUnit::of_char(')'),
26 }; 26 };
27 edit.target(nominal.syntax().range());
27 edit.set_cursor(offset) 28 edit.set_cursor(offset)
28 }) 29 })
29} 30}
@@ -38,7 +39,7 @@ fn derive_insertion_offset(nominal: &ast::NominalDef) -> Option<TextUnit> {
38#[cfg(test)] 39#[cfg(test)]
39mod tests { 40mod tests {
40 use super::*; 41 use super::*;
41 use crate::helpers::check_assist; 42 use crate::helpers::{check_assist, check_assist_target};
42 43
43 #[test] 44 #[test]
44 fn add_derive_new() { 45 fn add_derive_new() {
@@ -80,4 +81,21 @@ struct Foo { a: i32, }
80 ", 81 ",
81 ); 82 );
82 } 83 }
84
85 #[test]
86 fn add_derive_target() {
87 check_assist_target(
88 add_derive,
89 "
90struct SomeThingIrrelevant;
91/// `Foo` is a pretty important struct.
92/// It does stuff.
93struct Foo { a: i32<|>, }
94struct EvenMoreIrrelevant;
95 ",
96 "/// `Foo` is a pretty important struct.
97/// It does stuff.
98struct Foo { a: i32, }",
99 );
100 }
83} 101}