4 In order to build the VS Code plugin, you need to have node.js and npm with
5 a minimum version of 10 installed. Please refer to
6 [node.js and npm documentation](https://nodejs.org) for installation instructions.
8 You will also need the most recent version of VS Code: we don't try to
9 maintain compatibility with older versions yet.
11 The experimental VS Code plugin can then be built and installed by executing the
15 $ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1
20 $ rustup component add rust-src
23 This will run `cargo install --package ra_lsp_server` to install the server
24 binary into `~/.cargo/bin`, and then will build and install plugin from
26 [this](https://github.com/rust-analyzer/rust-analyzer/blob/0199572a3d06ff66eeae85a2d2c9762996f0d2d8/crates/tools/src/main.rs#L150)
27 for details. The installation is expected to *just work*, if it doesn't, report
30 It's better to remove existing Rust plugins to avoid interference.
32 ## Rust Analyzer Specific Features
34 These features are implemented as extensions to the language server protocol.
35 They are more experimental in nature and work only with VS Code.
37 ### Syntax highlighting
39 It overrides built-in highlighting, and works only with a specific theme
40 (zenburn). `rust-analyzer.highlightingOn` setting can be used to disable it.
42 ### Go to symbol in workspace <kbd>ctrl+t</kbd>
44 It mostly works on top of the built-in LSP functionality, however `#` and `*`
45 symbols can be used to narrow down the search. Specifically,
47 - `#Foo` searches for `Foo` type in the current workspace
48 - `#foo#` searches for `foo` function in the current workspace
49 - `#Foo*` searches for `Foo` type among dependencies, excluding `stdlib`
50 - `#foo#*` searches for `foo` function among dependencies.
52 That is, `#` switches from "types" to all symbols, `*` switches from the current
53 workspace to dependencies.
55 ### Commands <kbd>ctrl+shift+p</kbd>
57 #### Show Rust Syntax Tree
59 Shows the parse tree of the current file. It exists mostly for debugging
64 Extends the current selection to the encompassing syntactic construct
65 (expression, statement, item, module, etc). It works with multiple cursors. Do
66 bind this command to a key, its super-useful! Expected to be upstreamed to LSP soonish:
67 https://github.com/Microsoft/language-server-protocol/issues/613
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 Navigates to the parent module of the current module.
81 Join selected lines into one, smartly fixing up whitespace and trailing commas.
85 Shows popup suggesting to run a test/benchmark/binary **at the current cursor
86 location**. Super useful for repeatedly running just a single test. Do bind this
92 Some features trigger on typing certain characters:
94 - typing `let =` tries to smartly add `;` if `=` is followed by an existing expression.
95 - Enter inside comments automatically inserts `///`
96 - typing `.` in a chain method call auto-indents
99 ### Code Actions (Assists)
101 These are triggered in a particular context via light bulb. We use custom code on
102 the VS Code side to be able to position cursor.
109 fn foo(x: usize,<|> dim: (usize, usize))
111 fn foo(dim: (usize, usize), x: usize)
132 struct Foo<'a, T: Debug> {
136 struct Foo<'a, T: Debug> {
140 impl<'a, T: Debug> Foo<'a, T> {
152 pub(crate) fn foo() {}
155 - Introduce variable:
165 let var_name = 1 + 1;
170 - Replace if-let with match:
175 pub fn is_struct(&self) -> bool {
176 if <|>let VariantData::Struct(..) = *self {
186 pub fn is_struct(&self) -> bool {
188 VariantData::Struct(..) => true,
199 use algo:<|>:visitor::{Visitor, visit};
201 use algo::{<|>visitor::{Visitor, visit}};
206 * **Go to definition**: works correctly for local variables and some paths,
207 falls back to heuristic name matching for other things for the time being.
209 * **Completion**: completes paths, including dependencies and standard library.
210 Does not handle glob imports and macros. Completes fields and inherent
213 * **Outline** <kbd>alt+shift+o</kbd>
217 * **Format document**. Formats the current file with rustfmt. Rustfmt must be
218 installed separately with `rustup component add rustfmt`.
220 * **Hover** shows types of expressions and docstings
222 * **Rename** works for local variables
224 * **Code Lens** for running tests
229 - missing module for `mod foo;` with a fix to create `foo.rs`.
230 - struct field shorthand
231 - unnecessary braces in use item
236 Rust Analyzer is expected to be pretty fast. Specifically, the initial analysis
237 of the project (i.e, when you first invoke completion or symbols) typically
238 takes dozen of seconds at most. After that, everything is supposed to be more or
239 less instant. However currently all analysis results are kept in memory, so
240 memory usage is pretty high. Working with `rust-lang/rust` repo, for example,
241 needs about 5 gigabytes of ram.