From 0dd35ff2b2ceffdb926953fdacc7d30e1968047d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 14:16:46 +0300 Subject: auto-generate assists docs and tests --- docs/user/features.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/user/features.md') diff --git a/docs/user/features.md b/docs/user/features.md index 8b7a8d7fc..a94b65ad4 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -97,11 +97,13 @@ Start `cargo watch` for live error highlighting. Will prompt to install if it's Stop `cargo watch` -### Code Actions (Assists) +### Assists (Code Actions) These are triggered in a particular context via light bulb. We use custom code on the VS Code side to be able to position cursor. `<|>` signifies cursor +See [assists.md](./assists.md) + - Add `#[derive]` ```rust -- cgit v1.2.3 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/features.md | 91 --------------------------------------------------- 1 file changed, 91 deletions(-) (limited to 'docs/user/features.md') 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 From 3126152a84e08a80659d49d735d03628154564ed Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 17:37:04 +0300 Subject: document a couple of assists --- docs/user/features.md | 51 --------------------------------------------------- 1 file changed, 51 deletions(-) (limited to 'docs/user/features.md') diff --git a/docs/user/features.md b/docs/user/features.md index acf092cec..39dab710d 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -118,57 +118,6 @@ impl Debug<|> for Foo { } ``` -- Change Visibility - -```rust -// before: -<|>fn foo() {} - -// after: -<|>pub(crate) fn foo() {} - -// after: -<|>pub fn foo() {} -``` - -- Fill match arms - -```rust -// before: -enum A { - As, - Bs, - Cs(String), - Ds(String, String), - Es{x: usize, y: usize} -} - -fn main() { - let a = A::As; - match a<|> {} -} - -// after: -enum A { - As, - Bs, - Cs(String), - Ds(String, String), - Es{x: usize, y: usize} -} - -fn main() { - let a = A::As; - match <|>a { - A::As => (), - A::Bs => (), - A::Cs(_) => (), - A::Ds(_, _) => (), - A::Es{x, y} => (), - } -} -``` - - Fill struct fields ```rust -- cgit v1.2.3 From a490ba06fa635ecb34b5ce0b7205621eefaee603 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 27 Oct 2019 11:26:46 +0300 Subject: document some more assists --- docs/user/features.md | 84 --------------------------------------------------- 1 file changed, 84 deletions(-) (limited to 'docs/user/features.md') diff --git a/docs/user/features.md b/docs/user/features.md index 39dab710d..2e213e34c 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -154,45 +154,6 @@ fn main() { } ``` -- Flip `,` - -```rust -// before: -fn foo(x: usize,<|> dim: (usize, usize)) {} -// after: -fn foo(dim: (usize, usize), x: usize) {} -``` - -- Introduce variable: - -```rust -// before: -fn foo() { - foo(<|>1 + 1<|>); -} - -// after: -fn foo() { - let var_name = 1 + 1; - foo(var_name); -} -``` - -- Inline local variable: - -```rust -// before: -fn foo() { - let a<|> = 1 + 1; - let b = a * 10; -} - -// after: -fn foo() { - let b = (1 + 1) * 10; -} -``` - - Remove `dbg!` ```rust @@ -245,41 +206,6 @@ use crate:<|>:db::{RootDatabase, FileSymbol}; use crate::{<|>db::{RootDatabase, FileSymbol}}; ``` -- Flip binary expression - -```rust -// before: -fn foo() { - if 1 <<|> 2 { - println!("Who would have thought?"); - } -} -// after: -fn foo() { - if 2 ><|> 1 { - println!("Who would have thought?"); - } -} -``` - -- Move guard expression to match arm body -```rust -// before: -fn f() { - match x { - <|>y @ 4 | y @ 5 if y > 5 => true, - _ => false - } -} -// after: -fn f() { - match x { - y @ 4 | y @ 5 => if y > 5 { <|>true }, - _ => false - } -} -``` - - Move if condition to match arm guard ```rust // before: @@ -309,16 +235,6 @@ fn f() { } ``` -- Move type bounds to where clause - -```rust -// before: -fn foo T>() {} - -// after: -fn foo() where T: u32, F: FnOnce(T) -> T {} -``` - - Make raw string unescaped ```rust -- cgit v1.2.3 From da5528824a836a4f36f44f90adc9fadcc98ca75b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 27 Oct 2019 12:22:53 +0300 Subject: document almost all assists --- docs/user/features.md | 174 -------------------------------------------------- 1 file changed, 174 deletions(-) (limited to 'docs/user/features.md') diff --git a/docs/user/features.md b/docs/user/features.md index 2e213e34c..7ae2ca7b6 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -118,180 +118,6 @@ impl Debug<|> for Foo { } ``` -- Fill struct fields - -```rust -// before: -struct S<'a, D> { - a: u32, - b: String, - c: (i32, i32), - d: D, - r: &'a str, -} - -fn main() { - let s = S<|> {} -} - -// after: -struct S<'a, D> { - a: u32, - b: String, - c: (i32, i32), - d: D, - r: &'a str, -} - -fn main() { - let s = <|>S { - a: (), - b: (), - c: (), - d: (), - r: (), - } -} -``` - -- Remove `dbg!` - -```rust -// before: -fn foo(n: usize) { - if let Some(_) = dbg!(n.<|>checked_sub(4)) { - // ... - } -} - -// after: -fn foo(n: usize) { - if let Some(_) = n.<|>checked_sub(4) { - // ... - } -} -``` - -- Replace if-let with match: - -```rust -// before: -impl VariantData { - pub fn is_struct(&self) -> bool { - if <|>let VariantData::Struct(..) = *self { - true - } else { - false - } - } -} - -// after: -impl VariantData { - pub fn is_struct(&self) -> bool { - <|>match *self { - VariantData::Struct(..) => true, - _ => false, - } - } -} -``` - -- Split import - -```rust -// before: -use crate:<|>:db::{RootDatabase, FileSymbol}; -// after: -use crate::{<|>db::{RootDatabase, FileSymbol}}; -``` - -- Move if condition to match arm guard -```rust -// before: -fn f() { - let mut t = 'a'; - let chars = "abcd"; - match t { - '\r' => if chars.clone().next().is_some() { - t = 'e';<|> - false - }, - _ => true - } -} - -// after: -fn f() { - let mut t = 'a'; - let chars = "abcd"; - match t { - '\r' <|>if chars.clone().next().is_some() => { - t = 'e'; - false - }, - _ => true - } -} -``` - -- Make raw string unescaped - -```rust -// before: -fn f() { - let s = <|>"ab\ncd"; -} - -// after: -fn f() { - let s = <|>r#"ab -cd"#; -} -``` - -- Make usual string - -```rust -// before: -fn f() { - let s = <|>r#"abcd"#; -} - -// after: -fn f() { - let s = <|>"abcd"; -} -``` - -- Add hash - -```rust -// before: -fn f() { - let s = <|>r"abcd"; -} - -// after: -fn f() { - let s = <|>r#"abcd"#; -} -``` - -- Remove hash - -```rust -// before: -fn f() { - let s = <|>r#"abcd"#; -} - -// after: -fn f() { - let s = <|>r"abcd"; -} -``` - ### Magic Completions In addition to usual reference completion, rust-analyzer provides some ✨magic✨ -- cgit v1.2.3 From b6fcacd96d26e7edaf37bda852b8b3ad104d4c90 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 27 Oct 2019 17:49:39 +0300 Subject: move all assists to use generated docs --- docs/user/features.md | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'docs/user/features.md') diff --git a/docs/user/features.md b/docs/user/features.md index 7ae2ca7b6..c160dd70b 100644 --- a/docs/user/features.md +++ b/docs/user/features.md @@ -99,24 +99,10 @@ Stop `cargo watch` ### Assists (Code Actions) -These are triggered in a particular context via light bulb. We use custom code on -the VS Code side to be able to position cursor. `<|>` signifies cursor +Assists, or code actions, are small local refactorings, available in a particular context. +They are usually triggered by a shortcut or by clicking a light bulb icon in the editor. -See [assists.md](./assists.md) - -- Import path - -```rust -// before: -impl std::fmt::Debug<|> for Foo { -} - -// after: -use std::fmt::Debug; - -impl Debug<|> for Foo { -} -``` +See [assists.md](./assists.md) for the list of available assists. ### Magic Completions -- cgit v1.2.3