diff options
author | Paulo Lieuthier <[email protected]> | 2019-10-19 12:19:06 +0100 |
---|---|---|
committer | Paulo Lieuthier <[email protected]> | 2019-11-28 20:36:40 +0000 |
commit | 5b2d52c8df5235fce9d2ae78adc3182a9659b268 (patch) | |
tree | fb791abbbd5ad7505282113939b48d9a88f9d6e6 /crates/ra_assists/src | |
parent | 439080f0274cf4def3f393f466ceb05c8cb8bcd2 (diff) |
docs: describe new feature 'add custom impl for derived trait'
Diffstat (limited to 'crates/ra_assists/src')
-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 |
2 files changed, 36 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", |