aboutsummaryrefslogtreecommitdiff
path: root/docs/user
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-20 10:05:03 +0000
committerAleksey Kladov <[email protected]>2019-03-20 10:05:03 +0000
commit07a9e5c0e1c20f66730f608647e96ce29359b91d (patch)
tree7b5da44305f0f435b86481a1af514ec33b743e75 /docs/user
parentab9fef1ee26c185cdf2b14c3d21ecfae7b0905ae (diff)
document assists
Diffstat (limited to 'docs/user')
-rw-r--r--docs/user/features.md251
1 files changed, 203 insertions, 48 deletions
diff --git a/docs/user/features.md b/docs/user/features.md
index 5df606aee..aa3bf5157 100644
--- a/docs/user/features.md
+++ b/docs/user/features.md
@@ -1,45 +1,47 @@
1This documents is an index of features that rust-analyzer language server provides. 1This documents is an index of features that rust-analyzer language server
2provides. Shortcuts are for the default VS Code layout. If there's no shortcut,
3you can use <kbd>Ctrl+Shift+P</kbd> to search for the corresponding action.
2 4
3### Go to symbol in workspace <kbd>ctrl+t</kbd> 5### Workspace Symbol <kbd>ctrl+t</kbd>
4 6
5It mostly works on top of the built-in LSP functionality, however `#` and `*` 7Uses fuzzy-search to find types, modules and function by name across your
6symbols can be used to narrow down the search. Specifically, 8project and dependencies. This **the** most useful feature, which improves code
9navigation tremendously. It mostly works on top of the built-in LSP
10functionality, however `#` and `*` symbols can be used to narrow down the
11search. Specifically,
7 12
8- `#Foo` searches for `Foo` type in the current workspace 13- `Foo` searches for `Foo` type in the current workspace
9- `#foo#` searches for `foo` function in the current workspace 14- `foo#` searches for `foo` function in the current workspace
10- `#Foo*` searches for `Foo` type among dependencies, excluding `stdlib` 15- `Foo*` searches for `Foo` type among dependencies, excluding `stdlib`
11- `#foo#*` searches for `foo` function among dependencies. 16- `foo#*` searches for `foo` function among dependencies.
12 17
13That is, `#` switches from "types" to all symbols, `*` switches from the current 18That is, `#` switches from "types" to all symbols, `*` switches from the current
14workspace to dependencies. 19workspace to dependencies.
15 20
16### Commands <kbd>ctrl+shift+p</kbd> 21### Document Symbol <kbd>ctrl+shift+o</kbd>
17
18#### Show Rust Syntax Tree
19
20Shows the parse tree of the current file. It exists mostly for debugging
21rust-analyzer itself.
22 22
23#### Extend Selection 23Provides a tree of the symbols defined in the file. Can be used to
24 24
25Extends the current selection to the encompassing syntactic construct 25* fuzzy search symbol in a file (super useful)
26(expression, statement, item, module, etc). It works with multiple cursors. Do 26* draw breadcrumbs to describe the context around the cursor
27bind this command to a key, its super-useful! Expected to be upstreamed to LSP soonish: 27* draw outline of the file
28https://github.com/Microsoft/language-server-protocol/issues/613
29 28
30#### Matching Brace 29### On Typing Assists
31 30
32If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair, 31Some features trigger on typing certain characters:
33moves cursor to the matching brace. It uses the actual parser to determine
34braces, so it won't confuse generics with comparisons.
35 32
36#### Parent Module 33- typing `let =` tries to smartly add `;` if `=` is followed by an existing expression.
34- Enter inside comments automatically inserts `///`
35- typing `.` in a chain method call auto-indents
37 36
38Navigates to the parent module of the current module. 37### Commands <kbd>ctrl+shift+p</kbd>
39 38
40#### Join Lines 39#### Extend Selection
41 40
42Join selected lines into one, smartly fixing up whitespace and trailing commas. 41Extends the current selection to the encompassing syntactic construct
42(expression, statement, item, module, etc). It works with multiple cursors. Do
43bind this command to a key, it's super-useful! Expected to be upstreamed to LSP
44soonish: https://github.com/Microsoft/language-server-protocol/issues/613
43 45
44#### Run 46#### Run
45 47
@@ -47,33 +49,37 @@ Shows popup suggesting to run a test/benchmark/binary **at the current cursor
47location**. Super useful for repeatedly running just a single test. Do bind this 49location**. Super useful for repeatedly running just a single test. Do bind this
48to a shortcut! 50to a shortcut!
49 51
52#### Parent Module
50 53
51### On Typing Assists 54Navigates to the parent module of the current module.
52 55
53Some features trigger on typing certain characters: 56#### Matching Brace
54 57
55- typing `let =` tries to smartly add `;` if `=` is followed by an existing expression. 58If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair,
56- Enter inside comments automatically inserts `///` 59moves cursor to the matching brace. It uses the actual parser to determine
57- typing `.` in a chain method call auto-indents 60braces, so it won't confuse generics with comparisons.
58 61
62#### Join Lines
59 63
64Join selected lines into one, smartly fixing up whitespace and trailing commas.
60 65
66#### Show Syntax Tree
61 67
68Shows the parse tree of the current file. It exists mostly for debugging
69rust-analyzer itself.
62 70
63### Code Actions (Assists) 71#### Status
64 72
65These are triggered in a particular context via light bulb. We use custom code on 73Shows internal statistic about memory usage of rust-analyzer
66the VS Code side to be able to position cursor.
67 74
75#### Run garbage collection
68 76
69- Flip `,` 77Manually triggers GC
70 78
71```rust 79### Code Actions (Assists)
72// before: 80
73fn foo(x: usize,<|> dim: (usize, usize)) 81These are triggered in a particular context via light bulb. We use custom code on
74// after: 82the VS Code side to be able to position cursor. `<|>` signifies cursor
75fn foo(dim: (usize, usize), x: usize)
76```
77 83
78- Add `#[derive]` 84- Add `#[derive]`
79 85
@@ -106,14 +112,147 @@ impl<'a, T: Debug> Foo<'a, T> {
106} 112}
107``` 113```
108 114
109- Change visibility 115- Add missing `impl` members
110 116
111```rust 117```rust
112// before: 118// before:
113fn<|> foo() {} 119trait Foo {
120 fn foo(&self);
121 fn bar(&self);
122 fn baz(&self);
123}
124
125struct S;
126
127impl Foo for S {
128 fn bar(&self) {}
129 <|>
130}
131
132// after:
133trait Foo {
134 fn foo(&self);
135 fn bar(&self);
136 fn baz(&self);
137}
114 138
115// after 139struct S;
116pub(crate) fn foo() {} 140
141impl Foo for S {
142 fn bar(&self) {}
143 fn foo(&self) { unimplemented!() }
144 fn baz(&self) { unimplemented!() }<|>
145}
146```
147
148- Import path
149
150```rust
151// before:
152impl std::fmt::Debug<|> for Foo {
153}
154
155// after:
156use std::fmt::Debug
157
158impl Debug<|> for Foo {
159}
160```
161
162- Change Visibility
163
164```rust
165// before:
166<|>fn foo() {}
167
168// after:
169<|>pub(crate) fn foo() {}
170
171// after:
172<|>pub fn foo() {}
173```
174
175- Fill match arms
176
177```rust
178// before:
179enum A {
180 As,
181 Bs,
182 Cs(String),
183 Ds(String, String),
184 Es{x: usize, y: usize}
185}
186
187fn main() {
188 let a = A::As;
189 match a<|> {}
190}
191
192// after:
193enum A {
194 As,
195 Bs,
196 Cs(String),
197 Ds(String, String),
198 Es{x: usize, y: usize}
199}
200
201fn main() {
202 let a = A::As;
203 match <|>a {
204 A::As => (),
205 A::Bs => (),
206 A::Cs(_) => (),
207 A::Ds(_, _) => (),
208 A::Es{x, y} => (),
209 }
210}
211```
212
213-- Fill struct fields
214
215```rust
216// before:
217struct S<'a, D> {
218 a: u32,
219 b: String,
220 c: (i32, i32),
221 d: D,
222 r: &'a str,
223}
224
225fn main() {
226 let s = S<|> {}
227}
228
229// after:
230struct S<'a, D> {
231 a: u32,
232 b: String,
233 c: (i32, i32),
234 d: D,
235 r: &'a str,
236}
237
238fn main() {
239 let s = <|>S {
240 a: (),
241 b: (),
242 c: (),
243 d: (),
244 r: (),
245 }
246}
247```
248
249- Flip `,`
250
251```rust
252// before:
253fn foo(x: usize,<|> dim: (usize, usize)) {}
254// after:
255fn foo(dim: (usize, usize), x: usize) {}
117``` 256```
118 257
119- Introduce variable: 258- Introduce variable:
@@ -131,6 +270,24 @@ fn foo() {
131} 270}
132``` 271```
133 272
273-- Remove `dbg!`
274
275```rust
276// before:
277fn foo(n: usize) {
278 if let Some(_) = dbg!(n.<|>checked_sub(4)) {
279 // ...
280 }
281}
282
283// after:
284fn foo(n: usize) {
285 if let Some(_) = n.<|>checked_sub(4) {
286 // ...
287 }
288}
289```
290
134- Replace if-let with match: 291- Replace if-let with match:
135 292
136```rust 293```rust
@@ -164,5 +321,3 @@ use algo:<|>:visitor::{Visitor, visit};
164//after: 321//after:
165use algo::{<|>visitor::{Visitor, visit}}; 322use algo::{<|>visitor::{Visitor, visit}};
166``` 323```
167
168