aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/ra_assists/src/assists/add_custom_impl.rs17
-rw-r--r--crates/ra_assists/src/doc_tests/generated.rs19
-rw-r--r--docs/user/assists.md18
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
13const DERIVE_TRAIT: &'static str = "derive"; 13const 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// ```
15pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> { 32pub(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 @@
3use super::check; 3use super::check;
4 4
5#[test] 5#[test]
6fn doctest_add_custom_impl() {
7 check(
8 "add_custom_impl",
9 r#####"
10#[derive(Deb<|>ug, Display)]
11struct S;
12"#####,
13 r#####"
14#[derive(Display)]
15struct S;
16
17impl Debug for S {
18
19}
20"#####,
21 )
22}
23
24#[test]
6fn doctest_add_derive() { 25fn 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 @@
3Cursor position or selection is signified by `┃` character. 3Cursor position or selection is signified by `┃` character.
4 4
5 5
6## `add_custom_impl`
7
8Adds impl block for derived trait.
9
10```rust
11// BEFORE
12#[derive(Deb┃ug, Display)]
13struct S;
14
15// AFTER
16#[derive(Display)]
17struct S;
18
19impl Debug for S {
20
21}
22```
23
6## `add_derive` 24## `add_derive`
7 25
8Adds a new `#[derive()]` clause to a struct or enum. 26Adds a new `#[derive()]` clause to a struct or enum.