From d385438bcc8d302fbcb91114e19ac0cc30528822 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 23:38:15 +0300 Subject: generate more assists docs --- docs/user/assists.md | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/user/features.md | 91 --------------------------------- 2 files changed, 137 insertions(+), 91 deletions(-) (limited to 'docs') diff --git a/docs/user/assists.md b/docs/user/assists.md index cb4b0b9fb..eeb486832 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -1,5 +1,142 @@ # Assists +## `add_derive` + +Adds a new `#[derive()]` clause to a struct or enum. + +```rust +// BEFORE +struct Point { + x: u32, + y: u32,<|> +} + +// AFTER +#[derive()] +struct Point { + x: u32, + y: u32, +} +``` + +## `add_explicit_type` + +Specify type for a let binding + +```rust +// BEFORE +fn main() { + let x<|> = 92; +} + +// AFTER +fn main() { + let x: i32 = 92; +} +``` + +## `add_impl` + +Adds a new inherent impl for a type + +```rust +// BEFORE +struct Ctx { + data: T,<|> +} + +// AFTER +struct Ctx { + data: T, +} + +impl Ctx { + +} +``` + +## `add_impl_default_members` + +Adds scaffold for overriding default impl members + +```rust +// BEFORE +trait T { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl T for () { + Type X = (); + fn foo(&self) {}<|> + +} + +// AFTER +trait T { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl T for () { + Type X = (); + fn foo(&self) {} + fn bar(&self) {} + +} +``` + +## `add_impl_missing_members` + +Adds scaffold for required impl members + +```rust +// BEFORE +trait T { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl T for () {<|> + +} + +// AFTER +trait T { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl T for () { + fn foo(&self) { unimplemented!() } + +} +``` + +## `apply_demorgan` + +Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). +This transforms expressions of the form `!l || !r` into `!(l && r)`. +This also works with `&&`. This assist can only be applied with the cursor +on either `||` or `&&`, with both operands being a negation of some kind. +This means something of the form `!x` or `x != y`. + +```rust +// BEFORE +fn main() { + if x != 4 ||<|> !y {} +} + +// AFTER +fn main() { + if !(x == 4 && y) {} +} +``` + ## `convert_to_guarded_return` Replace a large conditional with a guarded return. diff --git a/docs/user/features.md b/docs/user/features.md index a94b65ad4..acf092cec 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -104,84 +104,6 @@ the VS Code side to be able to position cursor. `<|>` signifies cursor See [assists.md](./assists.md) -- Add `#[derive]` - -```rust -// before: -struct Foo { - <|>x: i32 -} -// after: -#[derive(<|>)] -struct Foo { - x: i32 -} -``` - -- Add `impl` - -```rust -// before: -struct Foo<'a, T: Debug> { - <|>t: T -} -// after: -struct Foo<'a, T: Debug> { - t: T -} - -impl<'a, T: Debug> Foo<'a, T> { - <|> -} -``` - -- Add missing `impl` members - -```rust -// before: -trait Foo { - fn foo(&self); - fn bar(&self); - fn baz(&self); -} - -struct S; - -impl Foo for S { - fn bar(&self) {} - <|> -} - -// after: -trait Foo { - fn foo(&self); - fn bar(&self); - fn baz(&self); -} - -struct S; - -impl Foo for S { - fn bar(&self) {} - fn foo(&self) { unimplemented!() } - fn baz(&self) { unimplemented!() }<|> -} -``` - -- Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) - -```rust -// before: -fn example(x: bool) -> bool { - !x || !x -} - -// after: -fn example(x: bool) -> bool { - !(x && x) -} -``` - - Import path ```rust @@ -391,19 +313,6 @@ fn foo() { } ``` -- Add explicit type - -```rust -// before: -fn foo() { - let t<|> = (&2, Some(1)); -} -// after: -fn foo() { - let t<|>: (&i32, Option) = (&2, Some(1)); -} -``` - - Move guard expression to match arm body ```rust // before: -- cgit v1.2.3