diff options
author | Aleksey Kladov <[email protected]> | 2019-10-25 21:38:15 +0100 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2019-10-25 21:38:15 +0100 |
commit | d385438bcc8d302fbcb91114e19ac0cc30528822 (patch) | |
tree | d57842c6462f4921976d6d9642ce7751681cf0bd /docs/user | |
parent | e6cb06d2850b9b9c38c0c13d6948ab39adcd652e (diff) |
generate more assists docs
Diffstat (limited to 'docs/user')
-rw-r--r-- | docs/user/assists.md | 137 | ||||
-rw-r--r-- | docs/user/features.md | 91 |
2 files changed, 137 insertions, 91 deletions
diff --git a/docs/user/assists.md b/docs/user/assists.md index cb4b0b9fb..eeb486832 100644 --- a/docs/user/assists.md +++ b/docs/user/assists.md | |||
@@ -1,5 +1,142 @@ | |||
1 | # Assists | 1 | # Assists |
2 | 2 | ||
3 | ## `add_derive` | ||
4 | |||
5 | Adds a new `#[derive()]` clause to a struct or enum. | ||
6 | |||
7 | ```rust | ||
8 | // BEFORE | ||
9 | struct Point { | ||
10 | x: u32, | ||
11 | y: u32,<|> | ||
12 | } | ||
13 | |||
14 | // AFTER | ||
15 | #[derive()] | ||
16 | struct Point { | ||
17 | x: u32, | ||
18 | y: u32, | ||
19 | } | ||
20 | ``` | ||
21 | |||
22 | ## `add_explicit_type` | ||
23 | |||
24 | Specify type for a let binding | ||
25 | |||
26 | ```rust | ||
27 | // BEFORE | ||
28 | fn main() { | ||
29 | let x<|> = 92; | ||
30 | } | ||
31 | |||
32 | // AFTER | ||
33 | fn main() { | ||
34 | let x: i32 = 92; | ||
35 | } | ||
36 | ``` | ||
37 | |||
38 | ## `add_impl` | ||
39 | |||
40 | Adds a new inherent impl for a type | ||
41 | |||
42 | ```rust | ||
43 | // BEFORE | ||
44 | struct Ctx<T: Clone> { | ||
45 | data: T,<|> | ||
46 | } | ||
47 | |||
48 | // AFTER | ||
49 | struct Ctx<T: Clone> { | ||
50 | data: T, | ||
51 | } | ||
52 | |||
53 | impl<T: Clone> Ctx<T> { | ||
54 | |||
55 | } | ||
56 | ``` | ||
57 | |||
58 | ## `add_impl_default_members` | ||
59 | |||
60 | Adds scaffold for overriding default impl members | ||
61 | |||
62 | ```rust | ||
63 | // BEFORE | ||
64 | trait T { | ||
65 | Type X; | ||
66 | fn foo(&self); | ||
67 | fn bar(&self) {} | ||
68 | } | ||
69 | |||
70 | impl T for () { | ||
71 | Type X = (); | ||
72 | fn foo(&self) {}<|> | ||
73 | |||
74 | } | ||
75 | |||
76 | // AFTER | ||
77 | trait T { | ||
78 | Type X; | ||
79 | fn foo(&self); | ||
80 | fn bar(&self) {} | ||
81 | } | ||
82 | |||
83 | impl T for () { | ||
84 | Type X = (); | ||
85 | fn foo(&self) {} | ||
86 | fn bar(&self) {} | ||
87 | |||
88 | } | ||
89 | ``` | ||
90 | |||
91 | ## `add_impl_missing_members` | ||
92 | |||
93 | Adds scaffold for required impl members | ||
94 | |||
95 | ```rust | ||
96 | // BEFORE | ||
97 | trait T { | ||
98 | Type X; | ||
99 | fn foo(&self); | ||
100 | fn bar(&self) {} | ||
101 | } | ||
102 | |||
103 | impl T for () {<|> | ||
104 | |||
105 | } | ||
106 | |||
107 | // AFTER | ||
108 | trait T { | ||
109 | Type X; | ||
110 | fn foo(&self); | ||
111 | fn bar(&self) {} | ||
112 | } | ||
113 | |||
114 | impl T for () { | ||
115 | fn foo(&self) { unimplemented!() } | ||
116 | |||
117 | } | ||
118 | ``` | ||
119 | |||
120 | ## `apply_demorgan` | ||
121 | |||
122 | Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws). | ||
123 | This transforms expressions of the form `!l || !r` into `!(l && r)`. | ||
124 | This also works with `&&`. This assist can only be applied with the cursor | ||
125 | on either `||` or `&&`, with both operands being a negation of some kind. | ||
126 | This means something of the form `!x` or `x != y`. | ||
127 | |||
128 | ```rust | ||
129 | // BEFORE | ||
130 | fn main() { | ||
131 | if x != 4 ||<|> !y {} | ||
132 | } | ||
133 | |||
134 | // AFTER | ||
135 | fn main() { | ||
136 | if !(x == 4 && y) {} | ||
137 | } | ||
138 | ``` | ||
139 | |||
3 | ## `convert_to_guarded_return` | 140 | ## `convert_to_guarded_return` |
4 | 141 | ||
5 | Replace a large conditional with a guarded return. | 142 | Replace a large conditional with a guarded return. |
diff --git a/docs/user/features.md b/docs/user/features.md index a94b65ad4..acf092cec 100644 --- a/docs/user/features.md +++ b/docs/user/features.md | |||
@@ -104,84 +104,6 @@ the VS Code side to be able to position cursor. `<|>` signifies cursor | |||
104 | 104 | ||
105 | See [assists.md](./assists.md) | 105 | See [assists.md](./assists.md) |
106 | 106 | ||
107 | - Add `#[derive]` | ||
108 | |||
109 | ```rust | ||
110 | // before: | ||
111 | struct Foo { | ||
112 | <|>x: i32 | ||
113 | } | ||
114 | // after: | ||
115 | #[derive(<|>)] | ||
116 | struct Foo { | ||
117 | x: i32 | ||
118 | } | ||
119 | ``` | ||
120 | |||
121 | - Add `impl` | ||
122 | |||
123 | ```rust | ||
124 | // before: | ||
125 | struct Foo<'a, T: Debug> { | ||
126 | <|>t: T | ||
127 | } | ||
128 | // after: | ||
129 | struct Foo<'a, T: Debug> { | ||
130 | t: T | ||
131 | } | ||
132 | |||
133 | impl<'a, T: Debug> Foo<'a, T> { | ||
134 | <|> | ||
135 | } | ||
136 | ``` | ||
137 | |||
138 | - Add missing `impl` members | ||
139 | |||
140 | ```rust | ||
141 | // before: | ||
142 | trait Foo { | ||
143 | fn foo(&self); | ||
144 | fn bar(&self); | ||
145 | fn baz(&self); | ||
146 | } | ||
147 | |||
148 | struct S; | ||
149 | |||
150 | impl Foo for S { | ||
151 | fn bar(&self) {} | ||
152 | <|> | ||
153 | } | ||
154 | |||
155 | // after: | ||
156 | trait Foo { | ||
157 | fn foo(&self); | ||
158 | fn bar(&self); | ||
159 | fn baz(&self); | ||
160 | } | ||
161 | |||
162 | struct S; | ||
163 | |||
164 | impl Foo for S { | ||
165 | fn bar(&self) {} | ||
166 | fn foo(&self) { unimplemented!() } | ||
167 | fn baz(&self) { unimplemented!() }<|> | ||
168 | } | ||
169 | ``` | ||
170 | |||
171 | - Apply [De Morgan's law](https://en.wikipedia.org/wiki/De_Morgan%27s_laws) | ||
172 | |||
173 | ```rust | ||
174 | // before: | ||
175 | fn example(x: bool) -> bool { | ||
176 | !x || !x | ||
177 | } | ||
178 | |||
179 | // after: | ||
180 | fn example(x: bool) -> bool { | ||
181 | !(x && x) | ||
182 | } | ||
183 | ``` | ||
184 | |||
185 | - Import path | 107 | - Import path |
186 | 108 | ||
187 | ```rust | 109 | ```rust |
@@ -391,19 +313,6 @@ fn foo() { | |||
391 | } | 313 | } |
392 | ``` | 314 | ``` |
393 | 315 | ||
394 | - Add explicit type | ||
395 | |||
396 | ```rust | ||
397 | // before: | ||
398 | fn foo() { | ||
399 | let t<|> = (&2, Some(1)); | ||
400 | } | ||
401 | // after: | ||
402 | fn foo() { | ||
403 | let t<|>: (&i32, Option<i32>) = (&2, Some(1)); | ||
404 | } | ||
405 | ``` | ||
406 | |||
407 | - Move guard expression to match arm body | 316 | - Move guard expression to match arm body |
408 | ```rust | 317 | ```rust |
409 | // before: | 318 | // before: |