From dc65219ae1216e747215fe937b248ebf2469f33f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 25 Oct 2019 09:00:30 +0300 Subject: document feature flags --- docs/user/README.md | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'docs/user') diff --git a/docs/user/README.md b/docs/user/README.md index f1628d6a4..a1cef22cc 100644 --- a/docs/user/README.md +++ b/docs/user/README.md @@ -83,8 +83,6 @@ host. ### Settings * `rust-analyzer.highlightingOn`: enables experimental syntax highlighting -* `rust-analyzer.showWorkspaceLoadedNotification`: to ease troubleshooting, a - notification is shown by default when a workspace is loaded * `rust-analyzer.enableEnhancedTyping`: by default, rust-analyzer intercepts `Enter` key to make it easier to continue comments. Note that it may conflict with VIM emulation plugin. * `rust-analyzer.raLspServerPath`: path to `ra_lsp_server` executable @@ -102,6 +100,17 @@ host. * `rust-analyzer.trace.server`: enables internal logging * `rust-analyzer.trace.cargo-watch`: enables cargo-watch logging * `RUST_SRC_PATH`: environment variable that overwrites the sysroot +* `rust-analyzer.featureFlags` -- a JSON object to tweak fine-grained behavior: + ```js + { + // Show diagnostics produced by rust-analyzer itself. + "lsp.diagnostics": true, + // Automatically insert `()` and `<>` when completing functions and types. + "completion.insertion.add-call-parenthesis": true, + // Show notification when workspace is fully loaded + "notifications.workspace-loaded": true, + } + ``` ## Emacs -- cgit v1.2.3 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/assists.md | 24 ++++++++++++++++++++++++ docs/user/features.md | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 docs/user/assists.md (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md new file mode 100644 index 000000000..cb4b0b9fb --- /dev/null +++ b/docs/user/assists.md @@ -0,0 +1,24 @@ +# Assists + +## `convert_to_guarded_return` + +Replace a large conditional with a guarded return. + +```rust +// BEFORE +fn main() { + <|>if cond { + foo(); + bar(); + } +} + +// AFTER +fn main() { + if !cond { + return; + } + foo(); + bar(); +} +``` 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 813b725957efe64b06316f524419328b6c152f73 Mon Sep 17 00:00:00 2001 From: Jacob Date: Fri, 25 Oct 2019 11:32:31 -0700 Subject: sublime: hint where feature flags would go --- docs/user/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'docs/user') diff --git a/docs/user/README.md b/docs/user/README.md index a1cef22cc..eb1d5ed14 100644 --- a/docs/user/README.md +++ b/docs/user/README.md @@ -182,7 +182,11 @@ Installation: "syntaxes": [ "Packages/Rust/Rust.sublime-syntax", "Packages/Rust Enhanced/RustEnhanced.sublime-syntax" - ] + ], + "initializationOptions": { + "featureFlags": { + } + }, } ``` -- 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/assists.md | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++ docs/user/features.md | 91 --------------------------------- 2 files changed, 137 insertions(+), 91 deletions(-) (limited to 'docs/user') 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 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/assists.md | 37 +++++++++++++++++++++++++++++++++++++ docs/user/features.md | 51 --------------------------------------------------- 2 files changed, 37 insertions(+), 51 deletions(-) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index eeb486832..7a64c80ad 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -137,6 +137,18 @@ fn main() { } ``` +## `change_visibility` + +Adds or changes existing visibility specifier. + +```rust +// BEFORE +fn<|> frobnicate() {} + +// AFTER +pub(crate) fn frobnicate() {} +``` + ## `convert_to_guarded_return` Replace a large conditional with a guarded return. @@ -159,3 +171,28 @@ fn main() { bar(); } ``` + +## `fill_match_arms` + +Adds missing clauses to a `match` expression. + +```rust +// BEFORE +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + <|> + } +} + +// AFTER +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move{ distance } => (), + Action::Stop => (), + } +} +``` 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 4ef9b8d17a75d3f68951f506ad390e1367c1b2ad Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 18:03:55 +0300 Subject: use correct spacing for enum pattern --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index 7a64c80ad..603b29c66 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -191,7 +191,7 @@ enum Action { Move { distance: u32 }, Stop } fn handle(action: Action) { match action { - Action::Move{ distance } => (), + Action::Move { distance } => (), Action::Stop => (), } } -- cgit v1.2.3 From a5cbd8d5e8aca0d0d8dde175ba13bfa995a753c0 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 19:08:13 +0300 Subject: check style for assist docs --- docs/user/assists.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 4 deletions(-) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index 603b29c66..8e2e8cc94 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -21,7 +21,7 @@ struct Point { ## `add_explicit_type` -Specify type for a let binding +Specify type for a let binding. ```rust // BEFORE @@ -37,7 +37,7 @@ fn main() { ## `add_impl` -Adds a new inherent impl for a type +Adds a new inherent impl for a type. ```rust // BEFORE @@ -57,7 +57,7 @@ impl Ctx { ## `add_impl_default_members` -Adds scaffold for overriding default impl members +Adds scaffold for overriding default impl members. ```rust // BEFORE @@ -90,7 +90,7 @@ impl T for () { ## `add_impl_missing_members` -Adds scaffold for required impl members +Adds scaffold for required impl members. ```rust // BEFORE @@ -196,3 +196,52 @@ fn handle(action: Action) { } } ``` + +## `flip_binexpr` + +Flips operands of a binary expression. + +```rust +// BEFORE +fn main() { + let _ = 90 +<|> 2; +} + +// AFTER +fn main() { + let _ = 2 + 90; +} +``` + +## `flip_comma` + +Flips two comma-separated items. + +```rust +// BEFORE +fn main() { + ((1, 2),<|> (3, 4)); +} + +// AFTER +fn main() { + ((3, 4), (1, 2)); +} +``` + +## `inline_local_variable` + +Inlines local variable. + +```rust +// BEFORE +fn main() { + let x<|> = 1 + 2; + x * 4; +} + +// AFTER +fn main() { + (1 + 2) * 4; +} +``` -- cgit v1.2.3 From 4a83aae09849123dbbbc5726b07c2601a14397a8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 19:58:18 +0300 Subject: support range selection in assist docs --- docs/user/assists.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index 8e2e8cc94..182f07e98 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -245,3 +245,20 @@ fn main() { (1 + 2) * 4; } ``` + +## `introduce_variable` + +Extracts subexpression into a variable. + +```rust +// BEFORE +fn main() { + <|>(1 + 2)<|> * 4; +} + +// AFTER +fn main() { + let var_name = (1 + 2); + var_name * 4; +} +``` -- cgit v1.2.3 From cf4720ffd5524f1ddda411e4810da8d97a0c593f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 26 Oct 2019 21:17:39 +0300 Subject: use unicode bar for drawing the cursor --- docs/user/assists.md | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index 182f07e98..ee1cfa142 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -1,5 +1,8 @@ # Assists +Cursor position or selection is signified by `┃` character. + + ## `add_derive` Adds a new `#[derive()]` clause to a struct or enum. @@ -8,7 +11,7 @@ Adds a new `#[derive()]` clause to a struct or enum. // BEFORE struct Point { x: u32, - y: u32,<|> + y: u32,┃ } // AFTER @@ -26,7 +29,7 @@ Specify type for a let binding. ```rust // BEFORE fn main() { - let x<|> = 92; + let x┃ = 92; } // AFTER @@ -42,7 +45,7 @@ Adds a new inherent impl for a type. ```rust // BEFORE struct Ctx { - data: T,<|> + data: T,┃ } // AFTER @@ -69,7 +72,7 @@ trait T { impl T for () { Type X = (); - fn foo(&self) {}<|> + fn foo(&self) {}┃ } @@ -100,7 +103,7 @@ trait T { fn bar(&self) {} } -impl T for () {<|> +impl T for () {┃ } @@ -128,7 +131,7 @@ This means something of the form `!x` or `x != y`. ```rust // BEFORE fn main() { - if x != 4 ||<|> !y {} + if x != 4 ||┃ !y {} } // AFTER @@ -143,7 +146,7 @@ Adds or changes existing visibility specifier. ```rust // BEFORE -fn<|> frobnicate() {} +┃fn frobnicate() {} // AFTER pub(crate) fn frobnicate() {} @@ -156,7 +159,7 @@ Replace a large conditional with a guarded return. ```rust // BEFORE fn main() { - <|>if cond { + ┃if cond { foo(); bar(); } @@ -182,7 +185,7 @@ enum Action { Move { distance: u32 }, Stop } fn handle(action: Action) { match action { - <|> + ┃ } } @@ -204,7 +207,7 @@ Flips operands of a binary expression. ```rust // BEFORE fn main() { - let _ = 90 +<|> 2; + let _ = 90 +┃ 2; } // AFTER @@ -220,7 +223,7 @@ Flips two comma-separated items. ```rust // BEFORE fn main() { - ((1, 2),<|> (3, 4)); + ((1, 2),┃ (3, 4)); } // AFTER @@ -236,7 +239,7 @@ Inlines local variable. ```rust // BEFORE fn main() { - let x<|> = 1 + 2; + let x┃ = 1 + 2; x * 4; } @@ -253,7 +256,7 @@ Extracts subexpression into a variable. ```rust // BEFORE fn main() { - <|>(1 + 2)<|> * 4; + ┃(1 + 2)┃ * 4; } // AFTER -- 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/assists.md | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++ docs/user/features.md | 84 ---------------------------------------------- 2 files changed, 93 insertions(+), 84 deletions(-) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index ee1cfa142..34a95696c 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -265,3 +265,96 @@ fn main() { var_name * 4; } ``` + +## `merge_match_arms` + +Merges identical match arms. + +```rust +// BEFORE +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + ┃Action::Move(..) => foo(), + Action::Stop => foo(), + } +} + +// AFTER +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move(..) | Action::Stop => foo(), + } +} +``` + +## `move_arm_cond_to_match_guard` + +Moves if expression from match arm body into a guard. + +```rust +// BEFORE +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => ┃if distance > 10 { foo() }, + _ => (), + } +} + +// AFTER +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } if distance > 10 => foo(), + _ => (), + } +} +``` + +## `move_bounds_to_where_clause` + +Moves inline type bounds to a where clause. + +```rust +// BEFORE +fn apply U>(f: F, x: T) -> U { + f(x) +} + +// AFTER +fn apply(f: F, x: T) -> U where F: FnOnce(T) -> U { + f(x) +} +``` + +## `move_guard_to_arm_body` + +Moves match guard into match arm body. + +```rust +// BEFORE +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } ┃if distance > 10 => foo(), + _ => (), + } +} + +// AFTER +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => if distance > 10 { foo() }, + _ => (), + } +} +``` 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/assists.md | 119 ++++++++++++++++++++++++++++++++++ docs/user/features.md | 174 -------------------------------------------------- 2 files changed, 119 insertions(+), 174 deletions(-) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index 34a95696c..e4d08a7dc 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -38,6 +38,22 @@ fn main() { } ``` +## `add_hash` + +Adds a hash to a raw string literal. + +```rust +// BEFORE +fn main() { + r#"Hello,┃ World!"#; +} + +// AFTER +fn main() { + r##"Hello, World!"##; +} +``` + ## `add_impl` Adds a new inherent impl for a type. @@ -266,6 +282,38 @@ fn main() { } ``` +## `make_raw_string` + +Adds `r#` to a plain string literal. + +```rust +// BEFORE +fn main() { + "Hello,┃ World!"; +} + +// AFTER +fn main() { + r#"Hello, World!"#; +} +``` + +## `make_usual_string` + +Turns a raw string into a plain string. + +```rust +// BEFORE +fn main() { + r#"Hello,┃ "World!""#; +} + +// AFTER +fn main() { + "Hello, \"World!\""; +} +``` + ## `merge_match_arms` Merges identical match arms. @@ -358,3 +406,74 @@ fn handle(action: Action) { } } ``` + +## `remove_dbg` + +Removes `dbg!()` macro call. + +```rust +// BEFORE +fn main() { + ┃dbg!(92); +} + +// AFTER +fn main() { + 92; +} +``` + +## `remove_hash` + +Removes a hash from a raw string literal. + +```rust +// BEFORE +fn main() { + r#"Hello,┃ World!"#; +} + +// AFTER +fn main() { + r"Hello, World!"; +} +``` + +## `replace_if_let_with_match` + +Replaces `if let` with an else branch with a `match` expression. + +```rust +// BEFORE +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + ┃if let Action::Move { distance } = action { + foo(distance) + } else { + bar() + } +} + +// AFTER +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => foo(distance), + _ => bar(), + } +} +``` + +## `split_import` + +Wraps the tail of import into braces. + +```rust +// BEFORE +use std::┃collections::HashMap; + +// AFTER +use std::{collections::HashMap}; +``` 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 85c64ec7bed4fba183f8ed22c96241c7baec3972 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 27 Oct 2019 16:56:53 +0300 Subject: use new api for flip_trait_bound assist --- docs/user/assists.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index e4d08a7dc..b1fe44d84 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -248,6 +248,18 @@ fn main() { } ``` +## `flip_trait_bound` + +Flips two trait bounds. + +```rust +// BEFORE +fn foo() { } + +// AFTER +fn foo() { } +``` + ## `inline_local_variable` Inlines local variable. -- 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/assists.md | 14 ++++++++++++++ docs/user/features.md | 20 +++----------------- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md index b1fe44d84..303353e74 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -136,6 +136,20 @@ impl T for () { } ``` +## `add_import` + +Adds a use statement for a given fully-qualified path. + +```rust +// BEFORE +fn process(map: std::collections::┃HashMap) {} + +// AFTER +use std::collections::HashMap; + +fn process(map: HashMap) {} +``` + ## `apply_demorgan` Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). 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