mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-25 20:43:21 +00:00
docs: describe new feature 'add custom impl for derived trait'
This commit is contained in:
parent
439080f027
commit
5b2d52c8df
3 changed files with 54 additions and 0 deletions
|
@ -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)?;
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in a new issue