diff options
Diffstat (limited to 'docs/user')
-rw-r--r-- | docs/user/assists.md | 119 | ||||
-rw-r--r-- | docs/user/features.md | 174 |
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 | |||
43 | Adds a hash to a raw string literal. | ||
44 | |||
45 | ```rust | ||
46 | // BEFORE | ||
47 | fn main() { | ||
48 | r#"Hello,┃ World!"#; | ||
49 | } | ||
50 | |||
51 | // AFTER | ||
52 | fn main() { | ||
53 | r##"Hello, World!"##; | ||
54 | } | ||
55 | ``` | ||
56 | |||
41 | ## `add_impl` | 57 | ## `add_impl` |
42 | 58 | ||
43 | Adds a new inherent impl for a type. | 59 | Adds a new inherent impl for a type. |
@@ -266,6 +282,38 @@ fn main() { | |||
266 | } | 282 | } |
267 | ``` | 283 | ``` |
268 | 284 | ||
285 | ## `make_raw_string` | ||
286 | |||
287 | Adds `r#` to a plain string literal. | ||
288 | |||
289 | ```rust | ||
290 | // BEFORE | ||
291 | fn main() { | ||
292 | "Hello,┃ World!"; | ||
293 | } | ||
294 | |||
295 | // AFTER | ||
296 | fn main() { | ||
297 | r#"Hello, World!"#; | ||
298 | } | ||
299 | ``` | ||
300 | |||
301 | ## `make_usual_string` | ||
302 | |||
303 | Turns a raw string into a plain string. | ||
304 | |||
305 | ```rust | ||
306 | // BEFORE | ||
307 | fn main() { | ||
308 | r#"Hello,┃ "World!""#; | ||
309 | } | ||
310 | |||
311 | // AFTER | ||
312 | fn main() { | ||
313 | "Hello, \"World!\""; | ||
314 | } | ||
315 | ``` | ||
316 | |||
269 | ## `merge_match_arms` | 317 | ## `merge_match_arms` |
270 | 318 | ||
271 | Merges identical match arms. | 319 | Merges identical match arms. |
@@ -358,3 +406,74 @@ fn handle(action: Action) { | |||
358 | } | 406 | } |
359 | } | 407 | } |
360 | ``` | 408 | ``` |
409 | |||
410 | ## `remove_dbg` | ||
411 | |||
412 | Removes `dbg!()` macro call. | ||
413 | |||
414 | ```rust | ||
415 | // BEFORE | ||
416 | fn main() { | ||
417 | ┃dbg!(92); | ||
418 | } | ||
419 | |||
420 | // AFTER | ||
421 | fn main() { | ||
422 | 92; | ||
423 | } | ||
424 | ``` | ||
425 | |||
426 | ## `remove_hash` | ||
427 | |||
428 | Removes a hash from a raw string literal. | ||
429 | |||
430 | ```rust | ||
431 | // BEFORE | ||
432 | fn main() { | ||
433 | r#"Hello,┃ World!"#; | ||
434 | } | ||
435 | |||
436 | // AFTER | ||
437 | fn main() { | ||
438 | r"Hello, World!"; | ||
439 | } | ||
440 | ``` | ||
441 | |||
442 | ## `replace_if_let_with_match` | ||
443 | |||
444 | Replaces `if let` with an else branch with a `match` expression. | ||
445 | |||
446 | ```rust | ||
447 | // BEFORE | ||
448 | enum Action { Move { distance: u32 }, Stop } | ||
449 | |||
450 | fn handle(action: Action) { | ||
451 | ┃if let Action::Move { distance } = action { | ||
452 | foo(distance) | ||
453 | } else { | ||
454 | bar() | ||
455 | } | ||
456 | } | ||
457 | |||
458 | // AFTER | ||
459 | enum Action { Move { distance: u32 }, Stop } | ||
460 | |||
461 | fn handle(action: Action) { | ||
462 | match action { | ||
463 | Action::Move { distance } => foo(distance), | ||
464 | _ => bar(), | ||
465 | } | ||
466 | } | ||
467 | ``` | ||
468 | |||
469 | ## `split_import` | ||
470 | |||
471 | Wraps the tail of import into braces. | ||
472 | |||
473 | ```rust | ||
474 | // BEFORE | ||
475 | use std::┃collections::HashMap; | ||
476 | |||
477 | // AFTER | ||
478 | use 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: | ||
125 | struct S<'a, D> { | ||
126 | a: u32, | ||
127 | b: String, | ||
128 | c: (i32, i32), | ||
129 | d: D, | ||
130 | r: &'a str, | ||
131 | } | ||
132 | |||
133 | fn main() { | ||
134 | let s = S<|> {} | ||
135 | } | ||
136 | |||
137 | // after: | ||
138 | struct S<'a, D> { | ||
139 | a: u32, | ||
140 | b: String, | ||
141 | c: (i32, i32), | ||
142 | d: D, | ||
143 | r: &'a str, | ||
144 | } | ||
145 | |||
146 | fn 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: | ||
161 | fn foo(n: usize) { | ||
162 | if let Some(_) = dbg!(n.<|>checked_sub(4)) { | ||
163 | // ... | ||
164 | } | ||
165 | } | ||
166 | |||
167 | // after: | ||
168 | fn 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: | ||
179 | impl 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: | ||
190 | impl 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: | ||
204 | use crate:<|>:db::{RootDatabase, FileSymbol}; | ||
205 | // after: | ||
206 | use crate::{<|>db::{RootDatabase, FileSymbol}}; | ||
207 | ``` | ||
208 | |||
209 | - Move if condition to match arm guard | ||
210 | ```rust | ||
211 | // before: | ||
212 | fn 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: | ||
225 | fn 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: | ||
242 | fn f() { | ||
243 | let s = <|>"ab\ncd"; | ||
244 | } | ||
245 | |||
246 | // after: | ||
247 | fn f() { | ||
248 | let s = <|>r#"ab | ||
249 | cd"#; | ||
250 | } | ||
251 | ``` | ||
252 | |||
253 | - Make usual string | ||
254 | |||
255 | ```rust | ||
256 | // before: | ||
257 | fn f() { | ||
258 | let s = <|>r#"abcd"#; | ||
259 | } | ||
260 | |||
261 | // after: | ||
262 | fn f() { | ||
263 | let s = <|>"abcd"; | ||
264 | } | ||
265 | ``` | ||
266 | |||
267 | - Add hash | ||
268 | |||
269 | ```rust | ||
270 | // before: | ||
271 | fn f() { | ||
272 | let s = <|>r"abcd"; | ||
273 | } | ||
274 | |||
275 | // after: | ||
276 | fn f() { | ||
277 | let s = <|>r#"abcd"#; | ||
278 | } | ||
279 | ``` | ||
280 | |||
281 | - Remove hash | ||
282 | |||
283 | ```rust | ||
284 | // before: | ||
285 | fn f() { | ||
286 | let s = <|>r#"abcd"#; | ||
287 | } | ||
288 | |||
289 | // after: | ||
290 | fn f() { | ||
291 | let s = <|>r"abcd"; | ||
292 | } | ||
293 | ``` | ||
294 | |||
295 | ### Magic Completions | 121 | ### Magic Completions |
296 | 122 | ||
297 | In addition to usual reference completion, rust-analyzer provides some ✨magic✨ | 123 | In addition to usual reference completion, rust-analyzer provides some ✨magic✨ |