aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_assists/src/add_impl.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_impl.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_impl.rs')
-rw-r--r--crates/ra_assists/src/add_impl.rs17
1 files changed, 16 insertions, 1 deletions
diff --git a/crates/ra_assists/src/add_impl.rs b/crates/ra_assists/src/add_impl.rs
index f2360bc89..32fc074a6 100644
--- a/crates/ra_assists/src/add_impl.rs
+++ b/crates/ra_assists/src/add_impl.rs
@@ -11,6 +11,7 @@ pub(crate) fn add_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
11 let nominal = ctx.node_at_offset::<ast::NominalDef>()?; 11 let nominal = ctx.node_at_offset::<ast::NominalDef>()?;
12 let name = nominal.name()?; 12 let name = nominal.name()?;
13 ctx.build("add impl", |edit| { 13 ctx.build("add impl", |edit| {
14 edit.target(nominal.syntax().range());
14 let type_params = nominal.type_param_list(); 15 let type_params = nominal.type_param_list();
15 let start_offset = nominal.syntax().range().end(); 16 let start_offset = nominal.syntax().range().end();
16 let mut buf = String::new(); 17 let mut buf = String::new();
@@ -37,7 +38,7 @@ pub(crate) fn add_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
37#[cfg(test)] 38#[cfg(test)]
38mod tests { 39mod tests {
39 use super::*; 40 use super::*;
40 use crate::helpers::check_assist; 41 use crate::helpers::{check_assist, check_assist_target};
41 42
42 #[test] 43 #[test]
43 fn test_add_impl() { 44 fn test_add_impl() {
@@ -54,4 +55,18 @@ mod tests {
54 ); 55 );
55 } 56 }
56 57
58 #[test]
59 fn add_impl_target() {
60 check_assist_target(
61 add_impl,
62 "
63struct SomeThingIrrelevant;
64/// Has a lifetime parameter
65struct Foo<'a, T: Foo<'a>> {<|>}
66struct EvenMoreIrrelevant;
67",
68 "/// Has a lifetime parameter
69struct Foo<'a, T: Foo<'a>> {}",
70 );
71 }
57} 72}