1 This documents is an index of features that rust-analyzer language server
2 provides. Shortcuts are for the default VS Code layout. If there's no shortcut,
3 you can use <kbd>Ctrl+Shift+P</kbd> to search for the corresponding action.
5 ### Workspace Symbol <kbd>ctrl+t</kbd>
7 Uses fuzzy-search to find types, modules and function by name across your
8 project and dependencies. This is **the** most useful feature, which improves code
9 navigation tremendously. It mostly works on top of the built-in LSP
10 functionality, however `#` and `*` symbols can be used to narrow down the
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.
18 That is, `#` switches from "types" to all symbols, `*` switches from the current
19 workspace to dependencies.
21 ### Document Symbol <kbd>ctrl+shift+o</kbd>
23 Provides a tree of the symbols defined in the file. Can be used to
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
31 Some features trigger on typing certain characters:
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
39 Extends the current selection to the encompassing syntactic construct
40 (expression, statement, item, module, etc). It works with multiple cursors. This
41 is a relatively new feature of LSP:
42 https://github.com/Microsoft/language-server-protocol/issues/613, check your
43 editor's LSP library to see if this feature is supported.
47 Navigates to the definition of an identifier.
49 ### Go to Implementation
51 Navigates to the impl block of structs, enums or traits. Also implemented as a code lens.
53 ### Go to Type Defintion
55 Navigates to the type of an identifier.
57 ### Commands <kbd>ctrl+shift+p</kbd>
61 Shows popup suggesting to run a test/benchmark/binary **at the current cursor
62 location**. Super useful for repeatedly running just a single test. Do bind this
67 Navigates to the parent module of the current module.
71 If the cursor is on any brace (`<>(){}[]`) which is a part of a brace-pair,
72 moves cursor to the matching brace. It uses the actual parser to determine
73 braces, so it won't confuse generics with comparisons.
77 Join selected lines into one, smartly fixing up whitespace and trailing commas.
81 Shows the parse tree of the current file. It exists mostly for debugging
86 Shows internal statistic about memory usage of rust-analyzer
88 #### Run garbage collection
92 #### Start Cargo Watch
94 Start `cargo watch` for live error highlighting. Will prompt to install if it's not already installed.
100 ### Assists (Code Actions)
102 Assists, or code actions, are small local refactorings, available in a particular context.
103 They are usually triggered by a shortcut or by clicking a light bulb icon in the editor.
105 See [assists.md](./assists.md) for the list of available assists.
107 ### Magic Completions
109 In addition to usual reference completion, rust-analyzer provides some ✨magic✨
112 Keywords like `if`, `else` `while`, `loop` are completed with braces, and cursor
113 is placed at the appropriate position. Even though `if` is easy to type, you
114 still want to complete it, to get ` { }` for free! `return` is inserted with a
115 space or `;` depending on the return type of the function.
117 When completing a function call, `()` are automatically inserted. If function
118 takes arguments, cursor is positioned inside the parenthesis.
120 There are postifx completions, which can be triggerd by typing something like
121 `foo().if`. The word after `.` determines postifx completion, possible variants are:
123 - `expr.if` -> `if expr {}`
124 - `expr.match` -> `match expr {}`
125 - `expr.while` -> `while expr {}`
126 - `expr.ref` -> `&expr`
127 - `expr.refm` -> `&mut expr`
128 - `expr.not` -> `!expr`
129 - `expr.dbg` -> `dbg!(expr)`
131 There also snippet completions:
133 #### Inside Expressions
135 - `pd` -> `println!("{:?}")`
136 - `ppd` -> `println!("{:#?}")`
140 - `tfn` -> `#[test] fn f(){}`
142 ### Code highlighting
144 Experimental feature to let rust-analyzer highlight Rust code instead of using the
147 #### Rainbow highlighting
149 Experimental feature that, given code highlighting using rust-analyzer is
150 active, will pick unique colors for identifiers.