aboutsummaryrefslogtreecommitdiff
path: root/docs/user/assists.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/user/assists.md')
-rw-r--r--docs/user/assists.md769
1 files changed, 0 insertions, 769 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md
deleted file mode 100644
index 4ad7ea59d..000000000
--- a/docs/user/assists.md
+++ /dev/null
@@ -1,769 +0,0 @@
1# Assists
2
3Cursor position or selection is signified by `┃` character.
4
5
6## `add_custom_impl`
7
8Adds impl block for derived trait.
9
10```rust
11// BEFORE
12#[derive(Deb┃ug, Display)]
13struct S;
14
15// AFTER
16#[derive(Display)]
17struct S;
18
19impl Debug for S {
20 $0
21}
22```
23
24## `add_derive`
25
26Adds a new `#[derive()]` clause to a struct or enum.
27
28```rust
29// BEFORE
30struct Point {
31 x: u32,
32 y: u32,┃
33}
34
35// AFTER
36#[derive($0)]
37struct Point {
38 x: u32,
39 y: u32,
40}
41```
42
43## `add_explicit_type`
44
45Specify type for a let binding.
46
47```rust
48// BEFORE
49fn main() {
50 let x┃ = 92;
51}
52
53// AFTER
54fn main() {
55 let x: i32 = 92;
56}
57```
58
59## `add_function`
60
61Adds a stub function with a signature matching the function under the cursor.
62
63```rust
64// BEFORE
65struct Baz;
66fn baz() -> Baz { Baz }
67fn foo() {
68 bar┃("", baz());
69}
70
71
72// AFTER
73struct Baz;
74fn baz() -> Baz { Baz }
75fn foo() {
76 bar("", baz());
77}
78
79fn bar(arg: &str, baz: Baz) {
80 ${0:todo!()}
81}
82
83```
84
85## `add_hash`
86
87Adds a hash to a raw string literal.
88
89```rust
90// BEFORE
91fn main() {
92 r#"Hello,┃ World!"#;
93}
94
95// AFTER
96fn main() {
97 r##"Hello, World!"##;
98}
99```
100
101## `add_impl`
102
103Adds a new inherent impl for a type.
104
105```rust
106// BEFORE
107struct Ctx<T: Clone> {
108 data: T,┃
109}
110
111// AFTER
112struct Ctx<T: Clone> {
113 data: T,
114}
115
116impl<T: Clone> Ctx<T> {
117 $0
118}
119```
120
121## `add_impl_default_members`
122
123Adds scaffold for overriding default impl members.
124
125```rust
126// BEFORE
127trait Trait {
128 Type X;
129 fn foo(&self);
130 fn bar(&self) {}
131}
132
133impl Trait for () {
134 Type X = ();
135 fn foo(&self) {}┃
136
137}
138
139// AFTER
140trait Trait {
141 Type X;
142 fn foo(&self);
143 fn bar(&self) {}
144}
145
146impl Trait for () {
147 Type X = ();
148 fn foo(&self) {}
149 $0fn bar(&self) {}
150
151}
152```
153
154## `add_impl_missing_members`
155
156Adds scaffold for required impl members.
157
158```rust
159// BEFORE
160trait Trait<T> {
161 Type X;
162 fn foo(&self) -> T;
163 fn bar(&self) {}
164}
165
166impl Trait<u32> for () {┃
167
168}
169
170// AFTER
171trait Trait<T> {
172 Type X;
173 fn foo(&self) -> T;
174 fn bar(&self) {}
175}
176
177impl Trait<u32> for () {
178 fn foo(&self) -> u32 {
179 ${0:todo!()}
180 }
181
182}
183```
184
185## `add_new`
186
187Adds a new inherent impl for a type.
188
189```rust
190// BEFORE
191struct Ctx<T: Clone> {
192 data: T,┃
193}
194
195// AFTER
196struct Ctx<T: Clone> {
197 data: T,
198}
199
200impl<T: Clone> Ctx<T> {
201 fn $0new(data: T) -> Self { Self { data } }
202}
203
204```
205
206## `add_turbo_fish`
207
208Adds `::<_>` to a call of a generic method or function.
209
210```rust
211// BEFORE
212fn make<T>() -> T { todo!() }
213fn main() {
214 let x = make┃();
215}
216
217// AFTER
218fn make<T>() -> T { todo!() }
219fn main() {
220 let x = make::<${0:_}>();
221}
222```
223
224## `apply_demorgan`
225
226Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws).
227This transforms expressions of the form `!l || !r` into `!(l && r)`.
228This also works with `&&`. This assist can only be applied with the cursor
229on either `||` or `&&`, with both operands being a negation of some kind.
230This means something of the form `!x` or `x != y`.
231
232```rust
233// BEFORE
234fn main() {
235 if x != 4 ||┃ !y {}
236}
237
238// AFTER
239fn main() {
240 if !(x == 4 && y) {}
241}
242```
243
244## `auto_import`
245
246If the name is unresolved, provides all possible imports for it.
247
248```rust
249// BEFORE
250fn main() {
251 let map = HashMap┃::new();
252}
253
254// AFTER
255use std::collections::HashMap;
256
257fn main() {
258 let map = HashMap::new();
259}
260```
261
262## `change_return_type_to_result`
263
264Change the function's return type to Result.
265
266```rust
267// BEFORE
268fn foo() -> i32┃ { 42i32 }
269
270// AFTER
271fn foo() -> Result<i32, ${0:_}> { Ok(42i32) }
272```
273
274## `change_visibility`
275
276Adds or changes existing visibility specifier.
277
278```rust
279// BEFORE
280┃fn frobnicate() {}
281
282// AFTER
283pub(crate) fn frobnicate() {}
284```
285
286## `convert_to_guarded_return`
287
288Replace a large conditional with a guarded return.
289
290```rust
291// BEFORE
292fn main() {
293 ┃if cond {
294 foo();
295 bar();
296 }
297}
298
299// AFTER
300fn main() {
301 if !cond {
302 return;
303 }
304 foo();
305 bar();
306}
307```
308
309## `fill_match_arms`
310
311Adds missing clauses to a `match` expression.
312
313```rust
314// BEFORE
315enum Action { Move { distance: u32 }, Stop }
316
317fn handle(action: Action) {
318 match action {
319
320 }
321}
322
323// AFTER
324enum Action { Move { distance: u32 }, Stop }
325
326fn handle(action: Action) {
327 match action {
328 $0Action::Move { distance } => {}
329 Action::Stop => {}
330 }
331}
332```
333
334## `fix_visibility`
335
336Makes inaccessible item public.
337
338```rust
339// BEFORE
340mod m {
341 fn frobnicate() {}
342}
343fn main() {
344 m::frobnicate┃() {}
345}
346
347// AFTER
348mod m {
349 $0pub(crate) fn frobnicate() {}
350}
351fn main() {
352 m::frobnicate() {}
353}
354```
355
356## `flip_binexpr`
357
358Flips operands of a binary expression.
359
360```rust
361// BEFORE
362fn main() {
363 let _ = 90 +┃ 2;
364}
365
366// AFTER
367fn main() {
368 let _ = 2 + 90;
369}
370```
371
372## `flip_comma`
373
374Flips two comma-separated items.
375
376```rust
377// BEFORE
378fn main() {
379 ((1, 2),┃ (3, 4));
380}
381
382// AFTER
383fn main() {
384 ((3, 4), (1, 2));
385}
386```
387
388## `flip_trait_bound`
389
390Flips two trait bounds.
391
392```rust
393// BEFORE
394fn foo<T: Clone +┃ Copy>() { }
395
396// AFTER
397fn foo<T: Copy + Clone>() { }
398```
399
400## `inline_local_variable`
401
402Inlines local variable.
403
404```rust
405// BEFORE
406fn main() {
407 let x┃ = 1 + 2;
408 x * 4;
409}
410
411// AFTER
412fn main() {
413 (1 + 2) * 4;
414}
415```
416
417## `introduce_variable`
418
419Extracts subexpression into a variable.
420
421```rust
422// BEFORE
423fn main() {
424 ┃(1 + 2)┃ * 4;
425}
426
427// AFTER
428fn main() {
429 let $0var_name = (1 + 2);
430 var_name * 4;
431}
432```
433
434## `invert_if`
435
436Apply invert_if
437This transforms if expressions of the form `if !x {A} else {B}` into `if x {B} else {A}`
438This also works with `!=`. This assist can only be applied with the cursor
439on `if`.
440
441```rust
442// BEFORE
443fn main() {
444 if┃ !y { A } else { B }
445}
446
447// AFTER
448fn main() {
449 if y { B } else { A }
450}
451```
452
453## `make_raw_string`
454
455Adds `r#` to a plain string literal.
456
457```rust
458// BEFORE
459fn main() {
460 "Hello,┃ World!";
461}
462
463// AFTER
464fn main() {
465 r#"Hello, World!"#;
466}
467```
468
469## `make_usual_string`
470
471Turns a raw string into a plain string.
472
473```rust
474// BEFORE
475fn main() {
476 r#"Hello,┃ "World!""#;
477}
478
479// AFTER
480fn main() {
481 "Hello, \"World!\"";
482}
483```
484
485## `merge_imports`
486
487Merges two imports with a common prefix.
488
489```rust
490// BEFORE
491use std::┃fmt::Formatter;
492use std::io;
493
494// AFTER
495use std::{fmt::Formatter, io};
496```
497
498## `merge_match_arms`
499
500Merges identical match arms.
501
502```rust
503// BEFORE
504enum Action { Move { distance: u32 }, Stop }
505
506fn handle(action: Action) {
507 match action {
508 ┃Action::Move(..) => foo(),
509 Action::Stop => foo(),
510 }
511}
512
513// AFTER
514enum Action { Move { distance: u32 }, Stop }
515
516fn handle(action: Action) {
517 match action {
518 Action::Move(..) | Action::Stop => foo(),
519 }
520}
521```
522
523## `move_arm_cond_to_match_guard`
524
525Moves if expression from match arm body into a guard.
526
527```rust
528// BEFORE
529enum Action { Move { distance: u32 }, Stop }
530
531fn handle(action: Action) {
532 match action {
533 Action::Move { distance } => ┃if distance > 10 { foo() },
534 _ => (),
535 }
536}
537
538// AFTER
539enum Action { Move { distance: u32 }, Stop }
540
541fn handle(action: Action) {
542 match action {
543 Action::Move { distance } if distance > 10 => foo(),
544 _ => (),
545 }
546}
547```
548
549## `move_bounds_to_where_clause`
550
551Moves inline type bounds to a where clause.
552
553```rust
554// BEFORE
555fn apply<T, U, ┃F: FnOnce(T) -> U>(f: F, x: T) -> U {
556 f(x)
557}
558
559// AFTER
560fn apply<T, U, F>(f: F, x: T) -> U where F: FnOnce(T) -> U {
561 f(x)
562}
563```
564
565## `move_guard_to_arm_body`
566
567Moves match guard into match arm body.
568
569```rust
570// BEFORE
571enum Action { Move { distance: u32 }, Stop }
572
573fn handle(action: Action) {
574 match action {
575 Action::Move { distance } ┃if distance > 10 => foo(),
576 _ => (),
577 }
578}
579
580// AFTER
581enum Action { Move { distance: u32 }, Stop }
582
583fn handle(action: Action) {
584 match action {
585 Action::Move { distance } => if distance > 10 { foo() },
586 _ => (),
587 }
588}
589```
590
591## `remove_dbg`
592
593Removes `dbg!()` macro call.
594
595```rust
596// BEFORE
597fn main() {
598 ┃dbg!(92);
599}
600
601// AFTER
602fn main() {
603 92;
604}
605```
606
607## `remove_hash`
608
609Removes a hash from a raw string literal.
610
611```rust
612// BEFORE
613fn main() {
614 r#"Hello,┃ World!"#;
615}
616
617// AFTER
618fn main() {
619 r"Hello, World!";
620}
621```
622
623## `remove_mut`
624
625Removes the `mut` keyword.
626
627```rust
628// BEFORE
629impl Walrus {
630 fn feed(&mut┃ self, amount: u32) {}
631}
632
633// AFTER
634impl Walrus {
635 fn feed(&self, amount: u32) {}
636}
637```
638
639## `reorder_fields`
640
641Reorder the fields of record literals and record patterns in the same order as in
642the definition.
643
644```rust
645// BEFORE
646struct Foo {foo: i32, bar: i32};
647const test: Foo = ┃Foo {bar: 0, foo: 1}
648
649// AFTER
650struct Foo {foo: i32, bar: i32};
651const test: Foo = Foo {foo: 1, bar: 0}
652```
653
654## `replace_if_let_with_match`
655
656Replaces `if let` with an else branch with a `match` expression.
657
658```rust
659// BEFORE
660enum Action { Move { distance: u32 }, Stop }
661
662fn handle(action: Action) {
663 ┃if let Action::Move { distance } = action {
664 foo(distance)
665 } else {
666 bar()
667 }
668}
669
670// AFTER
671enum Action { Move { distance: u32 }, Stop }
672
673fn handle(action: Action) {
674 match action {
675 Action::Move { distance } => foo(distance),
676 _ => bar(),
677 }
678}
679```
680
681## `replace_let_with_if_let`
682
683Replaces `let` with an `if-let`.
684
685```rust
686// BEFORE
687
688fn main(action: Action) {
689 ┃let x = compute();
690}
691
692fn compute() -> Option<i32> { None }
693
694// AFTER
695
696fn main(action: Action) {
697 if let Some(x) = compute() {
698 }
699}
700
701fn compute() -> Option<i32> { None }
702```
703
704## `replace_qualified_name_with_use`
705
706Adds a use statement for a given fully-qualified name.
707
708```rust
709// BEFORE
710fn process(map: std::collections::┃HashMap<String, String>) {}
711
712// AFTER
713use std::collections::HashMap;
714
715fn process(map: HashMap<String, String>) {}
716```
717
718## `replace_unwrap_with_match`
719
720Replaces `unwrap` a `match` expression. Works for Result and Option.
721
722```rust
723// BEFORE
724enum Result<T, E> { Ok(T), Err(E) }
725fn main() {
726 let x: Result<i32, i32> = Result::Ok(92);
727 let y = x.┃unwrap();
728}
729
730// AFTER
731enum Result<T, E> { Ok(T), Err(E) }
732fn main() {
733 let x: Result<i32, i32> = Result::Ok(92);
734 let y = match x {
735 Ok(a) => a,
736 $0_ => unreachable!(),
737 };
738}
739```
740
741## `split_import`
742
743Wraps the tail of import into braces.
744
745```rust
746// BEFORE
747use std::┃collections::HashMap;
748
749// AFTER
750use std::{collections::HashMap};
751```
752
753## `unwrap_block`
754
755This assist removes if...else, for, while and loop control statements to just keep the body.
756
757```rust
758// BEFORE
759fn foo() {
760 if true {┃
761 println!("foo");
762 }
763}
764
765// AFTER
766fn foo() {
767 println!("foo");
768}
769```