From 46292c7cecb0bd957aee48f72b5c1e931ce47b79 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 May 2020 15:02:12 +0200 Subject: Move assists documentation into the manual --- docs/user/assists.md | 811 -------------------------------- docs/user/generated_assists.adoc | 973 +++++++++++++++++++++++++++++++++++++++ docs/user/manual.adoc | 3 +- 3 files changed, 975 insertions(+), 812 deletions(-) delete mode 100644 docs/user/assists.md create mode 100644 docs/user/generated_assists.adoc (limited to 'docs/user') diff --git a/docs/user/assists.md b/docs/user/assists.md deleted file mode 100644 index 04387e3b0..000000000 --- a/docs/user/assists.md +++ /dev/null @@ -1,811 +0,0 @@ -# Assists - -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 { - $0 -} -``` - -## `add_derive` - -Adds a new `#[derive()]` clause to a struct or enum. - -```rust -// BEFORE -struct Point { - x: u32, - y: u32,┃ -} - -// AFTER -#[derive($0)] -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_from_impl_for_enum` - -Adds a From impl for an enum variant with one tuple field. - -```rust -// BEFORE -enum A { ┃One(u32) } - -// AFTER -enum A { One(u32) } - -impl From for A { - fn from(v: u32) -> Self { - A::One(v) - } -} -``` - -## `add_function` - -Adds a stub function with a signature matching the function under the cursor. - -```rust -// BEFORE -struct Baz; -fn baz() -> Baz { Baz } -fn foo() { - bar┃("", baz()); -} - - -// AFTER -struct Baz; -fn baz() -> Baz { Baz } -fn foo() { - bar("", baz()); -} - -fn bar(arg: &str, baz: Baz) { - ${0:todo!()} -} - -``` - -## `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. - -```rust -// BEFORE -struct Ctx { - data: T,┃ -} - -// AFTER -struct Ctx { - data: T, -} - -impl Ctx { - $0 -} -``` - -## `add_impl_default_members` - -Adds scaffold for overriding default impl members. - -```rust -// BEFORE -trait Trait { - Type X; - fn foo(&self); - fn bar(&self) {} -} - -impl Trait for () { - Type X = (); - fn foo(&self) {}┃ - -} - -// AFTER -trait Trait { - Type X; - fn foo(&self); - fn bar(&self) {} -} - -impl Trait for () { - Type X = (); - fn foo(&self) {} - $0fn bar(&self) {} - -} -``` - -## `add_impl_missing_members` - -Adds scaffold for required impl members. - -```rust -// BEFORE -trait Trait { - Type X; - fn foo(&self) -> T; - fn bar(&self) {} -} - -impl Trait for () {┃ - -} - -// AFTER -trait Trait { - Type X; - fn foo(&self) -> T; - fn bar(&self) {} -} - -impl Trait for () { - fn foo(&self) -> u32 { - ${0:todo!()} - } - -} -``` - -## `add_new` - -Adds a new inherent impl for a type. - -```rust -// BEFORE -struct Ctx { - data: T,┃ -} - -// AFTER -struct Ctx { - data: T, -} - -impl Ctx { - fn $0new(data: T) -> Self { Self { data } } -} - -``` - -## `add_turbo_fish` - -Adds `::<_>` to a call of a generic method or function. - -```rust -// BEFORE -fn make() -> T { todo!() } -fn main() { - let x = make┃(); -} - -// AFTER -fn make() -> T { todo!() } -fn main() { - let x = make::<${0:_}>(); -} -``` - -## `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) {} -} -``` - -## `auto_import` - -If the name is unresolved, provides all possible imports for it. - -```rust -// BEFORE -fn main() { - let map = HashMap┃::new(); -} - -// AFTER -use std::collections::HashMap; - -fn main() { - let map = HashMap::new(); -} -``` - -## `change_lifetime_anon_to_named` - -Change an anonymous lifetime to a named lifetime. - -```rust -// BEFORE -impl Cursor<'_┃> { - fn node(self) -> &SyntaxNode { - match self { - Cursor::Replace(node) | Cursor::Before(node) => node, - } - } -} - -// AFTER -impl<'a> Cursor<'a> { - fn node(self) -> &SyntaxNode { - match self { - Cursor::Replace(node) | Cursor::Before(node) => node, - } - } -} -``` - -## `change_return_type_to_result` - -Change the function's return type to Result. - -```rust -// BEFORE -fn foo() -> i32┃ { 42i32 } - -// AFTER -fn foo() -> Result { Ok(42i32) } -``` - -## `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. - -```rust -// BEFORE -fn main() { - ┃if cond { - foo(); - bar(); - } -} - -// AFTER -fn main() { - if !cond { - return; - } - foo(); - 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 { - $0Action::Move { distance } => {} - Action::Stop => {} - } -} -``` - -## `fix_visibility` - -Makes inaccessible item public. - -```rust -// BEFORE -mod m { - fn frobnicate() {} -} -fn main() { - m::frobnicate┃() {} -} - -// AFTER -mod m { - $0pub(crate) fn frobnicate() {} -} -fn main() { - m::frobnicate() {} -} -``` - -## `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)); -} -``` - -## `flip_trait_bound` - -Flips two trait bounds. - -```rust -// BEFORE -fn foo() { } - -// AFTER -fn foo() { } -``` - -## `inline_local_variable` - -Inlines local variable. - -```rust -// BEFORE -fn main() { - let x┃ = 1 + 2; - x * 4; -} - -// AFTER -fn main() { - (1 + 2) * 4; -} -``` - -## `introduce_variable` - -Extracts subexpression into a variable. - -```rust -// BEFORE -fn main() { - ┃(1 + 2)┃ * 4; -} - -// AFTER -fn main() { - let $0var_name = (1 + 2); - var_name * 4; -} -``` - -## `invert_if` - -Apply invert_if -This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` -This also works with `!=`. This assist can only be applied with the cursor -on `if`. - -```rust -// BEFORE -fn main() { - if┃ !y { A } else { B } -} - -// AFTER -fn main() { - if y { B } else { A } -} -``` - -## `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_imports` - -Merges two imports with a common prefix. - -```rust -// BEFORE -use std::┃fmt::Formatter; -use std::io; - -// AFTER -use std::{fmt::Formatter, io}; -``` - -## `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() }, - _ => (), - } -} -``` - -## `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!"; -} -``` - -## `remove_mut` - -Removes the `mut` keyword. - -```rust -// BEFORE -impl Walrus { - fn feed(&mut┃ self, amount: u32) {} -} - -// AFTER -impl Walrus { - fn feed(&self, amount: u32) {} -} -``` - -## `reorder_fields` - -Reorder the fields of record literals and record patterns in the same order as in -the definition. - -```rust -// BEFORE -struct Foo {foo: i32, bar: i32}; -const test: Foo = ┃Foo {bar: 0, foo: 1} - -// AFTER -struct Foo {foo: i32, bar: i32}; -const test: Foo = Foo {foo: 1, bar: 0} -``` - -## `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(), - } -} -``` - -## `replace_let_with_if_let` - -Replaces `let` with an `if-let`. - -```rust -// BEFORE - -fn main(action: Action) { - ┃let x = compute(); -} - -fn compute() -> Option { None } - -// AFTER - -fn main(action: Action) { - if let Some(x) = compute() { - } -} - -fn compute() -> Option { None } -``` - -## `replace_qualified_name_with_use` - -Adds a use statement for a given fully-qualified name. - -```rust -// BEFORE -fn process(map: std::collections::┃HashMap) {} - -// AFTER -use std::collections::HashMap; - -fn process(map: HashMap) {} -``` - -## `replace_unwrap_with_match` - -Replaces `unwrap` a `match` expression. Works for Result and Option. - -```rust -// BEFORE -enum Result { Ok(T), Err(E) } -fn main() { - let x: Result = Result::Ok(92); - let y = x.┃unwrap(); -} - -// AFTER -enum Result { Ok(T), Err(E) } -fn main() { - let x: Result = Result::Ok(92); - let y = match x { - Ok(a) => a, - $0_ => unreachable!(), - }; -} -``` - -## `split_import` - -Wraps the tail of import into braces. - -```rust -// BEFORE -use std::┃collections::HashMap; - -// AFTER -use std::{collections::HashMap}; -``` - -## `unwrap_block` - -This assist removes if...else, for, while and loop control statements to just keep the body. - -```rust -// BEFORE -fn foo() { - if true {┃ - println!("foo"); - } -} - -// AFTER -fn foo() { - println!("foo"); -} -``` diff --git a/docs/user/generated_assists.adoc b/docs/user/generated_assists.adoc new file mode 100644 index 000000000..b8cdfb1cd --- /dev/null +++ b/docs/user/generated_assists.adoc @@ -0,0 +1,973 @@ +[discrete] +=== `add_custom_impl` + +Adds impl block for derived trait. + +.Before +```rust +#[derive(Deb┃ug, Display)] +struct S; +``` + +.After +```rust +#[derive(Display)] +struct S; + +impl Debug for S { + $0 +} +``` + + +[discrete] +=== `add_derive` + +Adds a new `#[derive()]` clause to a struct or enum. + +.Before +```rust +struct Point { + x: u32, + y: u32,┃ +} +``` + +.After +```rust +#[derive($0)] +struct Point { + x: u32, + y: u32, +} +``` + + +[discrete] +=== `add_explicit_type` + +Specify type for a let binding. + +.Before +```rust +fn main() { + let x┃ = 92; +} +``` + +.After +```rust +fn main() { + let x: i32 = 92; +} +``` + + +[discrete] +=== `add_from_impl_for_enum` + +Adds a From impl for an enum variant with one tuple field. + +.Before +```rust +enum A { ┃One(u32) } +``` + +.After +```rust +enum A { One(u32) } + +impl From for A { + fn from(v: u32) -> Self { + A::One(v) + } +} +``` + + +[discrete] +=== `add_function` + +Adds a stub function with a signature matching the function under the cursor. + +.Before +```rust +struct Baz; +fn baz() -> Baz { Baz } +fn foo() { + bar┃("", baz()); +} + +``` + +.After +```rust +struct Baz; +fn baz() -> Baz { Baz } +fn foo() { + bar("", baz()); +} + +fn bar(arg: &str, baz: Baz) { + ${0:todo!()} +} + +``` + + +[discrete] +=== `add_hash` + +Adds a hash to a raw string literal. + +.Before +```rust +fn main() { + r#"Hello,┃ World!"#; +} +``` + +.After +```rust +fn main() { + r##"Hello, World!"##; +} +``` + + +[discrete] +=== `add_impl` + +Adds a new inherent impl for a type. + +.Before +```rust +struct Ctx { + data: T,┃ +} +``` + +.After +```rust +struct Ctx { + data: T, +} + +impl Ctx { + $0 +} +``` + + +[discrete] +=== `add_impl_default_members` + +Adds scaffold for overriding default impl members. + +.Before +```rust +trait Trait { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl Trait for () { + Type X = (); + fn foo(&self) {}┃ + +} +``` + +.After +```rust +trait Trait { + Type X; + fn foo(&self); + fn bar(&self) {} +} + +impl Trait for () { + Type X = (); + fn foo(&self) {} + $0fn bar(&self) {} + +} +``` + + +[discrete] +=== `add_impl_missing_members` + +Adds scaffold for required impl members. + +.Before +```rust +trait Trait { + Type X; + fn foo(&self) -> T; + fn bar(&self) {} +} + +impl Trait for () {┃ + +} +``` + +.After +```rust +trait Trait { + Type X; + fn foo(&self) -> T; + fn bar(&self) {} +} + +impl Trait for () { + fn foo(&self) -> u32 { + ${0:todo!()} + } + +} +``` + + +[discrete] +=== `add_new` + +Adds a new inherent impl for a type. + +.Before +```rust +struct Ctx { + data: T,┃ +} +``` + +.After +```rust +struct Ctx { + data: T, +} + +impl Ctx { + fn $0new(data: T) -> Self { Self { data } } +} + +``` + + +[discrete] +=== `add_turbo_fish` + +Adds `::<_>` to a call of a generic method or function. + +.Before +```rust +fn make() -> T { todo!() } +fn main() { + let x = make┃(); +} +``` + +.After +```rust +fn make() -> T { todo!() } +fn main() { + let x = make::<${0:_}>(); +} +``` + + +[discrete] +=== `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`. + +.Before +```rust +fn main() { + if x != 4 ||┃ !y {} +} +``` + +.After +```rust +fn main() { + if !(x == 4 && y) {} +} +``` + + +[discrete] +=== `auto_import` + +If the name is unresolved, provides all possible imports for it. + +.Before +```rust +fn main() { + let map = HashMap┃::new(); +} +``` + +.After +```rust +use std::collections::HashMap; + +fn main() { + let map = HashMap::new(); +} +``` + + +[discrete] +=== `change_lifetime_anon_to_named` + +Change an anonymous lifetime to a named lifetime. + +.Before +```rust +impl Cursor<'_┃> { + fn node(self) -> &SyntaxNode { + match self { + Cursor::Replace(node) | Cursor::Before(node) => node, + } + } +} +``` + +.After +```rust +impl<'a> Cursor<'a> { + fn node(self) -> &SyntaxNode { + match self { + Cursor::Replace(node) | Cursor::Before(node) => node, + } + } +} +``` + + +[discrete] +=== `change_return_type_to_result` + +Change the function's return type to Result. + +.Before +```rust +fn foo() -> i32┃ { 42i32 } +``` + +.After +```rust +fn foo() -> Result { Ok(42i32) } +``` + + +[discrete] +=== `change_visibility` + +Adds or changes existing visibility specifier. + +.Before +```rust +┃fn frobnicate() {} +``` + +.After +```rust +pub(crate) fn frobnicate() {} +``` + + +[discrete] +=== `convert_to_guarded_return` + +Replace a large conditional with a guarded return. + +.Before +```rust +fn main() { + ┃if cond { + foo(); + bar(); + } +} +``` + +.After +```rust +fn main() { + if !cond { + return; + } + foo(); + bar(); +} +``` + + +[discrete] +=== `fill_match_arms` + +Adds missing clauses to a `match` expression. + +.Before +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + ┃ + } +} +``` + +.After +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + $0Action::Move { distance } => {} + Action::Stop => {} + } +} +``` + + +[discrete] +=== `fix_visibility` + +Makes inaccessible item public. + +.Before +```rust +mod m { + fn frobnicate() {} +} +fn main() { + m::frobnicate┃() {} +} +``` + +.After +```rust +mod m { + $0pub(crate) fn frobnicate() {} +} +fn main() { + m::frobnicate() {} +} +``` + + +[discrete] +=== `flip_binexpr` + +Flips operands of a binary expression. + +.Before +```rust +fn main() { + let _ = 90 +┃ 2; +} +``` + +.After +```rust +fn main() { + let _ = 2 + 90; +} +``` + + +[discrete] +=== `flip_comma` + +Flips two comma-separated items. + +.Before +```rust +fn main() { + ((1, 2),┃ (3, 4)); +} +``` + +.After +```rust +fn main() { + ((3, 4), (1, 2)); +} +``` + + +[discrete] +=== `flip_trait_bound` + +Flips two trait bounds. + +.Before +```rust +fn foo() { } +``` + +.After +```rust +fn foo() { } +``` + + +[discrete] +=== `inline_local_variable` + +Inlines local variable. + +.Before +```rust +fn main() { + let x┃ = 1 + 2; + x * 4; +} +``` + +.After +```rust +fn main() { + (1 + 2) * 4; +} +``` + + +[discrete] +=== `introduce_variable` + +Extracts subexpression into a variable. + +.Before +```rust +fn main() { + ┃(1 + 2)┃ * 4; +} +``` + +.After +```rust +fn main() { + let $0var_name = (1 + 2); + var_name * 4; +} +``` + + +[discrete] +=== `invert_if` + +Apply invert_if +This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` +This also works with `!=`. This assist can only be applied with the cursor +on `if`. + +.Before +```rust +fn main() { + if┃ !y { A } else { B } +} +``` + +.After +```rust +fn main() { + if y { B } else { A } +} +``` + + +[discrete] +=== `make_raw_string` + +Adds `r#` to a plain string literal. + +.Before +```rust +fn main() { + "Hello,┃ World!"; +} +``` + +.After +```rust +fn main() { + r#"Hello, World!"#; +} +``` + + +[discrete] +=== `make_usual_string` + +Turns a raw string into a plain string. + +.Before +```rust +fn main() { + r#"Hello,┃ "World!""#; +} +``` + +.After +```rust +fn main() { + "Hello, \"World!\""; +} +``` + + +[discrete] +=== `merge_imports` + +Merges two imports with a common prefix. + +.Before +```rust +use std::┃fmt::Formatter; +use std::io; +``` + +.After +```rust +use std::{fmt::Formatter, io}; +``` + + +[discrete] +=== `merge_match_arms` + +Merges identical match arms. + +.Before +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + ┃Action::Move(..) => foo(), + Action::Stop => foo(), + } +} +``` + +.After +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move(..) | Action::Stop => foo(), + } +} +``` + + +[discrete] +=== `move_arm_cond_to_match_guard` + +Moves if expression from match arm body into a guard. + +.Before +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => ┃if distance > 10 { foo() }, + _ => (), + } +} +``` + +.After +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } if distance > 10 => foo(), + _ => (), + } +} +``` + + +[discrete] +=== `move_bounds_to_where_clause` + +Moves inline type bounds to a where clause. + +.Before +```rust +fn apply U>(f: F, x: T) -> U { + f(x) +} +``` + +.After +```rust +fn apply(f: F, x: T) -> U where F: FnOnce(T) -> U { + f(x) +} +``` + + +[discrete] +=== `move_guard_to_arm_body` + +Moves match guard into match arm body. + +.Before +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } ┃if distance > 10 => foo(), + _ => (), + } +} +``` + +.After +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => if distance > 10 { foo() }, + _ => (), + } +} +``` + + +[discrete] +=== `remove_dbg` + +Removes `dbg!()` macro call. + +.Before +```rust +fn main() { + ┃dbg!(92); +} +``` + +.After +```rust +fn main() { + 92; +} +``` + + +[discrete] +=== `remove_hash` + +Removes a hash from a raw string literal. + +.Before +```rust +fn main() { + r#"Hello,┃ World!"#; +} +``` + +.After +```rust +fn main() { + r"Hello, World!"; +} +``` + + +[discrete] +=== `remove_mut` + +Removes the `mut` keyword. + +.Before +```rust +impl Walrus { + fn feed(&mut┃ self, amount: u32) {} +} +``` + +.After +```rust +impl Walrus { + fn feed(&self, amount: u32) {} +} +``` + + +[discrete] +=== `reorder_fields` + +Reorder the fields of record literals and record patterns in the same order as in +the definition. + +.Before +```rust +struct Foo {foo: i32, bar: i32}; +const test: Foo = ┃Foo {bar: 0, foo: 1} +``` + +.After +```rust +struct Foo {foo: i32, bar: i32}; +const test: Foo = Foo {foo: 1, bar: 0} +``` + + +[discrete] +=== `replace_if_let_with_match` + +Replaces `if let` with an else branch with a `match` expression. + +.Before +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + ┃if let Action::Move { distance } = action { + foo(distance) + } else { + bar() + } +} +``` + +.After +```rust +enum Action { Move { distance: u32 }, Stop } + +fn handle(action: Action) { + match action { + Action::Move { distance } => foo(distance), + _ => bar(), + } +} +``` + + +[discrete] +=== `replace_let_with_if_let` + +Replaces `let` with an `if-let`. + +.Before +```rust + +fn main(action: Action) { + ┃let x = compute(); +} + +fn compute() -> Option { None } +``` + +.After +```rust + +fn main(action: Action) { + if let Some(x) = compute() { + } +} + +fn compute() -> Option { None } +``` + + +[discrete] +=== `replace_qualified_name_with_use` + +Adds a use statement for a given fully-qualified name. + +.Before +```rust +fn process(map: std::collections::┃HashMap) {} +``` + +.After +```rust +use std::collections::HashMap; + +fn process(map: HashMap) {} +``` + + +[discrete] +=== `replace_unwrap_with_match` + +Replaces `unwrap` a `match` expression. Works for Result and Option. + +.Before +```rust +enum Result { Ok(T), Err(E) } +fn main() { + let x: Result = Result::Ok(92); + let y = x.┃unwrap(); +} +``` + +.After +```rust +enum Result { Ok(T), Err(E) } +fn main() { + let x: Result = Result::Ok(92); + let y = match x { + Ok(a) => a, + $0_ => unreachable!(), + }; +} +``` + + +[discrete] +=== `split_import` + +Wraps the tail of import into braces. + +.Before +```rust +use std::┃collections::HashMap; +``` + +.After +```rust +use std::{collections::HashMap}; +``` + + +[discrete] +=== `unwrap_block` + +This assist removes if...else, for, while and loop control statements to just keep the body. + +.Before +```rust +fn foo() { + if true {┃ + println!("foo"); + } +} +``` + +.After +```rust +fn foo() { + println!("foo"); +} +``` diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index f40139804..27b379213 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -278,5 +278,6 @@ include::./generated_features.adoc[] 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. +Cursor position or selection is signified by `┃` character. -See [assists.md](./assists.md) for the list of available assists. +include::./generated_assists.adoc[] -- cgit v1.2.3