diff options
Diffstat (limited to 'docs/user')
-rw-r--r-- | docs/user/generated_assists.adoc (renamed from docs/user/assists.md) | 466 | ||||
-rw-r--r-- | docs/user/generated_features.adoc | 38 | ||||
-rw-r--r-- | docs/user/manual.adoc (renamed from docs/user/readme.adoc) | 40 |
3 files changed, 374 insertions, 170 deletions
diff --git a/docs/user/assists.md b/docs/user/generated_assists.adoc index 04387e3b0..580ab4358 100644 --- a/docs/user/assists.md +++ b/docs/user/generated_assists.adoc | |||
@@ -1,18 +1,17 @@ | |||
1 | # Assists | 1 | [discrete] |
2 | 2 | === `add_custom_impl` | |
3 | Cursor position or selection is signified by `┃` character. | 3 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_custom_impl.rs#L14[add_custom_impl.rs] |
4 | |||
5 | |||
6 | ## `add_custom_impl` | ||
7 | 4 | ||
8 | Adds impl block for derived trait. | 5 | Adds impl block for derived trait. |
9 | 6 | ||
7 | .Before | ||
10 | ```rust | 8 | ```rust |
11 | // BEFORE | ||
12 | #[derive(Deb┃ug, Display)] | 9 | #[derive(Deb┃ug, Display)] |
13 | struct S; | 10 | struct S; |
11 | ``` | ||
14 | 12 | ||
15 | // AFTER | 13 | .After |
14 | ```rust | ||
16 | #[derive(Display)] | 15 | #[derive(Display)] |
17 | struct S; | 16 | struct S; |
18 | 17 | ||
@@ -21,18 +20,23 @@ impl Debug for S { | |||
21 | } | 20 | } |
22 | ``` | 21 | ``` |
23 | 22 | ||
24 | ## `add_derive` | 23 | |
24 | [discrete] | ||
25 | === `add_derive` | ||
26 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_derive.rs#L9[add_derive.rs] | ||
25 | 27 | ||
26 | Adds a new `#[derive()]` clause to a struct or enum. | 28 | Adds a new `#[derive()]` clause to a struct or enum. |
27 | 29 | ||
30 | .Before | ||
28 | ```rust | 31 | ```rust |
29 | // BEFORE | ||
30 | struct Point { | 32 | struct Point { |
31 | x: u32, | 33 | x: u32, |
32 | y: u32,┃ | 34 | y: u32,┃ |
33 | } | 35 | } |
36 | ``` | ||
34 | 37 | ||
35 | // AFTER | 38 | .After |
39 | ```rust | ||
36 | #[derive($0)] | 40 | #[derive($0)] |
37 | struct Point { | 41 | struct Point { |
38 | x: u32, | 42 | x: u32, |
@@ -40,31 +44,41 @@ struct Point { | |||
40 | } | 44 | } |
41 | ``` | 45 | ``` |
42 | 46 | ||
43 | ## `add_explicit_type` | 47 | |
48 | [discrete] | ||
49 | === `add_explicit_type` | ||
50 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_explicit_type.rs#L9[add_explicit_type.rs] | ||
44 | 51 | ||
45 | Specify type for a let binding. | 52 | Specify type for a let binding. |
46 | 53 | ||
54 | .Before | ||
47 | ```rust | 55 | ```rust |
48 | // BEFORE | ||
49 | fn main() { | 56 | fn main() { |
50 | let x┃ = 92; | 57 | let x┃ = 92; |
51 | } | 58 | } |
59 | ``` | ||
52 | 60 | ||
53 | // AFTER | 61 | .After |
62 | ```rust | ||
54 | fn main() { | 63 | fn main() { |
55 | let x: i32 = 92; | 64 | let x: i32 = 92; |
56 | } | 65 | } |
57 | ``` | 66 | ``` |
58 | 67 | ||
59 | ## `add_from_impl_for_enum` | 68 | |
69 | [discrete] | ||
70 | === `add_from_impl_for_enum` | ||
71 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_from_impl_for_enum.rs#L7[add_from_impl_for_enum.rs] | ||
60 | 72 | ||
61 | Adds a From impl for an enum variant with one tuple field. | 73 | Adds a From impl for an enum variant with one tuple field. |
62 | 74 | ||
75 | .Before | ||
63 | ```rust | 76 | ```rust |
64 | // BEFORE | ||
65 | enum A { ┃One(u32) } | 77 | enum A { ┃One(u32) } |
78 | ``` | ||
66 | 79 | ||
67 | // AFTER | 80 | .After |
81 | ```rust | ||
68 | enum A { One(u32) } | 82 | enum A { One(u32) } |
69 | 83 | ||
70 | impl From<u32> for A { | 84 | impl From<u32> for A { |
@@ -74,20 +88,25 @@ impl From<u32> for A { | |||
74 | } | 88 | } |
75 | ``` | 89 | ``` |
76 | 90 | ||
77 | ## `add_function` | 91 | |
92 | [discrete] | ||
93 | === `add_function` | ||
94 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_function.rs#L19[add_function.rs] | ||
78 | 95 | ||
79 | Adds a stub function with a signature matching the function under the cursor. | 96 | Adds a stub function with a signature matching the function under the cursor. |
80 | 97 | ||
98 | .Before | ||
81 | ```rust | 99 | ```rust |
82 | // BEFORE | ||
83 | struct Baz; | 100 | struct Baz; |
84 | fn baz() -> Baz { Baz } | 101 | fn baz() -> Baz { Baz } |
85 | fn foo() { | 102 | fn foo() { |
86 | bar┃("", baz()); | 103 | bar┃("", baz()); |
87 | } | 104 | } |
88 | 105 | ||
106 | ``` | ||
89 | 107 | ||
90 | // AFTER | 108 | .After |
109 | ```rust | ||
91 | struct Baz; | 110 | struct Baz; |
92 | fn baz() -> Baz { Baz } | 111 | fn baz() -> Baz { Baz } |
93 | fn foo() { | 112 | fn foo() { |
@@ -100,33 +119,43 @@ fn bar(arg: &str, baz: Baz) { | |||
100 | 119 | ||
101 | ``` | 120 | ``` |
102 | 121 | ||
103 | ## `add_hash` | 122 | |
123 | [discrete] | ||
124 | === `add_hash` | ||
125 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/raw_string.rs#L65[raw_string.rs] | ||
104 | 126 | ||
105 | Adds a hash to a raw string literal. | 127 | Adds a hash to a raw string literal. |
106 | 128 | ||
129 | .Before | ||
107 | ```rust | 130 | ```rust |
108 | // BEFORE | ||
109 | fn main() { | 131 | fn main() { |
110 | r#"Hello,┃ World!"#; | 132 | r#"Hello,┃ World!"#; |
111 | } | 133 | } |
134 | ``` | ||
112 | 135 | ||
113 | // AFTER | 136 | .After |
137 | ```rust | ||
114 | fn main() { | 138 | fn main() { |
115 | r##"Hello, World!"##; | 139 | r##"Hello, World!"##; |
116 | } | 140 | } |
117 | ``` | 141 | ``` |
118 | 142 | ||
119 | ## `add_impl` | 143 | |
144 | [discrete] | ||
145 | === `add_impl` | ||
146 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_impl.rs#L6[add_impl.rs] | ||
120 | 147 | ||
121 | Adds a new inherent impl for a type. | 148 | Adds a new inherent impl for a type. |
122 | 149 | ||
150 | .Before | ||
123 | ```rust | 151 | ```rust |
124 | // BEFORE | ||
125 | struct Ctx<T: Clone> { | 152 | struct Ctx<T: Clone> { |
126 | data: T,┃ | 153 | data: T,┃ |
127 | } | 154 | } |
155 | ``` | ||
128 | 156 | ||
129 | // AFTER | 157 | .After |
158 | ```rust | ||
130 | struct Ctx<T: Clone> { | 159 | struct Ctx<T: Clone> { |
131 | data: T, | 160 | data: T, |
132 | } | 161 | } |
@@ -136,12 +165,15 @@ impl<T: Clone> Ctx<T> { | |||
136 | } | 165 | } |
137 | ``` | 166 | ``` |
138 | 167 | ||
139 | ## `add_impl_default_members` | 168 | |
169 | [discrete] | ||
170 | === `add_impl_default_members` | ||
171 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_missing_impl_members.rs#L64[add_missing_impl_members.rs] | ||
140 | 172 | ||
141 | Adds scaffold for overriding default impl members. | 173 | Adds scaffold for overriding default impl members. |
142 | 174 | ||
175 | .Before | ||
143 | ```rust | 176 | ```rust |
144 | // BEFORE | ||
145 | trait Trait { | 177 | trait Trait { |
146 | Type X; | 178 | Type X; |
147 | fn foo(&self); | 179 | fn foo(&self); |
@@ -153,8 +185,10 @@ impl Trait for () { | |||
153 | fn foo(&self) {}┃ | 185 | fn foo(&self) {}┃ |
154 | 186 | ||
155 | } | 187 | } |
188 | ``` | ||
156 | 189 | ||
157 | // AFTER | 190 | .After |
191 | ```rust | ||
158 | trait Trait { | 192 | trait Trait { |
159 | Type X; | 193 | Type X; |
160 | fn foo(&self); | 194 | fn foo(&self); |
@@ -169,12 +203,15 @@ impl Trait for () { | |||
169 | } | 203 | } |
170 | ``` | 204 | ``` |
171 | 205 | ||
172 | ## `add_impl_missing_members` | 206 | |
207 | [discrete] | ||
208 | === `add_impl_missing_members` | ||
209 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_missing_impl_members.rs#L24[add_missing_impl_members.rs] | ||
173 | 210 | ||
174 | Adds scaffold for required impl members. | 211 | Adds scaffold for required impl members. |
175 | 212 | ||
213 | .Before | ||
176 | ```rust | 214 | ```rust |
177 | // BEFORE | ||
178 | trait Trait<T> { | 215 | trait Trait<T> { |
179 | Type X; | 216 | Type X; |
180 | fn foo(&self) -> T; | 217 | fn foo(&self) -> T; |
@@ -184,8 +221,10 @@ trait Trait<T> { | |||
184 | impl Trait<u32> for () {┃ | 221 | impl Trait<u32> for () {┃ |
185 | 222 | ||
186 | } | 223 | } |
224 | ``` | ||
187 | 225 | ||
188 | // AFTER | 226 | .After |
227 | ```rust | ||
189 | trait Trait<T> { | 228 | trait Trait<T> { |
190 | Type X; | 229 | Type X; |
191 | fn foo(&self) -> T; | 230 | fn foo(&self) -> T; |
@@ -200,17 +239,22 @@ impl Trait<u32> for () { | |||
200 | } | 239 | } |
201 | ``` | 240 | ``` |
202 | 241 | ||
203 | ## `add_new` | 242 | |
243 | [discrete] | ||
244 | === `add_new` | ||
245 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_new.rs#L12[add_new.rs] | ||
204 | 246 | ||
205 | Adds a new inherent impl for a type. | 247 | Adds a new inherent impl for a type. |
206 | 248 | ||
249 | .Before | ||
207 | ```rust | 250 | ```rust |
208 | // BEFORE | ||
209 | struct Ctx<T: Clone> { | 251 | struct Ctx<T: Clone> { |
210 | data: T,┃ | 252 | data: T,┃ |
211 | } | 253 | } |
254 | ``` | ||
212 | 255 | ||
213 | // AFTER | 256 | .After |
257 | ```rust | ||
214 | struct Ctx<T: Clone> { | 258 | struct Ctx<T: Clone> { |
215 | data: T, | 259 | data: T, |
216 | } | 260 | } |
@@ -221,25 +265,33 @@ impl<T: Clone> Ctx<T> { | |||
221 | 265 | ||
222 | ``` | 266 | ``` |
223 | 267 | ||
224 | ## `add_turbo_fish` | 268 | |
269 | [discrete] | ||
270 | === `add_turbo_fish` | ||
271 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/add_turbo_fish.rs#L10[add_turbo_fish.rs] | ||
225 | 272 | ||
226 | Adds `::<_>` to a call of a generic method or function. | 273 | Adds `::<_>` to a call of a generic method or function. |
227 | 274 | ||
275 | .Before | ||
228 | ```rust | 276 | ```rust |
229 | // BEFORE | ||
230 | fn make<T>() -> T { todo!() } | 277 | fn make<T>() -> T { todo!() } |
231 | fn main() { | 278 | fn main() { |
232 | let x = make┃(); | 279 | let x = make┃(); |
233 | } | 280 | } |
281 | ``` | ||
234 | 282 | ||
235 | // AFTER | 283 | .After |
284 | ```rust | ||
236 | fn make<T>() -> T { todo!() } | 285 | fn make<T>() -> T { todo!() } |
237 | fn main() { | 286 | fn main() { |
238 | let x = make::<${0:_}>(); | 287 | let x = make::<${0:_}>(); |
239 | } | 288 | } |
240 | ``` | 289 | ``` |
241 | 290 | ||
242 | ## `apply_demorgan` | 291 | |
292 | [discrete] | ||
293 | === `apply_demorgan` | ||
294 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/apply_demorgan.rs#L5[apply_demorgan.rs] | ||
243 | 295 | ||
244 | Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). | 296 | Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). |
245 | This transforms expressions of the form `!l || !r` into `!(l && r)`. | 297 | This transforms expressions of the form `!l || !r` into `!(l && r)`. |
@@ -247,29 +299,36 @@ This also works with `&&`. This assist can only be applied with the cursor | |||
247 | on either `||` or `&&`, with both operands being a negation of some kind. | 299 | on either `||` or `&&`, with both operands being a negation of some kind. |
248 | This means something of the form `!x` or `x != y`. | 300 | This means something of the form `!x` or `x != y`. |
249 | 301 | ||
302 | .Before | ||
250 | ```rust | 303 | ```rust |
251 | // BEFORE | ||
252 | fn main() { | 304 | fn main() { |
253 | if x != 4 ||┃ !y {} | 305 | if x != 4 ||┃ !y {} |
254 | } | 306 | } |
307 | ``` | ||
255 | 308 | ||
256 | // AFTER | 309 | .After |
310 | ```rust | ||
257 | fn main() { | 311 | fn main() { |
258 | if !(x == 4 && y) {} | 312 | if !(x == 4 && y) {} |
259 | } | 313 | } |
260 | ``` | 314 | ``` |
261 | 315 | ||
262 | ## `auto_import` | 316 | |
317 | [discrete] | ||
318 | === `auto_import` | ||
319 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/auto_import.rs#L18[auto_import.rs] | ||
263 | 320 | ||
264 | If the name is unresolved, provides all possible imports for it. | 321 | If the name is unresolved, provides all possible imports for it. |
265 | 322 | ||
323 | .Before | ||
266 | ```rust | 324 | ```rust |
267 | // BEFORE | ||
268 | fn main() { | 325 | fn main() { |
269 | let map = HashMap┃::new(); | 326 | let map = HashMap┃::new(); |
270 | } | 327 | } |
328 | ``` | ||
271 | 329 | ||
272 | // AFTER | 330 | .After |
331 | ```rust | ||
273 | use std::collections::HashMap; | 332 | use std::collections::HashMap; |
274 | 333 | ||
275 | fn main() { | 334 | fn main() { |
@@ -277,12 +336,15 @@ fn main() { | |||
277 | } | 336 | } |
278 | ``` | 337 | ``` |
279 | 338 | ||
280 | ## `change_lifetime_anon_to_named` | 339 | |
340 | [discrete] | ||
341 | === `change_lifetime_anon_to_named` | ||
342 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/change_lifetime_anon_to_named.rs#L9[change_lifetime_anon_to_named.rs] | ||
281 | 343 | ||
282 | Change an anonymous lifetime to a named lifetime. | 344 | Change an anonymous lifetime to a named lifetime. |
283 | 345 | ||
346 | .Before | ||
284 | ```rust | 347 | ```rust |
285 | // BEFORE | ||
286 | impl Cursor<'_┃> { | 348 | impl Cursor<'_┃> { |
287 | fn node(self) -> &SyntaxNode { | 349 | fn node(self) -> &SyntaxNode { |
288 | match self { | 350 | match self { |
@@ -290,8 +352,10 @@ impl Cursor<'_┃> { | |||
290 | } | 352 | } |
291 | } | 353 | } |
292 | } | 354 | } |
355 | ``` | ||
293 | 356 | ||
294 | // AFTER | 357 | .After |
358 | ```rust | ||
295 | impl<'a> Cursor<'a> { | 359 | impl<'a> Cursor<'a> { |
296 | fn node(self) -> &SyntaxNode { | 360 | fn node(self) -> &SyntaxNode { |
297 | match self { | 361 | match self { |
@@ -301,44 +365,59 @@ impl<'a> Cursor<'a> { | |||
301 | } | 365 | } |
302 | ``` | 366 | ``` |
303 | 367 | ||
304 | ## `change_return_type_to_result` | 368 | |
369 | [discrete] | ||
370 | === `change_return_type_to_result` | ||
371 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/change_return_type_to_result.rs#L8[change_return_type_to_result.rs] | ||
305 | 372 | ||
306 | Change the function's return type to Result. | 373 | Change the function's return type to Result. |
307 | 374 | ||
375 | .Before | ||
308 | ```rust | 376 | ```rust |
309 | // BEFORE | ||
310 | fn foo() -> i32┃ { 42i32 } | 377 | fn foo() -> i32┃ { 42i32 } |
378 | ``` | ||
311 | 379 | ||
312 | // AFTER | 380 | .After |
381 | ```rust | ||
313 | fn foo() -> Result<i32, ${0:_}> { Ok(42i32) } | 382 | fn foo() -> Result<i32, ${0:_}> { Ok(42i32) } |
314 | ``` | 383 | ``` |
315 | 384 | ||
316 | ## `change_visibility` | 385 | |
386 | [discrete] | ||
387 | === `change_visibility` | ||
388 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/change_visibility.rs#L14[change_visibility.rs] | ||
317 | 389 | ||
318 | Adds or changes existing visibility specifier. | 390 | Adds or changes existing visibility specifier. |
319 | 391 | ||
392 | .Before | ||
320 | ```rust | 393 | ```rust |
321 | // BEFORE | ||
322 | ┃fn frobnicate() {} | 394 | ┃fn frobnicate() {} |
395 | ``` | ||
323 | 396 | ||
324 | // AFTER | 397 | .After |
398 | ```rust | ||
325 | pub(crate) fn frobnicate() {} | 399 | pub(crate) fn frobnicate() {} |
326 | ``` | 400 | ``` |
327 | 401 | ||
328 | ## `convert_to_guarded_return` | 402 | |
403 | [discrete] | ||
404 | === `convert_to_guarded_return` | ||
405 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/early_return.rs#L21[early_return.rs] | ||
329 | 406 | ||
330 | Replace a large conditional with a guarded return. | 407 | Replace a large conditional with a guarded return. |
331 | 408 | ||
409 | .Before | ||
332 | ```rust | 410 | ```rust |
333 | // BEFORE | ||
334 | fn main() { | 411 | fn main() { |
335 | ┃if cond { | 412 | ┃if cond { |
336 | foo(); | 413 | foo(); |
337 | bar(); | 414 | bar(); |
338 | } | 415 | } |
339 | } | 416 | } |
417 | ``` | ||
340 | 418 | ||
341 | // AFTER | 419 | .After |
420 | ```rust | ||
342 | fn main() { | 421 | fn main() { |
343 | if !cond { | 422 | if !cond { |
344 | return; | 423 | return; |
@@ -348,12 +427,15 @@ fn main() { | |||
348 | } | 427 | } |
349 | ``` | 428 | ``` |
350 | 429 | ||
351 | ## `fill_match_arms` | 430 | |
431 | [discrete] | ||
432 | === `fill_match_arms` | ||
433 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/fill_match_arms.rs#L14[fill_match_arms.rs] | ||
352 | 434 | ||
353 | Adds missing clauses to a `match` expression. | 435 | Adds missing clauses to a `match` expression. |
354 | 436 | ||
437 | .Before | ||
355 | ```rust | 438 | ```rust |
356 | // BEFORE | ||
357 | enum Action { Move { distance: u32 }, Stop } | 439 | enum Action { Move { distance: u32 }, Stop } |
358 | 440 | ||
359 | fn handle(action: Action) { | 441 | fn handle(action: Action) { |
@@ -361,8 +443,10 @@ fn handle(action: Action) { | |||
361 | ┃ | 443 | ┃ |
362 | } | 444 | } |
363 | } | 445 | } |
446 | ``` | ||
364 | 447 | ||
365 | // AFTER | 448 | .After |
449 | ```rust | ||
366 | enum Action { Move { distance: u32 }, Stop } | 450 | enum Action { Move { distance: u32 }, Stop } |
367 | 451 | ||
368 | fn handle(action: Action) { | 452 | fn handle(action: Action) { |
@@ -373,20 +457,25 @@ fn handle(action: Action) { | |||
373 | } | 457 | } |
374 | ``` | 458 | ``` |
375 | 459 | ||
376 | ## `fix_visibility` | 460 | |
461 | [discrete] | ||
462 | === `fix_visibility` | ||
463 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/fix_visibility.rs#L13[fix_visibility.rs] | ||
377 | 464 | ||
378 | Makes inaccessible item public. | 465 | Makes inaccessible item public. |
379 | 466 | ||
467 | .Before | ||
380 | ```rust | 468 | ```rust |
381 | // BEFORE | ||
382 | mod m { | 469 | mod m { |
383 | fn frobnicate() {} | 470 | fn frobnicate() {} |
384 | } | 471 | } |
385 | fn main() { | 472 | fn main() { |
386 | m::frobnicate┃() {} | 473 | m::frobnicate┃() {} |
387 | } | 474 | } |
475 | ``` | ||
388 | 476 | ||
389 | // AFTER | 477 | .After |
478 | ```rust | ||
390 | mod m { | 479 | mod m { |
391 | $0pub(crate) fn frobnicate() {} | 480 | $0pub(crate) fn frobnicate() {} |
392 | } | 481 | } |
@@ -395,154 +484,202 @@ fn main() { | |||
395 | } | 484 | } |
396 | ``` | 485 | ``` |
397 | 486 | ||
398 | ## `flip_binexpr` | 487 | |
488 | [discrete] | ||
489 | === `flip_binexpr` | ||
490 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/flip_binexpr.rs#L5[flip_binexpr.rs] | ||
399 | 491 | ||
400 | Flips operands of a binary expression. | 492 | Flips operands of a binary expression. |
401 | 493 | ||
494 | .Before | ||
402 | ```rust | 495 | ```rust |
403 | // BEFORE | ||
404 | fn main() { | 496 | fn main() { |
405 | let _ = 90 +┃ 2; | 497 | let _ = 90 +┃ 2; |
406 | } | 498 | } |
499 | ``` | ||
407 | 500 | ||
408 | // AFTER | 501 | .After |
502 | ```rust | ||
409 | fn main() { | 503 | fn main() { |
410 | let _ = 2 + 90; | 504 | let _ = 2 + 90; |
411 | } | 505 | } |
412 | ``` | 506 | ``` |
413 | 507 | ||
414 | ## `flip_comma` | 508 | |
509 | [discrete] | ||
510 | === `flip_comma` | ||
511 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/flip_comma.rs#L5[flip_comma.rs] | ||
415 | 512 | ||
416 | Flips two comma-separated items. | 513 | Flips two comma-separated items. |
417 | 514 | ||
515 | .Before | ||
418 | ```rust | 516 | ```rust |
419 | // BEFORE | ||
420 | fn main() { | 517 | fn main() { |
421 | ((1, 2),┃ (3, 4)); | 518 | ((1, 2),┃ (3, 4)); |
422 | } | 519 | } |
520 | ``` | ||
423 | 521 | ||
424 | // AFTER | 522 | .After |
523 | ```rust | ||
425 | fn main() { | 524 | fn main() { |
426 | ((3, 4), (1, 2)); | 525 | ((3, 4), (1, 2)); |
427 | } | 526 | } |
428 | ``` | 527 | ``` |
429 | 528 | ||
430 | ## `flip_trait_bound` | 529 | |
530 | [discrete] | ||
531 | === `flip_trait_bound` | ||
532 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/flip_trait_bound.rs#L9[flip_trait_bound.rs] | ||
431 | 533 | ||
432 | Flips two trait bounds. | 534 | Flips two trait bounds. |
433 | 535 | ||
536 | .Before | ||
434 | ```rust | 537 | ```rust |
435 | // BEFORE | ||
436 | fn foo<T: Clone +┃ Copy>() { } | 538 | fn foo<T: Clone +┃ Copy>() { } |
539 | ``` | ||
437 | 540 | ||
438 | // AFTER | 541 | .After |
542 | ```rust | ||
439 | fn foo<T: Copy + Clone>() { } | 543 | fn foo<T: Copy + Clone>() { } |
440 | ``` | 544 | ``` |
441 | 545 | ||
442 | ## `inline_local_variable` | 546 | |
547 | [discrete] | ||
548 | === `inline_local_variable` | ||
549 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/inline_local_variable.rs#L13[inline_local_variable.rs] | ||
443 | 550 | ||
444 | Inlines local variable. | 551 | Inlines local variable. |
445 | 552 | ||
553 | .Before | ||
446 | ```rust | 554 | ```rust |
447 | // BEFORE | ||
448 | fn main() { | 555 | fn main() { |
449 | let x┃ = 1 + 2; | 556 | let x┃ = 1 + 2; |
450 | x * 4; | 557 | x * 4; |
451 | } | 558 | } |
559 | ``` | ||
452 | 560 | ||
453 | // AFTER | 561 | .After |
562 | ```rust | ||
454 | fn main() { | 563 | fn main() { |
455 | (1 + 2) * 4; | 564 | (1 + 2) * 4; |
456 | } | 565 | } |
457 | ``` | 566 | ``` |
458 | 567 | ||
459 | ## `introduce_variable` | 568 | |
569 | [discrete] | ||
570 | === `introduce_variable` | ||
571 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/introduce_variable.rs#L14[introduce_variable.rs] | ||
460 | 572 | ||
461 | Extracts subexpression into a variable. | 573 | Extracts subexpression into a variable. |
462 | 574 | ||
575 | .Before | ||
463 | ```rust | 576 | ```rust |
464 | // BEFORE | ||
465 | fn main() { | 577 | fn main() { |
466 | ┃(1 + 2)┃ * 4; | 578 | ┃(1 + 2)┃ * 4; |
467 | } | 579 | } |
580 | ``` | ||
468 | 581 | ||
469 | // AFTER | 582 | .After |
583 | ```rust | ||
470 | fn main() { | 584 | fn main() { |
471 | let $0var_name = (1 + 2); | 585 | let $0var_name = (1 + 2); |
472 | var_name * 4; | 586 | var_name * 4; |
473 | } | 587 | } |
474 | ``` | 588 | ``` |
475 | 589 | ||
476 | ## `invert_if` | 590 | |
591 | [discrete] | ||
592 | === `invert_if` | ||
593 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/invert_if.rs#L12[invert_if.rs] | ||
477 | 594 | ||
478 | Apply invert_if | 595 | Apply invert_if |
479 | This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` | 596 | This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}` |
480 | This also works with `!=`. This assist can only be applied with the cursor | 597 | This also works with `!=`. This assist can only be applied with the cursor |
481 | on `if`. | 598 | on `if`. |
482 | 599 | ||
600 | .Before | ||
483 | ```rust | 601 | ```rust |
484 | // BEFORE | ||
485 | fn main() { | 602 | fn main() { |
486 | if┃ !y { A } else { B } | 603 | if┃ !y { A } else { B } |
487 | } | 604 | } |
605 | ``` | ||
488 | 606 | ||
489 | // AFTER | 607 | .After |
608 | ```rust | ||
490 | fn main() { | 609 | fn main() { |
491 | if y { B } else { A } | 610 | if y { B } else { A } |
492 | } | 611 | } |
493 | ``` | 612 | ``` |
494 | 613 | ||
495 | ## `make_raw_string` | 614 | |
615 | [discrete] | ||
616 | === `make_raw_string` | ||
617 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/raw_string.rs#L10[raw_string.rs] | ||
496 | 618 | ||
497 | Adds `r#` to a plain string literal. | 619 | Adds `r#` to a plain string literal. |
498 | 620 | ||
621 | .Before | ||
499 | ```rust | 622 | ```rust |
500 | // BEFORE | ||
501 | fn main() { | 623 | fn main() { |
502 | "Hello,┃ World!"; | 624 | "Hello,┃ World!"; |
503 | } | 625 | } |
626 | ``` | ||
504 | 627 | ||
505 | // AFTER | 628 | .After |
629 | ```rust | ||
506 | fn main() { | 630 | fn main() { |
507 | r#"Hello, World!"#; | 631 | r#"Hello, World!"#; |
508 | } | 632 | } |
509 | ``` | 633 | ``` |
510 | 634 | ||
511 | ## `make_usual_string` | 635 | |
636 | [discrete] | ||
637 | === `make_usual_string` | ||
638 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/raw_string.rs#L39[raw_string.rs] | ||
512 | 639 | ||
513 | Turns a raw string into a plain string. | 640 | Turns a raw string into a plain string. |
514 | 641 | ||
642 | .Before | ||
515 | ```rust | 643 | ```rust |
516 | // BEFORE | ||
517 | fn main() { | 644 | fn main() { |
518 | r#"Hello,┃ "World!""#; | 645 | r#"Hello,┃ "World!""#; |
519 | } | 646 | } |
647 | ``` | ||
520 | 648 | ||
521 | // AFTER | 649 | .After |
650 | ```rust | ||
522 | fn main() { | 651 | fn main() { |
523 | "Hello, \"World!\""; | 652 | "Hello, \"World!\""; |
524 | } | 653 | } |
525 | ``` | 654 | ``` |
526 | 655 | ||
527 | ## `merge_imports` | 656 | |
657 | [discrete] | ||
658 | === `merge_imports` | ||
659 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/merge_imports.rs#L14[merge_imports.rs] | ||
528 | 660 | ||
529 | Merges two imports with a common prefix. | 661 | Merges two imports with a common prefix. |
530 | 662 | ||
663 | .Before | ||
531 | ```rust | 664 | ```rust |
532 | // BEFORE | ||
533 | use std::┃fmt::Formatter; | 665 | use std::┃fmt::Formatter; |
534 | use std::io; | 666 | use std::io; |
667 | ``` | ||
535 | 668 | ||
536 | // AFTER | 669 | .After |
670 | ```rust | ||
537 | use std::{fmt::Formatter, io}; | 671 | use std::{fmt::Formatter, io}; |
538 | ``` | 672 | ``` |
539 | 673 | ||
540 | ## `merge_match_arms` | 674 | |
675 | [discrete] | ||
676 | === `merge_match_arms` | ||
677 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/merge_match_arms.rs#L11[merge_match_arms.rs] | ||
541 | 678 | ||
542 | Merges identical match arms. | 679 | Merges identical match arms. |
543 | 680 | ||
681 | .Before | ||
544 | ```rust | 682 | ```rust |
545 | // BEFORE | ||
546 | enum Action { Move { distance: u32 }, Stop } | 683 | enum Action { Move { distance: u32 }, Stop } |
547 | 684 | ||
548 | fn handle(action: Action) { | 685 | fn handle(action: Action) { |
@@ -551,8 +688,10 @@ fn handle(action: Action) { | |||
551 | Action::Stop => foo(), | 688 | Action::Stop => foo(), |
552 | } | 689 | } |
553 | } | 690 | } |
691 | ``` | ||
554 | 692 | ||
555 | // AFTER | 693 | .After |
694 | ```rust | ||
556 | enum Action { Move { distance: u32 }, Stop } | 695 | enum Action { Move { distance: u32 }, Stop } |
557 | 696 | ||
558 | fn handle(action: Action) { | 697 | fn handle(action: Action) { |
@@ -562,12 +701,15 @@ fn handle(action: Action) { | |||
562 | } | 701 | } |
563 | ``` | 702 | ``` |
564 | 703 | ||
565 | ## `move_arm_cond_to_match_guard` | 704 | |
705 | [discrete] | ||
706 | === `move_arm_cond_to_match_guard` | ||
707 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/move_guard.rs#L56[move_guard.rs] | ||
566 | 708 | ||
567 | Moves if expression from match arm body into a guard. | 709 | Moves if expression from match arm body into a guard. |
568 | 710 | ||
711 | .Before | ||
569 | ```rust | 712 | ```rust |
570 | // BEFORE | ||
571 | enum Action { Move { distance: u32 }, Stop } | 713 | enum Action { Move { distance: u32 }, Stop } |
572 | 714 | ||
573 | fn handle(action: Action) { | 715 | fn handle(action: Action) { |
@@ -576,8 +718,10 @@ fn handle(action: Action) { | |||
576 | _ => (), | 718 | _ => (), |
577 | } | 719 | } |
578 | } | 720 | } |
721 | ``` | ||
579 | 722 | ||
580 | // AFTER | 723 | .After |
724 | ```rust | ||
581 | enum Action { Move { distance: u32 }, Stop } | 725 | enum Action { Move { distance: u32 }, Stop } |
582 | 726 | ||
583 | fn handle(action: Action) { | 727 | fn handle(action: Action) { |
@@ -588,28 +732,36 @@ fn handle(action: Action) { | |||
588 | } | 732 | } |
589 | ``` | 733 | ``` |
590 | 734 | ||
591 | ## `move_bounds_to_where_clause` | 735 | |
736 | [discrete] | ||
737 | === `move_bounds_to_where_clause` | ||
738 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/move_bounds.rs#L10[move_bounds.rs] | ||
592 | 739 | ||
593 | Moves inline type bounds to a where clause. | 740 | Moves inline type bounds to a where clause. |
594 | 741 | ||
742 | .Before | ||
595 | ```rust | 743 | ```rust |
596 | // BEFORE | ||
597 | fn apply<T, U, ┃F: FnOnce(T) -> U>(f: F, x: T) -> U { | 744 | fn apply<T, U, ┃F: FnOnce(T) -> U>(f: F, x: T) -> U { |
598 | f(x) | 745 | f(x) |
599 | } | 746 | } |
747 | ``` | ||
600 | 748 | ||
601 | // AFTER | 749 | .After |
750 | ```rust | ||
602 | fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U { | 751 | fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U { |
603 | f(x) | 752 | f(x) |
604 | } | 753 | } |
605 | ``` | 754 | ``` |
606 | 755 | ||
607 | ## `move_guard_to_arm_body` | 756 | |
757 | [discrete] | ||
758 | === `move_guard_to_arm_body` | ||
759 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/move_guard.rs#L8[move_guard.rs] | ||
608 | 760 | ||
609 | Moves match guard into match arm body. | 761 | Moves match guard into match arm body. |
610 | 762 | ||
763 | .Before | ||
611 | ```rust | 764 | ```rust |
612 | // BEFORE | ||
613 | enum Action { Move { distance: u32 }, Stop } | 765 | enum Action { Move { distance: u32 }, Stop } |
614 | 766 | ||
615 | fn handle(action: Action) { | 767 | fn handle(action: Action) { |
@@ -618,8 +770,10 @@ fn handle(action: Action) { | |||
618 | _ => (), | 770 | _ => (), |
619 | } | 771 | } |
620 | } | 772 | } |
773 | ``` | ||
621 | 774 | ||
622 | // AFTER | 775 | .After |
776 | ```rust | ||
623 | enum Action { Move { distance: u32 }, Stop } | 777 | enum Action { Move { distance: u32 }, Stop } |
624 | 778 | ||
625 | fn handle(action: Action) { | 779 | fn handle(action: Action) { |
@@ -630,75 +784,98 @@ fn handle(action: Action) { | |||
630 | } | 784 | } |
631 | ``` | 785 | ``` |
632 | 786 | ||
633 | ## `remove_dbg` | 787 | |
788 | [discrete] | ||
789 | === `remove_dbg` | ||
790 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/remove_dbg.rs#L8[remove_dbg.rs] | ||
634 | 791 | ||
635 | Removes `dbg!()` macro call. | 792 | Removes `dbg!()` macro call. |
636 | 793 | ||
794 | .Before | ||
637 | ```rust | 795 | ```rust |
638 | // BEFORE | ||
639 | fn main() { | 796 | fn main() { |
640 | ┃dbg!(92); | 797 | ┃dbg!(92); |
641 | } | 798 | } |
799 | ``` | ||
642 | 800 | ||
643 | // AFTER | 801 | .After |
802 | ```rust | ||
644 | fn main() { | 803 | fn main() { |
645 | 92; | 804 | 92; |
646 | } | 805 | } |
647 | ``` | 806 | ``` |
648 | 807 | ||
649 | ## `remove_hash` | 808 | |
809 | [discrete] | ||
810 | === `remove_hash` | ||
811 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/raw_string.rs#L89[raw_string.rs] | ||
650 | 812 | ||
651 | Removes a hash from a raw string literal. | 813 | Removes a hash from a raw string literal. |
652 | 814 | ||
815 | .Before | ||
653 | ```rust | 816 | ```rust |
654 | // BEFORE | ||
655 | fn main() { | 817 | fn main() { |
656 | r#"Hello,┃ World!"#; | 818 | r#"Hello,┃ World!"#; |
657 | } | 819 | } |
820 | ``` | ||
658 | 821 | ||
659 | // AFTER | 822 | .After |
823 | ```rust | ||
660 | fn main() { | 824 | fn main() { |
661 | r"Hello, World!"; | 825 | r"Hello, World!"; |
662 | } | 826 | } |
663 | ``` | 827 | ``` |
664 | 828 | ||
665 | ## `remove_mut` | 829 | |
830 | [discrete] | ||
831 | === `remove_mut` | ||
832 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/remove_mut.rs#L5[remove_mut.rs] | ||
666 | 833 | ||
667 | Removes the `mut` keyword. | 834 | Removes the `mut` keyword. |
668 | 835 | ||
836 | .Before | ||
669 | ```rust | 837 | ```rust |
670 | // BEFORE | ||
671 | impl Walrus { | 838 | impl Walrus { |
672 | fn feed(&mut┃ self, amount: u32) {} | 839 | fn feed(&mut┃ self, amount: u32) {} |
673 | } | 840 | } |
841 | ``` | ||
674 | 842 | ||
675 | // AFTER | 843 | .After |
844 | ```rust | ||
676 | impl Walrus { | 845 | impl Walrus { |
677 | fn feed(&self, amount: u32) {} | 846 | fn feed(&self, amount: u32) {} |
678 | } | 847 | } |
679 | ``` | 848 | ``` |
680 | 849 | ||
681 | ## `reorder_fields` | 850 | |
851 | [discrete] | ||
852 | === `reorder_fields` | ||
853 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/reorder_fields.rs#L10[reorder_fields.rs] | ||
682 | 854 | ||
683 | Reorder the fields of record literals and record patterns in the same order as in | 855 | Reorder the fields of record literals and record patterns in the same order as in |
684 | the definition. | 856 | the definition. |
685 | 857 | ||
858 | .Before | ||
686 | ```rust | 859 | ```rust |
687 | // BEFORE | ||
688 | struct Foo {foo: i32, bar: i32}; | 860 | struct Foo {foo: i32, bar: i32}; |
689 | const test: Foo = ┃Foo {bar: 0, foo: 1} | 861 | const test: Foo = ┃Foo {bar: 0, foo: 1} |
862 | ``` | ||
690 | 863 | ||
691 | // AFTER | 864 | .After |
865 | ```rust | ||
692 | struct Foo {foo: i32, bar: i32}; | 866 | struct Foo {foo: i32, bar: i32}; |
693 | const test: Foo = Foo {foo: 1, bar: 0} | 867 | const test: Foo = Foo {foo: 1, bar: 0} |
694 | ``` | 868 | ``` |
695 | 869 | ||
696 | ## `replace_if_let_with_match` | 870 | |
871 | [discrete] | ||
872 | === `replace_if_let_with_match` | ||
873 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/replace_if_let_with_match.rs#L13[replace_if_let_with_match.rs] | ||
697 | 874 | ||
698 | Replaces `if let` with an else branch with a `match` expression. | 875 | Replaces `if let` with an else branch with a `match` expression. |
699 | 876 | ||
877 | .Before | ||
700 | ```rust | 878 | ```rust |
701 | // BEFORE | ||
702 | enum Action { Move { distance: u32 }, Stop } | 879 | enum Action { Move { distance: u32 }, Stop } |
703 | 880 | ||
704 | fn handle(action: Action) { | 881 | fn handle(action: Action) { |
@@ -708,8 +885,10 @@ fn handle(action: Action) { | |||
708 | bar() | 885 | bar() |
709 | } | 886 | } |
710 | } | 887 | } |
888 | ``` | ||
711 | 889 | ||
712 | // AFTER | 890 | .After |
891 | ```rust | ||
713 | enum Action { Move { distance: u32 }, Stop } | 892 | enum Action { Move { distance: u32 }, Stop } |
714 | 893 | ||
715 | fn handle(action: Action) { | 894 | fn handle(action: Action) { |
@@ -720,20 +899,25 @@ fn handle(action: Action) { | |||
720 | } | 899 | } |
721 | ``` | 900 | ``` |
722 | 901 | ||
723 | ## `replace_let_with_if_let` | 902 | |
903 | [discrete] | ||
904 | === `replace_let_with_if_let` | ||
905 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/replace_let_with_if_let.rs#L14[replace_let_with_if_let.rs] | ||
724 | 906 | ||
725 | Replaces `let` with an `if-let`. | 907 | Replaces `let` with an `if-let`. |
726 | 908 | ||
909 | .Before | ||
727 | ```rust | 910 | ```rust |
728 | // BEFORE | ||
729 | 911 | ||
730 | fn main(action: Action) { | 912 | fn main(action: Action) { |
731 | ┃let x = compute(); | 913 | ┃let x = compute(); |
732 | } | 914 | } |
733 | 915 | ||
734 | fn compute() -> Option<i32> { None } | 916 | fn compute() -> Option<i32> { None } |
917 | ``` | ||
735 | 918 | ||
736 | // AFTER | 919 | .After |
920 | ```rust | ||
737 | 921 | ||
738 | fn main(action: Action) { | 922 | fn main(action: Action) { |
739 | if let Some(x) = compute() { | 923 | if let Some(x) = compute() { |
@@ -743,33 +927,43 @@ fn main(action: Action) { | |||
743 | fn compute() -> Option<i32> { None } | 927 | fn compute() -> Option<i32> { None } |
744 | ``` | 928 | ``` |
745 | 929 | ||
746 | ## `replace_qualified_name_with_use` | 930 | |
931 | [discrete] | ||
932 | === `replace_qualified_name_with_use` | ||
933 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/replace_qualified_name_with_use.rs#L6[replace_qualified_name_with_use.rs] | ||
747 | 934 | ||
748 | Adds a use statement for a given fully-qualified name. | 935 | Adds a use statement for a given fully-qualified name. |
749 | 936 | ||
937 | .Before | ||
750 | ```rust | 938 | ```rust |
751 | // BEFORE | ||
752 | fn process(map: std::collections::┃HashMap<String, String>) {} | 939 | fn process(map: std::collections::┃HashMap<String, String>) {} |
940 | ``` | ||
753 | 941 | ||
754 | // AFTER | 942 | .After |
943 | ```rust | ||
755 | use std::collections::HashMap; | 944 | use std::collections::HashMap; |
756 | 945 | ||
757 | fn process(map: HashMap<String, String>) {} | 946 | fn process(map: HashMap<String, String>) {} |
758 | ``` | 947 | ``` |
759 | 948 | ||
760 | ## `replace_unwrap_with_match` | 949 | |
950 | [discrete] | ||
951 | === `replace_unwrap_with_match` | ||
952 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/replace_unwrap_with_match.rs#L17[replace_unwrap_with_match.rs] | ||
761 | 953 | ||
762 | Replaces `unwrap` a `match` expression. Works for Result and Option. | 954 | Replaces `unwrap` a `match` expression. Works for Result and Option. |
763 | 955 | ||
956 | .Before | ||
764 | ```rust | 957 | ```rust |
765 | // BEFORE | ||
766 | enum Result<T, E> { Ok(T), Err(E) } | 958 | enum Result<T, E> { Ok(T), Err(E) } |
767 | fn main() { | 959 | fn main() { |
768 | let x: Result<i32, i32> = Result::Ok(92); | 960 | let x: Result<i32, i32> = Result::Ok(92); |
769 | let y = x.┃unwrap(); | 961 | let y = x.┃unwrap(); |
770 | } | 962 | } |
963 | ``` | ||
771 | 964 | ||
772 | // AFTER | 965 | .After |
966 | ```rust | ||
773 | enum Result<T, E> { Ok(T), Err(E) } | 967 | enum Result<T, E> { Ok(T), Err(E) } |
774 | fn main() { | 968 | fn main() { |
775 | let x: Result<i32, i32> = Result::Ok(92); | 969 | let x: Result<i32, i32> = Result::Ok(92); |
@@ -780,31 +974,41 @@ fn main() { | |||
780 | } | 974 | } |
781 | ``` | 975 | ``` |
782 | 976 | ||
783 | ## `split_import` | 977 | |
978 | [discrete] | ||
979 | === `split_import` | ||
980 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/split_import.rs#L7[split_import.rs] | ||
784 | 981 | ||
785 | Wraps the tail of import into braces. | 982 | Wraps the tail of import into braces. |
786 | 983 | ||
984 | .Before | ||
787 | ```rust | 985 | ```rust |
788 | // BEFORE | ||
789 | use std::┃collections::HashMap; | 986 | use std::┃collections::HashMap; |
987 | ``` | ||
790 | 988 | ||
791 | // AFTER | 989 | .After |
990 | ```rust | ||
792 | use std::{collections::HashMap}; | 991 | use std::{collections::HashMap}; |
793 | ``` | 992 | ``` |
794 | 993 | ||
795 | ## `unwrap_block` | 994 | |
995 | [discrete] | ||
996 | === `unwrap_block` | ||
997 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_assists/src/handlers/unwrap_block.rs#L9[unwrap_block.rs] | ||
796 | 998 | ||
797 | This assist removes if...else, for, while and loop control statements to just keep the body. | 999 | This assist removes if...else, for, while and loop control statements to just keep the body. |
798 | 1000 | ||
1001 | .Before | ||
799 | ```rust | 1002 | ```rust |
800 | // BEFORE | ||
801 | fn foo() { | 1003 | fn foo() { |
802 | if true {┃ | 1004 | if true {┃ |
803 | println!("foo"); | 1005 | println!("foo"); |
804 | } | 1006 | } |
805 | } | 1007 | } |
1008 | ``` | ||
806 | 1009 | ||
807 | // AFTER | 1010 | .After |
1011 | ```rust | ||
808 | fn foo() { | 1012 | fn foo() { |
809 | println!("foo"); | 1013 | println!("foo"); |
810 | } | 1014 | } |
diff --git a/docs/user/generated_features.adoc b/docs/user/generated_features.adoc index 803073d55..12812fa0b 100644 --- a/docs/user/generated_features.adoc +++ b/docs/user/generated_features.adoc | |||
@@ -1,5 +1,5 @@ | |||
1 | === Expand Macro Recursively | 1 | === Expand Macro Recursively |
2 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/expand_macro.rs[expand_macro.rs] | 2 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/expand_macro.rs#L15[expand_macro.rs] |
3 | 3 | ||
4 | Shows the full macro expansion of the macro at current cursor. | 4 | Shows the full macro expansion of the macro at current cursor. |
5 | 5 | ||
@@ -11,7 +11,7 @@ Shows the full macro expansion of the macro at current cursor. | |||
11 | 11 | ||
12 | 12 | ||
13 | === Extend Selection | 13 | === Extend Selection |
14 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/extend_selection.rs[extend_selection.rs] | 14 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/extend_selection.rs#L15[extend_selection.rs] |
15 | 15 | ||
16 | Extends the current selection to the encompassing syntactic construct | 16 | Extends the current selection to the encompassing syntactic construct |
17 | (expression, statement, item, module, etc). It works with multiple cursors. | 17 | (expression, statement, item, module, etc). It works with multiple cursors. |
@@ -24,7 +24,7 @@ Extends the current selection to the encompassing syntactic construct | |||
24 | 24 | ||
25 | 25 | ||
26 | === File Structure | 26 | === File Structure |
27 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/display/structure.rs[structure.rs] | 27 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/display/structure.rs#L17[structure.rs] |
28 | 28 | ||
29 | Provides a tree of the symbols defined in the file. Can be used to | 29 | Provides a tree of the symbols defined in the file. Can be used to |
30 | 30 | ||
@@ -40,7 +40,7 @@ Provides a tree of the symbols defined in the file. Can be used to | |||
40 | 40 | ||
41 | 41 | ||
42 | === Go to Definition | 42 | === Go to Definition |
43 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_definition.rs[goto_definition.rs] | 43 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_definition.rs#L18[goto_definition.rs] |
44 | 44 | ||
45 | Navigates to the definition of an identifier. | 45 | Navigates to the definition of an identifier. |
46 | 46 | ||
@@ -52,7 +52,7 @@ Navigates to the definition of an identifier. | |||
52 | 52 | ||
53 | 53 | ||
54 | === Go to Implementation | 54 | === Go to Implementation |
55 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_implementation.rs[goto_implementation.rs] | 55 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_implementation.rs#L7[goto_implementation.rs] |
56 | 56 | ||
57 | Navigates to the impl block of structs, enums or traits. Also implemented as a code lens. | 57 | Navigates to the impl block of structs, enums or traits. Also implemented as a code lens. |
58 | 58 | ||
@@ -64,7 +64,7 @@ Navigates to the impl block of structs, enums or traits. Also implemented as a c | |||
64 | 64 | ||
65 | 65 | ||
66 | === Go to Type Definition | 66 | === Go to Type Definition |
67 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_type_definition.rs[goto_type_definition.rs] | 67 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/goto_type_definition.rs#L6[goto_type_definition.rs] |
68 | 68 | ||
69 | Navigates to the type of an identifier. | 69 | Navigates to the type of an identifier. |
70 | 70 | ||
@@ -76,14 +76,14 @@ Navigates to the type of an identifier. | |||
76 | 76 | ||
77 | 77 | ||
78 | === Hover | 78 | === Hover |
79 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/hover.rs[hover.rs] | 79 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/hover.rs#L63[hover.rs] |
80 | 80 | ||
81 | Shows additional information, like type of an expression or documentation for definition when "focusing" code. | 81 | Shows additional information, like type of an expression or documentation for definition when "focusing" code. |
82 | Focusing is usually hovering with a mouse, but can also be triggered with a shortcut. | 82 | Focusing is usually hovering with a mouse, but can also be triggered with a shortcut. |
83 | 83 | ||
84 | 84 | ||
85 | === Inlay Hints | 85 | === Inlay Hints |
86 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/inlay_hints.rs[inlay_hints.rs] | 86 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/inlay_hints.rs#L40[inlay_hints.rs] |
87 | 87 | ||
88 | rust-analyzer shows additional information inline with the source code. | 88 | rust-analyzer shows additional information inline with the source code. |
89 | Editors usually render this using read-only virtual text snippets interspersed with code. | 89 | Editors usually render this using read-only virtual text snippets interspersed with code. |
@@ -106,7 +106,7 @@ https://github.com/rust-analyzer/rust-analyzer/issues/1623[1], https://github.co | |||
106 | 106 | ||
107 | 107 | ||
108 | === Join Lines | 108 | === Join Lines |
109 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/join_lines.rs[join_lines.rs] | 109 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/join_lines.rs#L12[join_lines.rs] |
110 | 110 | ||
111 | Join selected lines into one, smartly fixing up whitespace, trailing commas, and braces. | 111 | Join selected lines into one, smartly fixing up whitespace, trailing commas, and braces. |
112 | 112 | ||
@@ -118,7 +118,7 @@ Join selected lines into one, smartly fixing up whitespace, trailing commas, and | |||
118 | 118 | ||
119 | 119 | ||
120 | === Magic Completions | 120 | === Magic Completions |
121 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/completion.rs[completion.rs] | 121 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/completion.rs#L38[completion.rs] |
122 | 122 | ||
123 | In addition to usual reference completion, rust-analyzer provides some ✨magic✨ | 123 | In addition to usual reference completion, rust-analyzer provides some ✨magic✨ |
124 | completions as well: | 124 | completions as well: |
@@ -163,7 +163,7 @@ mod tests { | |||
163 | 163 | ||
164 | 164 | ||
165 | === Matching Brace | 165 | === Matching Brace |
166 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/matching_brace.rs[matching_brace.rs] | 166 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/matching_brace.rs#L3[matching_brace.rs] |
167 | 167 | ||
168 | If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair, | 168 | If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair, |
169 | moves cursor to the matching brace. It uses the actual parser to determine | 169 | moves cursor to the matching brace. It uses the actual parser to determine |
@@ -177,7 +177,7 @@ braces, so it won't confuse generics with comparisons. | |||
177 | 177 | ||
178 | 178 | ||
179 | === On Typing Assists | 179 | === On Typing Assists |
180 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/typing.rs[typing.rs] | 180 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/typing.rs#L35[typing.rs] |
181 | 181 | ||
182 | Some features trigger on typing certain characters: | 182 | Some features trigger on typing certain characters: |
183 | 183 | ||
@@ -187,7 +187,7 @@ Some features trigger on typing certain characters: | |||
187 | 187 | ||
188 | 188 | ||
189 | === Parent Module | 189 | === Parent Module |
190 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/parent_module.rs[parent_module.rs] | 190 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/parent_module.rs#L12[parent_module.rs] |
191 | 191 | ||
192 | Navigates to the parent module of the current module. | 192 | Navigates to the parent module of the current module. |
193 | 193 | ||
@@ -199,7 +199,7 @@ Navigates to the parent module of the current module. | |||
199 | 199 | ||
200 | 200 | ||
201 | === Run | 201 | === Run |
202 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/runnables.rs[runnables.rs] | 202 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/runnables.rs#L45[runnables.rs] |
203 | 203 | ||
204 | Shows a popup suggesting to run a test/benchmark/binary **at the current cursor | 204 | Shows a popup suggesting to run a test/benchmark/binary **at the current cursor |
205 | location**. Super useful for repeatedly running just a single test. Do bind this | 205 | location**. Super useful for repeatedly running just a single test. Do bind this |
@@ -213,7 +213,7 @@ to a shortcut! | |||
213 | 213 | ||
214 | 214 | ||
215 | === Semantic Syntax Highlighting | 215 | === Semantic Syntax Highlighting |
216 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/syntax_highlighting.rs[syntax_highlighting.rs] | 216 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/syntax_highlighting.rs#L33[syntax_highlighting.rs] |
217 | 217 | ||
218 | rust-analyzer highlights the code semantically. | 218 | rust-analyzer highlights the code semantically. |
219 | For example, `bar` in `foo::Bar` might be colored differently depending on whether `Bar` is an enum or a trait. | 219 | For example, `bar` in `foo::Bar` might be colored differently depending on whether `Bar` is an enum or a trait. |
@@ -225,7 +225,7 @@ We also give special modifier for `mut` and `&mut` local variables. | |||
225 | 225 | ||
226 | 226 | ||
227 | === Show Syntax Tree | 227 | === Show Syntax Tree |
228 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/syntax_tree.rs[syntax_tree.rs] | 228 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/syntax_tree.rs#L9[syntax_tree.rs] |
229 | 229 | ||
230 | Shows the parse tree of the current file. It exists mostly for debugging | 230 | Shows the parse tree of the current file. It exists mostly for debugging |
231 | rust-analyzer itself. | 231 | rust-analyzer itself. |
@@ -238,7 +238,7 @@ rust-analyzer itself. | |||
238 | 238 | ||
239 | 239 | ||
240 | === Status | 240 | === Status |
241 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/status.rs[status.rs] | 241 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/status.rs#L27[status.rs] |
242 | 242 | ||
243 | Shows internal statistic about memory usage of rust-analyzer. | 243 | Shows internal statistic about memory usage of rust-analyzer. |
244 | 244 | ||
@@ -250,7 +250,7 @@ Shows internal statistic about memory usage of rust-analyzer. | |||
250 | 250 | ||
251 | 251 | ||
252 | === Structural Seach and Replace | 252 | === Structural Seach and Replace |
253 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/ssr.rs[ssr.rs] | 253 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide/src/ssr.rs#L26[ssr.rs] |
254 | 254 | ||
255 | Search and replace with named wildcards that will match any expression. | 255 | Search and replace with named wildcards that will match any expression. |
256 | The syntax for a structural search replace command is `<search_pattern> ==>> <replace_pattern>`. | 256 | The syntax for a structural search replace command is `<search_pattern> ==>> <replace_pattern>`. |
@@ -275,7 +275,7 @@ String::from((y + 5).foo(z)) | |||
275 | 275 | ||
276 | 276 | ||
277 | === Workspace Symbol | 277 | === Workspace Symbol |
278 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_db/src/symbol_index.rs[symbol_index.rs] | 278 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_ide_db/src/symbol_index.rs#L113[symbol_index.rs] |
279 | 279 | ||
280 | Uses fuzzy-search to find types, modules and functions by name across your | 280 | Uses fuzzy-search to find types, modules and functions by name across your |
281 | project and dependencies. This is **the** most useful feature, which improves code | 281 | project and dependencies. This is **the** most useful feature, which improves code |
diff --git a/docs/user/readme.adoc b/docs/user/manual.adoc index 12def7327..202783fd9 100644 --- a/docs/user/readme.adoc +++ b/docs/user/manual.adoc | |||
@@ -2,12 +2,7 @@ | |||
2 | :toc: preamble | 2 | :toc: preamble |
3 | :sectanchors: | 3 | :sectanchors: |
4 | :page-layout: post | 4 | :page-layout: post |
5 | // https://gist.github.com/dcode/0cfbf2699a1fe9b46ff04c41721dda74#admonitions | 5 | :icons: font |
6 | :tip-caption: :bulb: | ||
7 | :note-caption: :information_source: | ||
8 | :important-caption: :heavy_exclamation_mark: | ||
9 | :caution-caption: :fire: | ||
10 | :warning-caption: :warning: | ||
11 | :source-highlighter: rouge | 6 | :source-highlighter: rouge |
12 | :experimental: | 7 | :experimental: |
13 | 8 | ||
@@ -19,7 +14,7 @@ https://microsoft.github.io/language-server-protocol/[Language Server Protocol] | |||
19 | The LSP allows various code editors, like VS Code, Emacs or Vim, to implement semantic features like completion or goto definition by talking to an external language server process. | 14 | The LSP allows various code editors, like VS Code, Emacs or Vim, to implement semantic features like completion or goto definition by talking to an external language server process. |
20 | 15 | ||
21 | To improve this document, send a pull request against | 16 | To improve this document, send a pull request against |
22 | https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/readme.adoc[this file]. | 17 | https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/manual.adoc[this file]. |
23 | 18 | ||
24 | If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum. | 19 | If you have questions about using rust-analyzer, please ask them in the https://users.rust-lang.org/c/ide/14["`IDEs and Editors`"] topic of Rust users forum. |
25 | 20 | ||
@@ -67,16 +62,6 @@ The server binary is stored in: | |||
67 | 62 | ||
68 | Note that we only support two most recent versions of VS Code. | 63 | Note that we only support two most recent versions of VS Code. |
69 | 64 | ||
70 | ==== Special `when` clause context for keybindings. | ||
71 | You may use `inRustProject` context to configure keybindings for rust projects only. For example: | ||
72 | [source,json] | ||
73 | ---- | ||
74 | { "key": "ctrl+shift+f5", "command": "workbench.action.debug.restart", "when": "inDebugMode && !inRustProject"}, | ||
75 | { "key": "ctrl+shift+f5", "command": "rust-analyzer.debug", "when": "inRustProject"}, | ||
76 | { "key": "ctrl+i", "command": "rust-analyzer.toggleInlayHints", "when": "inRustProject" } | ||
77 | ---- | ||
78 | More about `when` clause contexts https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts[here]. | ||
79 | |||
80 | ==== Updates | 65 | ==== Updates |
81 | 66 | ||
82 | The extension will be updated automatically as new versions become available. It will ask your permission to download the matching language server version binary if needed. | 67 | The extension will be updated automatically as new versions become available. It will ask your permission to download the matching language server version binary if needed. |
@@ -124,10 +109,23 @@ Here are some useful self-diagnostic commands: | |||
124 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. | 109 | * To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel. |
125 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. | 110 | * To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools. |
126 | 111 | ||
112 | ==== Special `when` clause context for keybindings. | ||
113 | You may use `inRustProject` context to configure keybindings for rust projects only. For example: | ||
114 | [source,json] | ||
115 | ---- | ||
116 | { | ||
117 | "key": "ctrl+i", | ||
118 | "command": "rust-analyzer.toggleInlayHints", | ||
119 | "when": "inRustProject" | ||
120 | } | ||
121 | ---- | ||
122 | More about `when` clause contexts https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts[here]. | ||
123 | |||
127 | === rust-analyzer Language Server Binary | 124 | === rust-analyzer Language Server Binary |
128 | 125 | ||
129 | Other editors generally require the `rust-analyzer` binary to be in `$PATH`. | 126 | Other editors generally require the `rust-analyzer` binary to be in `$PATH`. |
130 | You can download the pre-built binary from the https://github.com/rust-analyzer/rust-analyzer/releases[releases] page. Typically, you then need to rename the binary for your platform, e.g. `rust-analyzer-mac` if you're on Mac OS, to `rust-analyzer` and make it executable in addition to moving it into a directory in your `$PATH`. | 127 | You can download the pre-built binary from the https://github.com/rust-analyzer/rust-analyzer/releases[releases] page. |
128 | Typically, you then need to rename the binary for your platform, e.g. `rust-analyzer-mac` if you're on Mac OS, to `rust-analyzer` and make it executable in addition to moving it into a directory in your `$PATH`. | ||
131 | 129 | ||
132 | On Linux to install the `rust-analyzer` binary into `~/.local/bin`, this commands could be used | 130 | On Linux to install the `rust-analyzer` binary into `~/.local/bin`, this commands could be used |
133 | 131 | ||
@@ -147,7 +145,8 @@ $ git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyz | |||
147 | $ cargo xtask install --server | 145 | $ cargo xtask install --server |
148 | ---- | 146 | ---- |
149 | 147 | ||
150 | If your editor can't find the binary even though the binary is on your `$PATH`, the likely explanation is that it doesn't see the same `$PATH` as the shell, see https://github.com/rust-analyzer/rust-analyzer/issues/1811[this issue]. On Unix, running the editor from a shell or changing the `.desktop` file to set the environment should help. | 148 | If your editor can't find the binary even though the binary is on your `$PATH`, the likely explanation is that it doesn't see the same `$PATH` as the shell, see https://github.com/rust-analyzer/rust-analyzer/issues/1811[this issue]. |
149 | On Unix, running the editor from a shell or changing the `.desktop` file to set the environment should help. | ||
151 | 150 | ||
152 | ==== Arch Linux | 151 | ==== Arch Linux |
153 | 152 | ||
@@ -278,5 +277,6 @@ include::./generated_features.adoc[] | |||
278 | 277 | ||
279 | Assists, or code actions, are small local refactorings, available in a particular context. | 278 | Assists, or code actions, are small local refactorings, available in a particular context. |
280 | They are usually triggered by a shortcut or by clicking a light bulb icon in the editor. | 279 | They are usually triggered by a shortcut or by clicking a light bulb icon in the editor. |
280 | Cursor position or selection is signified by `┃` character. | ||
281 | 281 | ||
282 | See [assists.md](./assists.md) for the list of available assists. | 282 | include::./generated_assists.adoc[] |