Skip to content

Commit 5b2d52c

Browse files
docs: describe new feature 'add custom impl for derived trait'
1 parent 439080f commit 5b2d52c

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

crates/ra_assists/src/assists/add_custom_impl.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,23 @@ use ra_syntax::{
1212

1313
const DERIVE_TRAIT: &'static str = "derive";
1414

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+
// ```
1532
pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
1633
let input = ctx.find_node_at_offset::<ast::AttrInput>()?;
1734
let attr = input.syntax().parent().and_then(ast::Attr::cast)?;

crates/ra_assists/src/doc_tests/generated.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,25 @@
22
33
use super::check;
44

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+
524
#[test]
625
fn doctest_add_derive() {
726
check(

docs/user/assists.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,24 @@
33
Cursor position or selection is signified by `` character.
44

55

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+
624
## `add_derive`
725

826
Adds a new `#[derive()]` clause to a struct or enum.

0 commit comments

Comments
 (0)