Skip to content
This repository was archived by the owner on Nov 18, 2022. It is now read-only.

Commit fc2eb5c

Browse files
authored
Merge pull request #793 from rust-lang/support-rust-analyzer
Support rust-analyzer as alternate LSP engine
2 parents 5480e00 + 687af89 commit fc2eb5c

12 files changed

+970
-331
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
### Unreleased
22

3+
* Support rust-analyzer as an alternate LSP server
34
* Bump required VSCode version to 1.43, use language server protocol (LSP) v3.15
45

56
### 0.7.5 - 2020-05-06

README.md

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,41 @@ Adds language support for Rust to Visual Studio Code. Supports:
1414
* snippets
1515
* build tasks
1616

17+
Rust support is powered by a separate [language server](https://microsoft.github.io/language-server-protocol/overviews/lsp/overview/)
18+
- either by the official [Rust Language Server](https://github.com/rust-lang/rls) (RLS) or
19+
[rust-analyzer](https://github.com/rust-lang/rls), depending on the user's
20+
preference. If you don't have it installed, the extension will install it for
21+
you (with permission).
1722

18-
Rust support is powered by the [Rust Language Server](https://github.com/rust-lang/rls)
19-
(RLS). If you don't have it installed, the extension will install it for you.
20-
21-
This extension is built and maintained by the RLS team, part of the Rust
23+
This extension is built and maintained by the Rust
2224
[IDEs and editors team](https://www.rust-lang.org/en-US/team.html#Dev-tools-team).
23-
It is the reference client implementation for the RLS. Our focus is on providing
24-
a stable, high quality extension that makes best use of the RLS. We aim to
25-
support as many features as possible, but our priority is supporting the
26-
essential features as well as possible.
25+
Our focus is on providing
26+
a stable, high quality extension that makes the best use of the respective language
27+
server. We aim to support as many features as possible, but our priority is
28+
supporting the essential features as well as possible.
29+
30+
For support, please file an
31+
[issue on the repo](https://github.com/rust-lang/rls-vscode/issues/new)
32+
or talk to us [on Discord](https://discordapp.com/invite/rust-lang).
33+
For RLS, there is also some [troubleshooting and debugging](https://github.com/rust-lang/rls/blob/master/debugging.md) advice.
2734

28-
For support, please file an [issue on the repo](https://github.com/rust-lang/rls-vscode/issues/new)
29-
or talk to us [on Discord](https://discordapp.com/invite/rust-lang). There is also some
30-
[troubleshooting and debugging](https://github.com/rust-lang/rls/blob/master/debugging.md)
31-
advice.
35+
## Contribution
3236

3337
Contributing code, tests, documentation, and bug reports is appreciated! For
34-
more details on building and debugging, etc., see [contributing.md](contributing.md).
38+
more details see [contributing.md](contributing.md).
3539

3640

3741
## Quick start
3842

39-
* Install [rustup](https://www.rustup.rs/) (Rust toolchain manager).
40-
* Install this extension from [the VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust)
43+
1. Install [rustup](https://www.rustup.rs/) (Rust toolchain manager).
44+
2. Install this extension from [the VSCode Marketplace](https://marketplace.visualstudio.com/items?itemName=rust-lang.rust)
4145
(or by entering `ext install rust-lang.rust` at the command palette <kbd>Ctrl</kbd>+<kbd>P</kbd>).
42-
* (Skip this step if you already have Rust projects that you'd like to work on.)
46+
3. (Skip this step if you already have Rust projects that you'd like to work on.)
4347
Create a new Rust project by following [these instructions](https://doc.rust-lang.org/book/ch01-03-hello-cargo.html).
44-
* Open a Rust project (`File > Add Folder to Workspace...`). Open the folder for the whole
45-
project (i.e., the folder containing 'Cargo.toml'), not the 'src' folder.
46-
* You'll be prompted to install the RLS. Once installed, the RLS should start
47-
building your project.
48+
4. Open a Rust project (`File > Add Folder to Workspace...`). Open the folder for the whole
49+
project (i.e., the folder containing `Cargo.toml`, not the `src` folder).
50+
5. You'll be prompted to install the Rust server. Once installed, it should start
51+
analyzing your project (RLS will also have to to build the project).
4852

4953

5054
## Configuration
@@ -53,24 +57,25 @@ This extension provides options in VSCode's configuration settings. These
5357
include `rust.*`, which are passed directly to RLS, and the `rust-client.*`
5458
, which mostly deal with how to spawn it or debug it.
5559
You can find the settings under `File > Preferences > Settings`; they all
56-
have Intellisense help.
60+
have IntelliSense help.
5761

58-
Some highlights:
62+
Examples:
5963

6064
* `rust.show_warnings` - set to false to silence warnings in the editor.
6165
* `rust.all_targets` - build and index code for all targets (i.e., integration tests, examples, and benches)
6266
* `rust.cfg_test` - build and index test code (i.e., code with `#[cfg(test)]`/`#[test]`)
63-
6467
* `rust-client.channel` - specifies from which toolchain the RLS should be spawned
6568

69+
> **_TIP:_** To select the underlying language server, set `rust-client.engine` accordingly!
70+
6671
## Features
6772

6873
### Snippets
6974

70-
Snippets are code templates which expand into common boilerplate. Intellisense
71-
includes snippet names as options when you type; select one by pressing 'enter'.
72-
You can move to the next 'hole' in the template by pressing 'tab'. We provide
73-
the following snippets:
75+
Snippets are code templates which expand into common boilerplate. IntelliSense
76+
includes snippet names as options when you type; select one by pressing
77+
<kbd>enter</kbd>. You can move to the next snippet 'hole' in the template by
78+
pressing <kbd>tab</kbd>. We provide the following snippets:
7479

7580
* `for` - a for loop
7681
* `macro_rules` - declare a macro
@@ -102,18 +107,25 @@ to `true`. Find it under `File > Preferences > Settings`.
102107
## Requirements
103108

104109
* [Rustup](https://www.rustup.rs/),
105-
* A Rust toolchain (the extension will configure this for you, with
106-
permission),
107-
* `rls`, `rust-src`, and `rust-analysis` components (the
108-
extension will install these for you, with permission).
110+
* A Rust toolchain (the extension will configure this for you, with permission),
111+
* `rls`, `rust-src`, and `rust-analysis` components (the extension will install
112+
these for you, with permission). Only `rust-src` is required when using
113+
rust-analyzer.
109114

110115

111116
## Implementation
112117

113-
This extension almost exclusively uses the RLS for its feature support (syntax
114-
highlighting, snippets, and build tasks are provided client-side). The RLS uses
115-
the Rust compiler (`rustc`) to get data about Rust programs. It uses Cargo to
116-
manage building. Both Cargo and `rustc` are run in-process by the RLS. Formatting
117-
and code completion are provided by `rustfmt` and Racer, again both of these are
118-
run in-process by the RLS.
118+
Both language servers can use Cargo to get more information about Rust projects
119+
and both use [`rustfmt`](https://github.com/rust-lang/rustfmt/) extensively to
120+
format the code.
121+
122+
[RLS](https://github.com/rust-lang/rls) uses Cargo and also the Rust compiler
123+
([`rustc`](https://github.com/rust-lang/rust/)) in a more direct fashion, where
124+
it builds the project and reuses the data computed by the compiler itself. To
125+
provide code completion it uses a separate tool called
126+
[`racer`](https://github.com/racer-rust/racer).
119127

128+
[Rust Analyzer](https://github.com/rust-analyzer/rust-analyzer) is a separate
129+
compiler frontend for the Rust language that doesn't use the Rust compiler
130+
([`rustc`](https://github.com/rust-lang/rust/)) directly but rather performs its
131+
own analysis that's tailor-fitted to the editor/IDE use case.

package-lock.json

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,15 @@
5050
"installDevExtension": "npm install && ./node_modules/.bin/vsce package -o ./out/rls-vscode-dev.vsix && code --install-extension ./out/rls-vscode-dev.vsix"
5151
},
5252
"dependencies": {
53+
"node-fetch": "^2.6.0",
5354
"vscode-languageclient": "^6.0.0"
5455
},
5556
"devDependencies": {
5657
"@types/chai": "^4.2.11",
5758
"@types/glob": "^7.1.1",
5859
"@types/mocha": "^5.2.6",
5960
"@types/node": "^12.8.1",
61+
"@types/node-fetch": "^2.5.7",
6062
"@types/vscode": "^1.43.0",
6163
"chai": "^4.2.0",
6264
"glob": "^7.1.4",
@@ -87,26 +89,26 @@
8789
"commands": [
8890
{
8991
"command": "rls.update",
90-
"title": "Update the RLS",
91-
"description": "Use Rustup to update Rust, the RLS, and required data",
92+
"title": "Update the current Rust toolchain",
93+
"description": "Use Rustup to the current Rust toolchain, along with its components",
9294
"category": "Rust"
9395
},
9496
{
9597
"command": "rls.restart",
96-
"title": "Restart the RLS",
98+
"title": "Restart the Rust server",
9799
"description": "Sometimes, it's just best to try turning it off and on again",
98100
"category": "Rust"
99101
},
100102
{
101103
"command": "rls.start",
102-
"title": "Start the RLS",
103-
"description": "Start the RLS (when rust-client.autoStartRls is false or when manually stopped)",
104+
"title": "Start the Rust server",
105+
"description": "Start the Rust server (when rust-client.autoStartRls is false or when manually stopped)",
104106
"category": "Rust"
105107
},
106108
{
107109
"command": "rls.stop",
108-
"title": "Stop the RLS",
109-
"description": "Stop the RLS for a workspace until manually started again",
110+
"title": "Stop the Rust server",
111+
"description": "Stop the Rust server for a workspace until manually started again",
110112
"category": "Rust"
111113
}
112114
],
@@ -160,6 +162,20 @@
160162
"type": "object",
161163
"title": "Rust configuration",
162164
"properties": {
165+
"rust-client.engine": {
166+
"type": "string",
167+
"enum": [
168+
"rls",
169+
"rust-analyzer"
170+
],
171+
"enumDescriptions": [
172+
"Use the Rust Language Server (RLS)",
173+
"Use the rust-analyzer language server (NOTE: not fully supported yet)"
174+
],
175+
"default": "rls",
176+
"description": "The underlying LSP server used to provide IDE support for Rust projects.",
177+
"scope": "window"
178+
},
163179
"rust-client.logToFile": {
164180
"type": "boolean",
165181
"default": false,
@@ -448,6 +464,22 @@
448464
"default": true,
449465
"description": "Show additional context in hover tooltips when available. This is often the type local variable declaration.",
450466
"scope": "resource"
467+
},
468+
"rust.rust-analyzer": {
469+
"type": "object",
470+
"default": {},
471+
"description": "Settings passed down to rust-analyzer server",
472+
"scope": "resource"
473+
},
474+
"rust.rust-analyzer.releaseTag": {
475+
"type": "string",
476+
"default": "nightly",
477+
"description": "Which binary release to download and use"
478+
},
479+
"rust.rust-analyzer.path": {
480+
"type": ["string", "null"],
481+
"default": null,
482+
"description": "When specified, uses the rust-analyzer binary at a given path"
451483
}
452484
}
453485
}

0 commit comments

Comments
 (0)