diff --git a/generated_assists.adoc b/generated_assists.adoc index fae149ae..937bc20f 100644 --- a/generated_assists.adoc +++ b/generated_assists.adoc @@ -1,7 +1,7 @@ //Generated file, do not edit by hand, see `xtask/src/codegen` [discrete] === `add_explicit_type` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/add_explicit_type.rs#L9[add_explicit_type.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/add_explicit_type.rs#L9[add_explicit_type.rs] Specify type for a let binding. @@ -22,7 +22,7 @@ fn main() { [discrete] === `add_hash` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/raw_string.rs#L92[raw_string.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/raw_string.rs#L92[raw_string.rs] Adds a hash to a raw string literal. @@ -43,7 +43,7 @@ fn main() { [discrete] === `add_impl_default_members` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/add_missing_impl_members.rs#L53[add_missing_impl_members.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/add_missing_impl_members.rs#L53[add_missing_impl_members.rs] Adds scaffold for overriding default impl members. @@ -81,7 +81,7 @@ impl Trait for () { [discrete] === `add_impl_missing_members` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/add_missing_impl_members.rs#L12[add_missing_impl_members.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/add_missing_impl_members.rs#L12[add_missing_impl_members.rs] Adds scaffold for required impl members. @@ -118,7 +118,7 @@ impl Trait for () { [discrete] === `add_lifetime_to_type` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/add_lifetime_to_type.rs#L6[add_lifetime_to_type.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/add_lifetime_to_type.rs#L6[add_lifetime_to_type.rs] Adds a new lifetime to a struct, enum or union. @@ -141,7 +141,7 @@ struct Point<'a> { [discrete] === `add_turbo_fish` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/add_turbo_fish.rs#L10[add_turbo_fish.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/add_turbo_fish.rs#L10[add_turbo_fish.rs] Adds `::<_>` to a call of a generic method or function. @@ -164,32 +164,31 @@ fn main() { [discrete] === `apply_demorgan` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/apply_demorgan.rs#L5[apply_demorgan.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/apply_demorgan.rs#L5[apply_demorgan.rs] Apply https://en.wikipedia.org/wiki/De_Morgan%27s_laws[De Morgan's law]. 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`. +on either `||` or `&&`. .Before ```rust fn main() { - if x != 4 ||┃ !y {} + if x != 4 ||┃ y < 3.14 {} } ``` .After ```rust fn main() { - if !(x == 4 && y) {} + if !(x == 4 && !(y < 3.14)) {} } ``` [discrete] === `auto_import` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/auto_import.rs#L65[auto_import.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/auto_import.rs#L65[auto_import.rs] If the name is unresolved, provides all possible imports for it. @@ -212,7 +211,7 @@ fn main() { [discrete] === `change_visibility` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/change_visibility.rs#L11[change_visibility.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/change_visibility.rs#L11[change_visibility.rs] Adds or changes existing visibility specifier. @@ -229,7 +228,7 @@ pub(crate) fn frobnicate() {} [discrete] === `convert_integer_literal` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/convert_integer_literal.rs#L5[convert_integer_literal.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/convert_integer_literal.rs#L5[convert_integer_literal.rs] Converts the base of integer literals to other bases. @@ -246,7 +245,7 @@ const _: i32 = 0b1010; [discrete] === `convert_to_guarded_return` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/early_return.rs#L21[early_return.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/early_return.rs#L21[early_return.rs] Replace a large conditional with a guarded return. @@ -274,7 +273,7 @@ fn main() { [discrete] === `expand_glob_import` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/expand_glob_import.rs#L18[expand_glob_import.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/expand_glob_import.rs#L18[expand_glob_import.rs] Expands glob imports. @@ -305,7 +304,7 @@ fn qux(bar: Bar, baz: Baz) {} [discrete] === `extract_function` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/extract_function.rs#L30[extract_function.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/extract_function.rs#L30[extract_function.rs] Extracts selected statements into new function. @@ -336,7 +335,7 @@ fn ┃fun_name(n: i32) { [discrete] === `extract_struct_from_enum_variant` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/extract_struct_from_enum_variant.rs#L23[extract_struct_from_enum_variant.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/extract_struct_from_enum_variant.rs#L23[extract_struct_from_enum_variant.rs] Extracts a struct from enum variant. @@ -355,7 +354,7 @@ enum A { One(One) } [discrete] === `extract_variable` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/extract_variable.rs#L13[extract_variable.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/extract_variable.rs#L13[extract_variable.rs] Extracts subexpression into a variable. @@ -377,7 +376,7 @@ fn main() { [discrete] === `fill_match_arms` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/fill_match_arms.rs#L15[fill_match_arms.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/fill_match_arms.rs#L15[fill_match_arms.rs] Adds missing clauses to a `match` expression. @@ -407,7 +406,7 @@ fn handle(action: Action) { [discrete] === `fix_visibility` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/fix_visibility.rs#L12[fix_visibility.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/fix_visibility.rs#L12[fix_visibility.rs] Makes inaccessible item public. @@ -434,7 +433,7 @@ fn main() { [discrete] === `flip_binexpr` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/flip_binexpr.rs#L5[flip_binexpr.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/flip_binexpr.rs#L5[flip_binexpr.rs] Flips operands of a binary expression. @@ -455,7 +454,7 @@ fn main() { [discrete] === `flip_comma` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/flip_comma.rs#L5[flip_comma.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/flip_comma.rs#L5[flip_comma.rs] Flips two comma-separated items. @@ -476,7 +475,7 @@ fn main() { [discrete] === `flip_trait_bound` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/flip_trait_bound.rs#L9[flip_trait_bound.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/flip_trait_bound.rs#L9[flip_trait_bound.rs] Flips two trait bounds. @@ -493,7 +492,7 @@ fn foo() { } [discrete] === `generate_default_from_enum_variant` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_default_from_enum_variant.rs#L8[generate_default_from_enum_variant.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_default_from_enum_variant.rs#L8[generate_default_from_enum_variant.rs] Adds a Default impl for an enum using a variant. @@ -524,7 +523,7 @@ impl Default for Version { [discrete] === `generate_derive` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_derive.rs#L9[generate_derive.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_derive.rs#L9[generate_derive.rs] Adds a new `#[derive()]` clause to a struct or enum. @@ -547,8 +546,41 @@ struct Point { [discrete] -=== `generate_enum_match_method` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_enum_match_method.rs#L11[generate_enum_match_method.rs] +=== `generate_enum_as_method` +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_enum_projection_method.rs#L55[generate_enum_projection_method.rs] + +Generate an `as_` method for an enum variant. + +.Before +```rust +enum Value { + Number(i32), + Text(String)┃, +} +``` + +.After +```rust +enum Value { + Number(i32), + Text(String), +} + +impl Value { + fn as_text(&self) -> Option<&String> { + if let Self::Text(v) = self { + Some(v) + } else { + None + } + } +} +``` + + +[discrete] +=== `generate_enum_is_method` +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_enum_is_method.rs#L10[generate_enum_is_method.rs] Generate an `is_` method for an enum variant. @@ -578,9 +610,42 @@ impl Version { ``` +[discrete] +=== `generate_enum_try_into_method` +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_enum_projection_method.rs#L11[generate_enum_projection_method.rs] + +Generate an `try_into_` method for an enum variant. + +.Before +```rust +enum Value { + Number(i32), + Text(String)┃, +} +``` + +.After +```rust +enum Value { + Number(i32), + Text(String), +} + +impl Value { + fn try_into_text(self) -> Result { + if let Self::Text(v) = self { + Ok(v) + } else { + Err(self) + } + } +} +``` + + [discrete] === `generate_from_impl_for_enum` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_from_impl_for_enum.rs#L8[generate_from_impl_for_enum.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_from_impl_for_enum.rs#L8[generate_from_impl_for_enum.rs] Adds a From impl for an enum variant with one tuple field. @@ -603,7 +668,7 @@ impl From for A { [discrete] === `generate_function` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_function.rs#L18[generate_function.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_function.rs#L18[generate_function.rs] Adds a stub function with a signature matching the function under the cursor. @@ -634,7 +699,7 @@ fn bar(arg: &str, baz: Baz) ${0:-> ()} { [discrete] === `generate_getter` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_getter.rs#L9[generate_getter.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_getter.rs#L9[generate_getter.rs] Generate a getter method. @@ -662,7 +727,7 @@ impl Person { [discrete] === `generate_getter_mut` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_getter_mut.rs#L9[generate_getter_mut.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_getter_mut.rs#L9[generate_getter_mut.rs] Generate a mut getter method. @@ -690,7 +755,7 @@ impl Person { [discrete] === `generate_impl` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_impl.rs#L5[generate_impl.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_impl.rs#L5[generate_impl.rs] Adds a new inherent impl for a type. @@ -715,7 +780,7 @@ impl Ctx { [discrete] === `generate_new` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_new.rs#L11[generate_new.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_new.rs#L11[generate_new.rs] Adds a new inherent impl for a type. @@ -740,7 +805,7 @@ impl Ctx { [discrete] === `generate_setter` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/generate_setter.rs#L9[generate_setter.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/generate_setter.rs#L9[generate_setter.rs] Generate a setter method. @@ -768,7 +833,7 @@ impl Person { [discrete] === `infer_function_return_type` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/infer_function_return_type.rs#L7[infer_function_return_type.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/infer_function_return_type.rs#L7[infer_function_return_type.rs] Adds the return type to a function or closure inferred from its tail expression if it doesn't have a return type specified. This assists is useable in a functions or closures tail expression or return type position. @@ -786,7 +851,7 @@ fn foo() -> i32 { 42i32 } [discrete] === `inline_function` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/inline_function.rs#L14[inline_function.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/inline_function.rs#L14[inline_function.rs] Inlines a function body. @@ -813,7 +878,7 @@ fn main() { [discrete] === `inline_local_variable` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/inline_local_variable.rs#L14[inline_local_variable.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/inline_local_variable.rs#L14[inline_local_variable.rs] Inlines local variable. @@ -835,7 +900,7 @@ fn main() { [discrete] === `introduce_named_lifetime` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/introduce_named_lifetime.rs#L12[introduce_named_lifetime.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/introduce_named_lifetime.rs#L12[introduce_named_lifetime.rs] Change an anonymous lifetime to a named lifetime. @@ -864,7 +929,7 @@ impl<'a> Cursor<'a> { [discrete] === `invert_if` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/invert_if.rs#L12[invert_if.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/invert_if.rs#L12[invert_if.rs] Apply invert_if This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` @@ -888,7 +953,7 @@ fn main() { [discrete] === `make_raw_string` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/raw_string.rs#L8[raw_string.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/raw_string.rs#L8[raw_string.rs] Adds `r#` to a plain string literal. @@ -909,7 +974,7 @@ fn main() { [discrete] === `make_usual_string` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/raw_string.rs#L50[raw_string.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/raw_string.rs#L50[raw_string.rs] Turns a raw string into a plain string. @@ -930,7 +995,7 @@ fn main() { [discrete] === `merge_imports` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/merge_imports.rs#L13[merge_imports.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/merge_imports.rs#L13[merge_imports.rs] Merges two imports with a common prefix. @@ -948,7 +1013,7 @@ use std::{fmt::Formatter, io}; [discrete] === `merge_match_arms` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/merge_match_arms.rs#L11[merge_match_arms.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/merge_match_arms.rs#L11[merge_match_arms.rs] Merges identical match arms. @@ -978,7 +1043,7 @@ fn handle(action: Action) { [discrete] === `move_arm_cond_to_match_guard` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/move_guard.rs#L68[move_guard.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/move_guard.rs#L68[move_guard.rs] Moves if expression from match arm body into a guard. @@ -1009,7 +1074,7 @@ fn handle(action: Action) { [discrete] === `move_bounds_to_where_clause` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/move_bounds.rs#L10[move_bounds.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/move_bounds.rs#L10[move_bounds.rs] Moves inline type bounds to a where clause. @@ -1030,7 +1095,7 @@ fn apply(f: F, x: T) -> U where F: FnOnce(T) -> U { [discrete] === `move_guard_to_arm_body` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/move_guard.rs#L8[move_guard.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/move_guard.rs#L8[move_guard.rs] Moves match guard into match arm body. @@ -1063,7 +1128,7 @@ fn handle(action: Action) { [discrete] === `move_module_to_file` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/move_module_to_file.rs#L12[move_module_to_file.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/move_module_to_file.rs#L12[move_module_to_file.rs] Moves inline module's contents to a separate file. @@ -1082,7 +1147,7 @@ mod foo; [discrete] === `pull_assignment_up` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/pull_assignment_up.rs#L12[pull_assignment_up.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/pull_assignment_up.rs#L12[pull_assignment_up.rs] Extracts variable assignment to outside an if or match statement. @@ -1115,7 +1180,7 @@ fn main() { [discrete] === `qualify_path` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/qualify_path.rs#L20[qualify_path.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/qualify_path.rs#L20[qualify_path.rs] If the name is unresolved, provides all possible qualified paths for it. @@ -1136,7 +1201,7 @@ fn main() { [discrete] === `remove_dbg` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/remove_dbg.rs#L8[remove_dbg.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/remove_dbg.rs#L8[remove_dbg.rs] Removes `dbg!()` macro call. @@ -1157,7 +1222,7 @@ fn main() { [discrete] === `remove_hash` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/raw_string.rs#L120[raw_string.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/raw_string.rs#L120[raw_string.rs] Removes a hash from a raw string literal. @@ -1178,7 +1243,7 @@ fn main() { [discrete] === `remove_mut` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/remove_mut.rs#L5[remove_mut.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/remove_mut.rs#L5[remove_mut.rs] Removes the `mut` keyword. @@ -1199,7 +1264,7 @@ impl Walrus { [discrete] === `remove_unused_param` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/remove_unused_param.rs#L14[remove_unused_param.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/remove_unused_param.rs#L14[remove_unused_param.rs] Removes unused function parameter. @@ -1224,7 +1289,7 @@ fn main() { [discrete] === `reorder_fields` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/reorder_fields.rs#L11[reorder_fields.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/reorder_fields.rs#L11[reorder_fields.rs] Reorder the fields of record literals and record patterns in the same order as in the definition. @@ -1244,7 +1309,7 @@ const test: Foo = Foo {foo: 1, bar: 0} [discrete] === `reorder_impl` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/reorder_impl.rs#L15[reorder_impl.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/reorder_impl.rs#L15[reorder_impl.rs] Reorder the methods of an `impl Trait`. The methods will be ordered in the same order as in the trait definition. @@ -1284,7 +1349,7 @@ impl Foo for Bar { [discrete] === `replace_derive_with_manual_impl` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_derive_with_manual_impl.rs#L19[replace_derive_with_manual_impl.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_derive_with_manual_impl.rs#L19[replace_derive_with_manual_impl.rs] Converts a `derive` impl into a manual one. @@ -1307,9 +1372,36 @@ impl Debug for S { ``` +[discrete] +=== `replace_for_loop_with_for_each` +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_for_loop_with_for_each.rs#L10[replace_for_loop_with_for_each.rs] + +Converts a for loop into a for_each loop on the Iterator. + +.Before +```rust +fn main() { + let x = vec![1, 2, 3]; + for┃ v in x { + let y = v * 2; + } +} +``` + +.After +```rust +fn main() { + let x = vec![1, 2, 3]; + x.into_iter().for_each(|v| { + let y = v * 2; + }); +} +``` + + [discrete] === `replace_if_let_with_match` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_if_let_with_match.rs#L18[replace_if_let_with_match.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_if_let_with_match.rs#L18[replace_if_let_with_match.rs] Replaces `if let` with an else branch with a `match` expression. @@ -1341,7 +1433,7 @@ fn handle(action: Action) { [discrete] === `replace_impl_trait_with_generic` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_impl_trait_with_generic.rs#L5[replace_impl_trait_with_generic.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_impl_trait_with_generic.rs#L5[replace_impl_trait_with_generic.rs] Replaces `impl Trait` function argument with the named generic. @@ -1358,7 +1450,7 @@ fn foo(bar: B) {} [discrete] === `replace_let_with_if_let` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_let_with_if_let.rs#L15[replace_let_with_if_let.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_let_with_if_let.rs#L15[replace_let_with_if_let.rs] Replaces `let` with an `if-let`. @@ -1386,7 +1478,7 @@ fn compute() -> Option { None } [discrete] === `replace_match_with_if_let` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_if_let_with_match.rs#L93[replace_if_let_with_match.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_if_let_with_match.rs#L93[replace_if_let_with_match.rs] Replaces a binary `match` with a wildcard pattern and no guards with an `if let` expression. @@ -1418,7 +1510,7 @@ fn handle(action: Action) { [discrete] === `replace_qualified_name_with_use` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_qualified_name_with_use.rs#L7[replace_qualified_name_with_use.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_qualified_name_with_use.rs#L7[replace_qualified_name_with_use.rs] Adds a use statement for a given fully-qualified name. @@ -1437,7 +1529,7 @@ fn process(map: HashMap) {} [discrete] === `replace_string_with_char` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_string_with_char.rs#L5[replace_string_with_char.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_string_with_char.rs#L5[replace_string_with_char.rs] Replace string with char. @@ -1458,7 +1550,7 @@ fn main() { [discrete] === `replace_unwrap_with_match` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/replace_unwrap_with_match.rs#L18[replace_unwrap_with_match.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/replace_unwrap_with_match.rs#L18[replace_unwrap_with_match.rs] Replaces `unwrap` a `match` expression. Works for Result and Option. @@ -1486,7 +1578,7 @@ fn main() { [discrete] === `split_import` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/split_import.rs#L7[split_import.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/split_import.rs#L7[split_import.rs] Wraps the tail of import into braces. @@ -1503,7 +1595,7 @@ use std::{collections::HashMap}; [discrete] === `toggle_ignore` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/toggle_ignore.rs#L8[toggle_ignore.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/toggle_ignore.rs#L8[toggle_ignore.rs] Adds `#[ignore]` attribute to the test. @@ -1527,7 +1619,7 @@ fn arithmetics { [discrete] === `unmerge_use` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/unmerge_use.rs#L13[unmerge_use.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/unmerge_use.rs#L13[unmerge_use.rs] Extracts single use item from use list. @@ -1545,7 +1637,7 @@ use std::fmt::Display; [discrete] === `unwrap_block` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/unwrap_block.rs#L11[unwrap_block.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/unwrap_block.rs#L11[unwrap_block.rs] This assist removes if...else, for, while and loop control statements to just keep the body. @@ -1568,7 +1660,7 @@ fn foo() { [discrete] === `wrap_return_type_in_result` -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/wrap_return_type_in_result.rs#L11[wrap_return_type_in_result.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/wrap_return_type_in_result.rs#L11[wrap_return_type_in_result.rs] Wrap the function's return type into Result. diff --git a/generated_features.adoc b/generated_features.adoc index 382b2b1a..43684165 100644 --- a/generated_features.adoc +++ b/generated_features.adoc @@ -7,7 +7,7 @@ and running/debugging binaries. === Auto Import -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/assists/src/handlers/auto_import.rs#L10[auto_import.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_assists/src/handlers/auto_import.rs#L10[auto_import.rs] Using the `auto-import` assist it is possible to insert missing imports for unresolved items. When inserting an import it will do so in a structured manner by keeping imports grouped, @@ -33,9 +33,9 @@ use self::auto_import; use super::AssistContext; ``` -.Merge Behaviour +.Merge Behavior -It is possible to configure how use-trees are merged with the `importMergeBehaviour` setting. +It is possible to configure how use-trees are merged with the `importMergeBehavior` setting. It has the following configurations: - `full`: This setting will cause auto-import to always completely merge use-trees that share the @@ -46,7 +46,7 @@ It has the following configurations: - `none`: This setting will cause auto-import to never merge use-trees keeping them as simple paths. -In `VS Code` the configuration for this is `rust-analyzer.assist.importMergeBehaviour`. +In `VS Code` the configuration for this is `rust-analyzer.assist.importMergeBehavior`. .Import Prefix @@ -385,7 +385,7 @@ Shows internal statistic about memory usage of rust-analyzer. === Structural Search and Replace -**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ssr/src/lib.rs#L6[lib.rs] +**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ide_ssr/src/lib.rs#L6[lib.rs] Search and replace with named wildcards that will match any expression, type, path, pattern or item. The syntax for a structural search replace command is ` ==>> `. diff --git a/manual.adoc b/manual.adoc index a2c7f56b..9f28237f 100644 --- a/manual.adoc +++ b/manual.adoc @@ -398,7 +398,7 @@ In general `rust-analyzer` is configured via LSP messages, which means that it's Some clients, such as <> or <> provide `rust-analyzer` specific configuration UIs. Others may require you to know a bit more about the interaction with `rust-analyzer`. -For the later category, it might help to know that the initial configuration is specified as a value of the `intializationOptions` field of the https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize[`InitializeParams` message, in the LSP protocol]. +For the later category, it might help to know that the initial configuration is specified as a value of the `initializationOptions` field of the https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize[`InitializeParams` message, in the LSP protocol]. The spec says that the field type is `any?`, but `rust-analyzer` is looking for a JSON object that is constructed using settings from the list below. Name of the setting, ignoring the `rust-analyzer.` prefix, is used as a path, and value of the setting becomes the JSON property value. diff --git a/thisweek/_posts/2021-03-01-changelog-66.adoc b/thisweek/_posts/2021-03-01-changelog-66.adoc new file mode 100644 index 00000000..c1f86fea --- /dev/null +++ b/thisweek/_posts/2021-03-01-changelog-66.adoc @@ -0,0 +1,59 @@ += Changelog #66 +:sectanchors: +:page-layout: post + +Commit: commit:5df3ee8274fdb7cdeb2b0871b4efea8cbf4724a1[] + +Release: release:2021-03-01[] + +== Sponsors + +**Become a sponsor:** On https://opencollective.com/rust-analyzer/[OpenCollective] or +https://github.com/sponsors/rust-analyzer[GitHub Sponsors]. + +== New Features + +* pr:7677[] generate more enum matching methods: ++ +image::https://user-images.githubusercontent.com/308347/109462415-1c03cd80-7a6c-11eb-8ed8-9fed51c0acb5.gif[] + +* pr:7741[] add "convert for loop into iterator" assist: ++ +image::https://user-images.githubusercontent.com/3757771/109151603-adbcc380-776a-11eb-92ab-5774a949c009.gif[] + +* pr:7719[] (first contribution) correctly parenthesize binary expression in the "apply De Morgan's law" assist: ++ +image::https://user-images.githubusercontent.com/3757771/109150372-1440e200-7769-11eb-8e13-afa4ac5b89ac.gif[] + +== Fixes + +* pr:7749[] make common assists easier to use. +* pr:7753[] (first contribution) add `isize` to the list of suffixed integers in `typed_integer`. +* pr:7768[] fix visibility computation inside block expressions. +* pr:7772[] pick up `ConstReference` patterns in `FindUsages`. +* pr:7775[] (first contribution) fix typo in manual. +* pr:7792[] (first contribution) change remaining occurrences of `importMergeBehaviour` to `importMergeBehavior`. +* pr:7794[] (first contribution) disable "Flip comma" assist inside macro calls. +* pr:7801[] restrict visibilities to the containing `DefMap`. +* pr:7802[], pr:7808[] fix builtin macros splitting expression on commas. +* pr:7803[] fix non-Latin characters in MBE doc comment expansion: ++ +image::https://user-images.githubusercontent.com/11014119/109409237-f58e5580-79cb-11eb-92ed-a6700bbe39b5.gif[] + +* pr:7805[] highlight only the last segment of unresolved macros. +* pr:7809[] (first contribution) delete old issues from GitHub's bug report template. +* pr:7815[] fix default allocator type in the inference of `box` expressions. + +== Internal Improvements + +* pr:7759[] (first contribution) rename `assists` and `ssr`. +* pr:7766[] update Code npm dependencies. +* pr:7770[] make memory usage reporting during benchmarking more reliable. +* pr:7566[] add benchmark tests for MBE. +* pr:7797[] format generated lints and features manually to avoid long lines. +* pr:7806[] update remaining references to `AnalysisChange`. +* pr:7807[] directly link the changelog from the `README`. +* pr:7804[] introduce `TypeCtor::Scalar`. +* pr:7812[] use consistent naming for assist. +* pr:7813[] inline `TypeCtor` into `Ty`. +* pr:7814[] turn `Ty::Tuple` variant into a tuple-variant. +* pr:7816[] lift `Ty::Fn` into a struct.