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') 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