diff options
-rw-r--r-- | crates/ra_assists/src/assists/add_custom_impl.rs | 17 | ||||
-rw-r--r-- | crates/ra_assists/src/doc_tests/generated.rs | 19 | ||||
-rw-r--r-- | docs/user/assists.md | 18 |
3 files changed, 54 insertions, 0 deletions
diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/assists/add_custom_impl.rs index 7e64cd902..037306fd6 100644 --- a/crates/ra_assists/src/assists/add_custom_impl.rs +++ b/crates/ra_assists/src/assists/add_custom_impl.rs | |||
@@ -12,6 +12,23 @@ use ra_syntax::{ | |||
12 | 12 | ||
13 | const DERIVE_TRAIT: &'static str = "derive"; | 13 | const DERIVE_TRAIT: &'static str = "derive"; |
14 | 14 | ||
15 | // Assist: add_custom_impl | ||
16 | // | ||
17 | // Adds impl block for derived trait. | ||
18 | // | ||
19 | // ``` | ||
20 | // #[derive(Deb<|>ug, Display)] | ||
21 | // struct S; | ||
22 | // ``` | ||
23 | // -> | ||
24 | // ``` | ||
25 | // #[derive(Display)] | ||
26 | // struct S; | ||
27 | // | ||
28 | // impl Debug for S { | ||
29 | // | ||
30 | // } | ||
31 | // ``` | ||
15 | pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { | 32 | pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { |
16 | let input = ctx.find_node_at_offset::<ast::AttrInput>()?; | 33 | let input = ctx.find_node_at_offset::<ast::AttrInput>()?; |
17 | let attr = input.syntax().parent().and_then(ast::Attr::cast)?; | 34 | let attr = input.syntax().parent().and_then(ast::Attr::cast)?; |
diff --git a/crates/ra_assists/src/doc_tests/generated.rs b/crates/ra_assists/src/doc_tests/generated.rs index 3c716c2d1..4586eeb59 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs | |||
@@ -3,6 +3,25 @@ | |||
3 | use super::check; | 3 | use super::check; |
4 | 4 | ||
5 | #[test] | 5 | #[test] |
6 | fn doctest_add_custom_impl() { | ||
7 | check( | ||
8 | "add_custom_impl", | ||
9 | r#####" | ||
10 | #[derive(Deb<|>ug, Display)] | ||
11 | struct S; | ||
12 | "#####, | ||
13 | r#####" | ||
14 | #[derive(Display)] | ||
15 | struct S; | ||
16 | |||
17 | impl Debug for S { | ||
18 | |||
19 | } | ||
20 | "#####, | ||
21 | ) | ||
22 | } | ||
23 | |||
24 | #[test] | ||
6 | fn doctest_add_derive() { | 25 | fn doctest_add_derive() { |
7 | check( | 26 | check( |
8 | "add_derive", | 27 | "add_derive", |
diff --git a/docs/user/assists.md b/docs/user/assists.md index 6f4c30bee..334ba450f 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -3,6 +3,24 @@ | |||
3 | Cursor position or selection is signified by `┃` character. | 3 | Cursor position or selection is signified by `┃` character. |
4 | 4 | ||
5 | 5 | ||
6 | ## `add_custom_impl` | ||
7 | |||
8 | Adds impl block for derived trait. | ||
9 | |||
10 | ```rust | ||
11 | // BEFORE | ||
12 | #[derive(Deb┃ug, Display)] | ||
13 | struct S; | ||
14 | |||
15 | // AFTER | ||
16 | #[derive(Display)] | ||
17 | struct S; | ||
18 | |||
19 | impl Debug for S { | ||
20 | |||
21 | } | ||
22 | ``` | ||
23 | |||
6 | ## `add_derive` | 24 | ## `add_derive` |
7 | 25 | ||
8 | Adds a new `#[derive()]` clause to a struct or enum. | 26 | Adds a new `#[derive()]` clause to a struct or enum. |