aboutsummaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
Diffstat (limited to 'docs')
-rw-r--r--docs/user/assists.md119
-rw-r--r--docs/user/features.md174
2 files changed, 119 insertions, 174 deletions
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() {
38} 38}
39``` 39```
40 40
41## `add_hash`
42
43Adds a hash to a raw string literal.
44
45```rust
46// BEFORE
47fn main() {
48 r#"Hello,┃ World!"#;
49}
50
51// AFTER
52fn main() {
53 r##"Hello, World!"##;
54}
55```
56
41## `add_impl` 57## `add_impl`
42 58
43Adds a new inherent impl for a type. 59Adds a new inherent impl for a type.
@@ -266,6 +282,38 @@ fn main() {
266} 282}
267``` 283```
268 284
285## `make_raw_string`
286
287Adds `r#` to a plain string literal.
288
289```rust
290// BEFORE
291fn main() {
292 "Hello,┃ World!";
293}
294
295// AFTER
296fn main() {
297 r#"Hello, World!"#;
298}
299```
300
301## `make_usual_string`
302
303Turns a raw string into a plain string.
304
305```rust
306// BEFORE
307fn main() {
308 r#"Hello,┃ "World!""#;
309}
310
311// AFTER
312fn main() {
313 "Hello, \"World!\"";
314}
315```
316
269## `merge_match_arms` 317## `merge_match_arms`
270 318
271Merges identical match arms. 319Merges identical match arms.
@@ -358,3 +406,74 @@ fn handle(action: Action) {
358 } 406 }
359} 407}
360``` 408```
409
410## `remove_dbg`
411
412Removes `dbg!()` macro call.
413
414```rust
415// BEFORE
416fn main() {
417 ┃dbg!(92);
418}
419
420// AFTER
421fn main() {
422 92;
423}
424```
425
426## `remove_hash`
427
428Removes a hash from a raw string literal.
429
430```rust
431// BEFORE
432fn main() {
433 r#"Hello,┃ World!"#;
434}
435
436// AFTER
437fn main() {
438 r"Hello, World!";
439}
440```
441
442## `replace_if_let_with_match`
443
444Replaces `if let` with an else branch with a `match` expression.
445
446```rust
447// BEFORE
448enum Action { Move { distance: u32 }, Stop }
449
450fn handle(action: Action) {
451 ┃if let Action::Move { distance } = action {
452 foo(distance)
453 } else {
454 bar()
455 }
456}
457
458// AFTER
459enum Action { Move { distance: u32 }, Stop }
460
461fn handle(action: Action) {
462 match action {
463 Action::Move { distance } => foo(distance),
464 _ => bar(),
465 }
466}
467```
468
469## `split_import`
470
471Wraps the tail of import into braces.
472
473```rust
474// BEFORE
475use std::┃collections::HashMap;
476
477// AFTER
478use std::{collections::HashMap};
479```
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 {
118} 118}
119``` 119```
120 120
121- Fill struct fields
122
123```rust
124// before:
125struct S<'a, D> {
126 a: u32,
127 b: String,
128 c: (i32, i32),
129 d: D,
130 r: &'a str,
131}
132
133fn main() {
134 let s = S<|> {}
135}
136
137// after:
138struct S<'a, D> {
139 a: u32,
140 b: String,
141 c: (i32, i32),
142 d: D,
143 r: &'a str,
144}
145
146fn main() {
147 let s = <|>S {
148 a: (),
149 b: (),
150 c: (),
151 d: (),
152 r: (),
153 }
154}
155```
156
157- Remove `dbg!`
158
159```rust
160// before:
161fn foo(n: usize) {
162 if let Some(_) = dbg!(n.<|>checked_sub(4)) {
163 // ...
164 }
165}
166
167// after:
168fn foo(n: usize) {
169 if let Some(_) = n.<|>checked_sub(4) {
170 // ...
171 }
172}
173```
174
175- Replace if-let with match:
176
177```rust
178// before:
179impl VariantData {
180 pub fn is_struct(&self) -> bool {
181 if <|>let VariantData::Struct(..) = *self {
182 true
183 } else {
184 false
185 }
186 }
187}
188
189// after:
190impl VariantData {
191 pub fn is_struct(&self) -> bool {
192 <|>match *self {
193 VariantData::Struct(..) => true,
194 _ => false,
195 }
196 }
197}
198```
199
200- Split import
201
202```rust
203// before:
204use crate:<|>:db::{RootDatabase, FileSymbol};
205// after:
206use crate::{<|>db::{RootDatabase, FileSymbol}};
207```
208
209- Move if condition to match arm guard
210```rust
211// before:
212fn f() {
213 let mut t = 'a';
214 let chars = "abcd";
215 match t {
216 '\r' => if chars.clone().next().is_some() {
217 t = 'e';<|>
218 false
219 },
220 _ => true
221 }
222}
223
224// after:
225fn f() {
226 let mut t = 'a';
227 let chars = "abcd";
228 match t {
229 '\r' <|>if chars.clone().next().is_some() => {
230 t = 'e';
231 false
232 },
233 _ => true
234 }
235}
236```
237
238- Make raw string unescaped
239
240```rust
241// before:
242fn f() {
243 let s = <|>"ab\ncd";
244}
245
246// after:
247fn f() {
248 let s = <|>r#"ab
249cd"#;
250}
251```
252
253- Make usual string
254
255```rust
256// before:
257fn f() {
258 let s = <|>r#"abcd"#;
259}
260
261// after:
262fn f() {
263 let s = <|>"abcd";
264}
265```
266
267- Add hash
268
269```rust
270// before:
271fn f() {
272 let s = <|>r"abcd";
273}
274
275// after:
276fn f() {
277 let s = <|>r#"abcd"#;
278}
279```
280
281- Remove hash
282
283```rust
284// before:
285fn f() {
286 let s = <|>r#"abcd"#;
287}
288
289// after:
290fn f() {
291 let s = <|>r"abcd";
292}
293```
294
295### Magic Completions 121### Magic Completions
296 122
297In addition to usual reference completion, rust-analyzer provides some ✨magic✨ 123In addition to usual reference completion, rust-analyzer provides some ✨magic✨