From 76733f0cd456005295e60da8c45d74c8c48f177c Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Wed, 29 Apr 2020 13:52:55 +0200 Subject: Add unwrap block assist #4156 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- docs/user/assists.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 6c6943622..02323772c 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -695,3 +695,21 @@ use std::┃collections::HashMap; // AFTER use std::{collections::HashMap}; ``` + +## `unwrap_block` + +Removes the `mut` keyword. + +```rust +// BEFORE +fn foo() { + if true {┃ + println!("foo"); + } +} + +// AFTER +fn foo() { + ┃println!("foo"); +} +``` -- cgit v1.2.3 From bbe22640b8d52354c3de3e126c9fcda5b1b174fd Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Wed, 29 Apr 2020 14:53:47 +0200 Subject: Add unwrap block assist #4156 Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- docs/user/assists.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 02323772c..a421aa0c3 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -698,7 +698,7 @@ use std::{collections::HashMap}; ## `unwrap_block` -Removes the `mut` keyword. +This assist removes if...else, for, while and loop control statements to just keep the body. ```rust // BEFORE @@ -710,6 +710,6 @@ fn foo() { // AFTER fn foo() { - ┃println!("foo"); + println!("foo"); } ``` -- cgit v1.2.3 From b73dbbfbf2cad646eb3f8e3342a1c390a874dc53 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 2 May 2020 11:50:43 +0200 Subject: Add missing members generates indented blocks --- docs/user/assists.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 6c6943622..5a83c4a98 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -175,7 +175,9 @@ trait Trait { } impl Trait for () { - fn foo(&self) -> u32 { todo!() } + fn foo(&self) -> u32 { + todo!() + } } ``` -- cgit v1.2.3 From 51c02ab84f6b88ba39e2d0a3ed22bea51114b05a Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Tue, 5 May 2020 19:02:45 +0200 Subject: add Ok wrapping Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- docs/user/assists.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index ee515949e..692fd4f52 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -241,6 +241,18 @@ fn main() { } ``` +## `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. -- cgit v1.2.3 From fa2e5299c3332b99fcd09fd54e8d812a6c34b0cc Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 17 May 2020 14:21:24 +0200 Subject: Add snippet support for some assists --- docs/user/assists.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 692fd4f52..41c5df528 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -17,7 +17,7 @@ struct S; struct S; impl Debug for S { - + $0 } ``` @@ -33,7 +33,7 @@ struct Point { } // AFTER -#[derive()] +#[derive($0)] struct Point { x: u32, y: u32, @@ -105,16 +105,16 @@ Adds a new inherent impl for a type. ```rust // BEFORE struct Ctx { - data: T,┃ + data: T,┃ } // AFTER struct Ctx { - data: T, + data: T, } impl Ctx { - + $0 } ``` -- cgit v1.2.3 From 80545e5d3a72ef05a77ff9584234f030c69bfe9f Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 00:07:00 +0200 Subject: New assist: add turbo fish --- docs/user/assists.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 41c5df528..c72b50a4d 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -203,6 +203,24 @@ impl Ctx { ``` +## `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). -- cgit v1.2.3 From 8eb3272ad6f774bccb967ee640b72a9a17273e7b Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Tue, 19 May 2020 22:25:07 +0200 Subject: Use snippets in add function --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index c72b50a4d..10ab67b2e 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -77,7 +77,7 @@ fn foo() { } fn bar(arg: &str, baz: Baz) { - todo!() + ${0:todo!()} } ``` -- cgit v1.2.3 From a04cababaa144d7a6db7b1dd114494b33d281ab9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 01:53:21 +0200 Subject: Use snippets in add_missing_members --- docs/user/assists.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 10ab67b2e..b687330f3 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -146,7 +146,7 @@ trait Trait { impl Trait for () { Type X = (); fn foo(&self) {} - fn bar(&self) {} + $0fn bar(&self) {} } ``` @@ -175,7 +175,7 @@ trait Trait { } impl Trait for () { - fn foo(&self) -> u32 { + $0fn foo(&self) -> u32 { todo!() } -- cgit v1.2.3 From 767d169a2ae543f28544e85e15bac1b6aa1cab23 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 02:07:21 +0200 Subject: Better cursor placement when adding impl members --- docs/user/assists.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index b687330f3..f329fcc10 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -175,8 +175,8 @@ trait Trait { } impl Trait for () { - $0fn foo(&self) -> u32 { - todo!() + fn foo(&self) -> u32 { + ${0:todo!()} } } -- cgit v1.2.3 From 9b2bd022dc6fbe13356622ada5b6499f012cb5ae Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 10:17:46 +0200 Subject: Snippetify add_new --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index f329fcc10..03c01d6c0 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -198,7 +198,7 @@ struct Ctx { } impl Ctx { - fn new(data: T) -> Self { Self { data } } + fn $0new(data: T) -> Self { Self { data } } } ``` -- cgit v1.2.3 From 33e111483fbc80c017037e0b158ee652ed41b3e8 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 11:10:15 +0200 Subject: Use snippets in change_return_type_to_result --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 03c01d6c0..006ec4d54 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -268,7 +268,7 @@ Change the function's return type to Result. fn foo() -> i32┃ { 42i32 } // AFTER -fn foo() -> Result { Ok(42i32) } +fn foo() -> Result { Ok(42i32) } ``` ## `change_visibility` -- cgit v1.2.3 From cec773926f08e2d46b05d923165f8e73c420aa8c Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 13:33:13 +0200 Subject: Split change_ and fix_ visibility assists --- docs/user/assists.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 006ec4d54..0ae242389 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -331,6 +331,28 @@ fn handle(action: Action) { } ``` +## `fix_visibility` + +Makes inaccessible item public. + +```rust +// BEFORE +mod m { + fn frobnicate() {} +} +fn main() { + m::frobnicate┃() {} +} + +// AFTER +mod m { + pub(crate) fn frobnicate() {} +} +fn main() { + m::frobnicate() {} +} +``` + ## `flip_binexpr` Flips operands of a binary expression. -- cgit v1.2.3 From c446fd76a2a6191adce87b20707a37bd46cb85a9 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 14:00:37 +0200 Subject: Snippetify fill_match_arms --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 0ae242389..a33c490b8 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -325,7 +325,7 @@ enum Action { Move { distance: u32 }, Stop } fn handle(action: Action) { match action { - Action::Move { distance } => {} + $0Action::Move { distance } => {} Action::Stop => {} } } -- cgit v1.2.3 From ba3a58d1b2d76bae2ac84923d12918a32ad680f6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 14:13:17 +0200 Subject: Snippetify fix_visibility --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index a33c490b8..51807ffda 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -346,7 +346,7 @@ fn main() { // AFTER mod m { - pub(crate) fn frobnicate() {} + $0pub(crate) fn frobnicate() {} } fn main() { m::frobnicate() {} -- cgit v1.2.3 From fd771707187a505c826096fc62ced6ba9b65460e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Wed, 20 May 2020 23:07:17 +0200 Subject: Snippetify introduce/inline var --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index 51807ffda..a6e27d67f 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -426,7 +426,7 @@ fn main() { // AFTER fn main() { - let var_name = (1 + 2); + let $0var_name = (1 + 2); var_name * 4; } ``` -- cgit v1.2.3 From 4ac0abd2960acf1b3a357c681e64b3cddba6fc8e Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 21 May 2020 00:01:08 +0200 Subject: Snippetify unwrap -> match --- docs/user/assists.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'docs/user/assists.md') diff --git a/docs/user/assists.md b/docs/user/assists.md index a6e27d67f..4ad7ea59d 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md @@ -733,7 +733,7 @@ fn main() { let x: Result = Result::Ok(92); let y = match x { Ok(a) => a, - _ => unreachable!(), + $0_ => unreachable!(), }; } ``` -- cgit v1.2.3