From 5b2d52c8df5235fce9d2ae78adc3182a9659b268 Mon Sep 17 00:00:00 2001 From: Paulo Lieuthier Date: Sat, 19 Oct 2019 08:19:06 -0300 Subject: docs: describe new feature 'add custom impl for derived trait' --- crates/ra_assists/src/assists/add_custom_impl.rs | 17 +++++++++++++++++ crates/ra_assists/src/doc_tests/generated.rs | 19 +++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'crates/ra_assists/src') 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::{ 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 3c716c2d1..4586eeb59 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( -- cgit v1.2.3