aboutsummaryrefslogtreecommitdiff
path: root/docs/user/features.md
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-03-20 09:17:12 +0000
committerAleksey Kladov <[email protected]>2019-03-20 09:17:12 +0000
commit192a5cd11d413fdbaeb8d2e5106d82ae3b4a05c1 (patch)
treedf4c52f32169b09b00d0b5af2b8338fd7dd213d7 /docs/user/features.md
parent206bbe9c93f3fd33922c9e00cfb263b980a79ca2 (diff)
better user docs
Diffstat (limited to 'docs/user/features.md')
-rw-r--r--docs/user/features.md168
1 files changed, 168 insertions, 0 deletions
diff --git a/docs/user/features.md b/docs/user/features.md
new file mode 100644
index 000000000..5df606aee
--- /dev/null
+++ b/docs/user/features.md
@@ -0,0 +1,168 @@
1This documents is an index of features that rust-analyzer language server provides.
2
3### Go to symbol in workspace <kbd>ctrl+t</kbd>
4
5It mostly works on top of the built-in LSP functionality, however `#` and `*`
6symbols can be used to narrow down the search. Specifically,
7
8- `#Foo` searches for `Foo` type in the current workspace
9- `#foo#` searches for `foo` function in the current workspace
10- `#Foo*` searches for `Foo` type among dependencies, excluding `stdlib`
11- `#foo#*` searches for `foo` function among dependencies.
12
13That is, `#` switches from "types" to all symbols, `*` switches from the current
14workspace to dependencies.
15
16### Commands <kbd>ctrl+shift+p</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
23#### Extend Selection
24
25Extends the current selection to the encompassing syntactic construct
26(expression, statement, item, module, etc). It works with multiple cursors. Do
27bind this command to a key, its super-useful! Expected to be upstreamed to LSP soonish:
28https://github.com/Microsoft/language-server-protocol/issues/613
29
30#### Matching Brace
31
32If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair,
33moves cursor to the matching brace. It uses the actual parser to determine
34braces, so it won't confuse generics with comparisons.
35
36#### Parent Module
37
38Navigates to the parent module of the current module.
39
40#### Join Lines
41
42Join selected lines into one, smartly fixing up whitespace and trailing commas.
43
44#### Run
45
46Shows 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
48to a shortcut!
49
50
51### On Typing Assists
52
53Some features trigger on typing certain characters:
54
55- typing `let =` tries to smartly add `;` if `=` is followed by an existing expression.
56- Enter inside comments automatically inserts `///`
57- typing `.` in a chain method call auto-indents
58
59
60
61
62
63### Code Actions (Assists)
64
65These are triggered in a particular context via light bulb. We use custom code on
66the VS Code side to be able to position cursor.
67
68
69- Flip `,`
70
71```rust
72// before:
73fn foo(x: usize,<|> dim: (usize, usize))
74// after:
75fn foo(dim: (usize, usize), x: usize)
76```
77
78- Add `#[derive]`
79
80```rust
81// before:
82struct Foo {
83 <|>x: i32
84}
85// after:
86#[derive(<|>)]
87struct Foo {
88 x: i32
89}
90```
91
92- Add `impl`
93
94```rust
95// before:
96struct Foo<'a, T: Debug> {
97 <|>t: T
98}
99// after:
100struct Foo<'a, T: Debug> {
101 t: T
102}
103
104impl<'a, T: Debug> Foo<'a, T> {
105 <|>
106}
107```
108
109- Change visibility
110
111```rust
112// before:
113fn<|> foo() {}
114
115// after
116pub(crate) fn foo() {}
117```
118
119- Introduce variable:
120
121```rust
122// before:
123fn foo() {
124 foo(<|>1 + 1<|>);
125}
126
127// after:
128fn foo() {
129 let var_name = 1 + 1;
130 foo(var_name);
131}
132```
133
134- Replace if-let with match:
135
136```rust
137// before:
138impl VariantData {
139 pub fn is_struct(&self) -> bool {
140 if <|>let VariantData::Struct(..) = *self {
141 true
142 } else {
143 false
144 }
145 }
146}
147
148// after:
149impl VariantData {
150 pub fn is_struct(&self) -> bool {
151 <|>match *self {
152 VariantData::Struct(..) => true,
153 _ => false,
154 }
155 }
156}
157```
158
159- Split import
160
161```rust
162// before:
163use algo:<|>:visitor::{Visitor, visit};
164//after:
165use algo::{<|>visitor::{Visitor, visit}};
166```
167
168