aboutsummaryrefslogtreecommitdiff
path: root/docs/user/features.md
diff options
context:
space:
mode:
Diffstat (limited to 'docs/user/features.md')
-rw-r--r--docs/user/features.md212
1 files changed, 0 insertions, 212 deletions
diff --git a/docs/user/features.md b/docs/user/features.md
deleted file mode 100644
index 340bce835..000000000
--- a/docs/user/features.md
+++ /dev/null
@@ -1,212 +0,0 @@
1This document is an index of features that the 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.
4
5### Workspace Symbol <kbd>ctrl+t</kbd>
6
7Uses fuzzy-search to find types, modules and functions by name across your
8project and dependencies. This is **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,
12
13- `Foo` searches for `Foo` type in the current workspace
14- `foo#` searches for `foo` function in the current workspace
15- `Foo*` searches for `Foo` type among dependencies, including `stdlib`
16- `foo#*` searches for `foo` function among dependencies
17
18That is, `#` switches from "types" to all symbols, `*` switches from the current
19workspace to dependencies.
20
21### Document Symbol <kbd>ctrl+shift+o</kbd>
22
23Provides a tree of the symbols defined in the file. Can be used to
24
25* fuzzy search symbol in a file (super useful)
26* draw breadcrumbs to describe the context around the cursor
27* draw outline of the file
28
29### On Typing Assists
30
31Some features trigger on typing certain characters:
32
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
36
37### Extend Selection
38
39Extends the current selection to the encompassing syntactic construct
40(expression, statement, item, module, etc). It works with multiple cursors. This
41is a relatively new feature of LSP:
42https://github.com/Microsoft/language-server-protocol/issues/613, check your
43editor's LSP library to see if this feature is supported.
44
45### Go to Definition
46
47Navigates to the definition of an identifier.
48
49### Go to Implementation
50
51Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
52
53### Go to Type Defintion
54
55Navigates to the type of an identifier.
56
57### Commands <kbd>ctrl+shift+p</kbd>
58
59#### Run
60
61Shows a popup suggesting to run a test/benchmark/binary **at the current cursor
62location**. Super useful for repeatedly running just a single test. Do bind this
63to a shortcut!
64
65#### Parent Module
66
67Navigates to the parent module of the current module.
68
69#### Matching Brace
70
71If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair,
72moves cursor to the matching brace. It uses the actual parser to determine
73braces, so it won't confuse generics with comparisons.
74
75#### Join Lines
76
77Join selected lines into one, smartly fixing up whitespace and trailing commas.
78
79#### Show Syntax Tree
80
81Shows the parse tree of the current file. It exists mostly for debugging
82rust-analyzer itself.
83
84#### Expand Macro Recursively
85
86Shows the full macro expansion of the macro at current cursor.
87
88#### Status
89
90Shows internal statistic about memory usage of rust-analyzer.
91
92#### Show RA Version
93
94Show current rust-analyzer version.
95
96#### Run Garbage Collection
97
98Manually triggers GC.
99
100#### Start Cargo Watch
101
102Start `cargo watch` for live error highlighting. Will prompt to install if it's not already installed.
103
104#### Stop Cargo Watch
105
106Stop `cargo watch`.
107
108#### Structural Seach and Replace
109
110Search and replace with named wildcards that will match any expression.
111The syntax for a structural search replace command is `<search_pattern> ==>> <replace_pattern>`. A `$<name>:expr` placeholder in the search pattern will match any expression and `$<name>` will reference it in the replacement. Available via the command `rust-analyzer.ssr`.
112
113```rust
114// Using structural search replace command [foo($a:expr, $b:expr) ==>> ($a).foo($b)]
115
116// BEFORE
117String::from(foo(y + 5, z))
118
119// AFTER
120String::from((y + 5).foo(z))
121```
122
123### Assists (Code Actions)
124
125Assists, or code actions, are small local refactorings, available in a particular context.
126They are usually triggered by a shortcut or by clicking a light bulb icon in the editor.
127
128See [assists.md](./assists.md) for the list of available assists.
129
130### Magic Completions
131
132In addition to usual reference completion, rust-analyzer provides some ✨magic✨
133completions as well:
134
135Keywords like `if`, `else` `while`, `loop` are completed with braces, and cursor
136is placed at the appropriate position. Even though `if` is easy to type, you
137still want to complete it, to get ` { }` for free! `return` is inserted with a
138space or `;` depending on the return type of the function.
139
140When completing a function call, `()` are automatically inserted. If a function
141takes arguments, the cursor is positioned inside the parenthesis.
142
143There are postfix completions, which can be triggered by typing something like
144`foo().if`. The word after `.` determines postfix completion. Possible variants are:
145
146- `expr.if` -> `if expr {}` or `if let ... {}` for `Option` or `Result`
147- `expr.match` -> `match expr {}`
148- `expr.while` -> `while expr {}` or `while let ... {}` for `Option` or `Result`
149- `expr.ref` -> `&expr`
150- `expr.refm` -> `&mut expr`
151- `expr.not` -> `!expr`
152- `expr.dbg` -> `dbg!(expr)`
153
154There also snippet completions:
155
156#### Inside Expressions
157
158- `pd` -> `println!("{:?}")`
159- `ppd` -> `println!("{:#?}")`
160
161#### Inside Modules
162
163- `tfn` -> `#[test] fn f(){}`
164- `tmod` ->
165```rust
166#[cfg(test)]
167mod tests {
168 use super::*;
169
170 #[test]
171 fn test_fn() {}
172}
173```
174
175### Code Highlighting
176
177Experimental feature to let rust-analyzer highlight Rust code instead of using the
178default highlighter.
179
180#### Rainbow Highlighting
181
182Experimental feature that, given code highlighting using rust-analyzer is
183active, will pick unique colors for identifiers.
184
185### Code hints
186
187Rust-analyzer has two types of hints to show the information about the code:
188
189* hover hints, appearing on hover on any element.
190
191These contain extended information on the hovered language item.
192
193* inlay hints, shown near the element hinted directly in the editor.
194
195Two types of inlay hints are displayed currently:
196
197* type hints, displaying the minimal information on the type of the expression (if the information is available)
198* method chaining hints, type information for multi-line method chains
199* parameter name hints, displaying the names of the parameters in the corresponding methods
200
201#### VS Code
202
203In VS Code, the following settings can be used to configure the inlay hints:
204
205* `rust-analyzer.inlayHints.typeHints` - enable hints for inferred types.
206* `rust-analyzer.inlayHints.chainingHints` - enable hints for inferred types on method chains.
207* `rust-analyzer.inlayHints.parameterHints` - enable hints for function parameters.
208* `rust-analyzer.inlayHints.maxLength` — shortens the hints if their length exceeds the value specified. If no value is specified (`null`), no shortening is applied.
209
210**Note:** VS Code does not have native support for inlay hints [yet](https://github.com/microsoft/vscode/issues/16221) and the hints are implemented using decorations.
211This approach has limitations, the caret movement and bracket highlighting near the edges of the hint may be weird:
212[1](https://github.com/rust-analyzer/rust-analyzer/issues/1623), [2](https://github.com/rust-analyzer/rust-analyzer/issues/3453).