From 5b2d52c8df5235fce9d2ae78adc3182a9659b268 Mon Sep 17 00:00:00 2001 From: Paulo Lieuthier Date: Sat, 19 Oct 2019 08:19:06 -0300 Subject: [PATCH] docs: describe new feature 'add custom impl for derived trait' --- .../ra_assists/src/assists/add_custom_impl.rs | 17 +++++++++++++++++ crates/ra_assists/src/doc_tests/generated.rs | 19 +++++++++++++++++++ docs/user/assists.md | 18 ++++++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/crates/ra_assists/src/assists/add_custom_impl.rs b/crates/ra_assists/src/assists/add_custom_impl.rs index 7e64cd9023..037306fd67 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::{ 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) -> Option { let input = ctx.find_node_at_offset::()?; 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 3c716c2d12..4586eeb592 100644 --- a/crates/ra_assists/src/doc_tests/generated.rs +++ b/crates/ra_assists/src/doc_tests/generated.rs @@ -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( diff --git a/docs/user/assists.md b/docs/user/assists.md index 6f4c30bee3..334ba450f5 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -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.