docs: describe new feature 'add custom impl for derived trait'

This commit is contained in:
Paulo Lieuthier 2019-10-19 08:19:06 -03:00
parent 439080f027
commit 5b2d52c8df
3 changed files with 54 additions and 0 deletions

View file

@ -12,6 +12,23 @@ use ra_syntax::{
const DERIVE_TRAIT: &'static str = "derive";
// Assist: add_custom_impl
//
// Adds impl block for derived trait.
//
// ```
// #[derive(Deb<|>ug, Display)]
// struct S;
// ```
// ->
// ```
// #[derive(Display)]
// struct S;
//
// impl Debug for S {
//
// }
// ```
pub(crate) fn add_custom_impl(ctx: AssistCtx<impl HirDatabase>) -> Option<Assist> {
let input = ctx.find_node_at_offset::<ast::AttrInput>()?;
let attr = input.syntax().parent().and_then(ast::Attr::cast)?;

View file

@ -2,6 +2,25 @@
use super::check;
#[test]
fn doctest_add_custom_impl() {
check(
"add_custom_impl",
r#####"
#[derive(Deb<|>ug, Display)]
struct S;
"#####,
r#####"
#[derive(Display)]
struct S;
impl Debug for S {
}
"#####,
)
}
#[test]
fn doctest_add_derive() {
check(

View file

@ -3,6 +3,24 @@
Cursor position or selection is signified by `┃` character.
## `add_custom_impl`
Adds impl block for derived trait.
```rust
// BEFORE
#[derive(Deb┃ug, Display)]
struct S;
// AFTER
#[derive(Display)]
struct S;
impl Debug for S {
}
```
## `add_derive`
Adds a new `#[derive()]` clause to a struct or enum.