2019-03-20 09:17:12 +00:00
The main interface to rust-analyzer is the
[LSP ](https://microsoft.github.io/language-server-protocol/ ) implementation. To
install lsp server, use `cargo install-lsp` , which is a shorthand for `cargo
install --package ra_lsp_server`. The binary is named `ra_lsp_server` , you
should be able to use it with any LSP-compatible editor. We use custom
extensions to LSP, so special client-side support is required to take full
advantage of rust-analyzer. This repository contains support code for VS Code
and Emacs.
Rust Analyzer needs sources of rust standard library to work, so you might need
to execute
```
$ rustup component add rust-src
```
2019-03-20 09:21:55 +00:00
See [./features.md ](./features.md ) document for a list of features that are available.
2019-03-20 09:17:12 +00:00
## VS Code
2019-02-10 21:09:33 +00:00
2019-03-13 14:23:22 +00:00
Prerequisites:
2019-02-10 21:09:33 +00:00
In order to build the VS Code plugin, you need to have node.js and npm with
a minimum version of 10 installed. Please refer to
[node.js and npm documentation ](https://nodejs.org ) for installation instructions.
2019-02-12 15:28:39 +00:00
You will also need the most recent version of VS Code: we don't try to
maintain compatibility with older versions yet.
2019-02-10 21:09:33 +00:00
The experimental VS Code plugin can then be built and installed by executing the
following commands:
2018-09-16 12:36:09 +00:00
```
2019-01-12 17:02:16 +00:00
$ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1
2018-12-27 14:56:07 +00:00
$ cd rust-analyzer
2018-09-16 12:36:09 +00:00
$ cargo install-code
```
2019-05-11 11:22:44 +00:00
The automatic installation is expected to *just work* for common cases, if it
doesn't, report bugs!
2019-05-30 14:10:10 +00:00
If you have an unusual setup (for example, `code` is not in the `PATH` ), you
2019-05-11 11:22:44 +00:00
should adapt these manual installation instructions:
```
$ git clone https://github.com/rust-analyzer/rust-analyzer.git --depth 1
$ cd rust-analyzer
$ cargo install --path ./crates/ra_lsp_server/ --force
$ cd ./editors/code
$ npm install
$ ./node_modules/vsce/out/vsce package
$ code --install-extension ./ra-lsp-0.0.1.vsix
```
2018-09-16 12:36:09 +00:00
It's better to remove existing Rust plugins to avoid interference.
2019-03-20 09:17:12 +00:00
Beyond basic LSP features, there are some extension commands which you can
2019-03-20 09:21:55 +00:00
invoke via < kbd > Ctrl+Shift+P</ kbd > or bind to a shortcut. See [./features.md ](./features.md )
2019-03-20 09:17:12 +00:00
for details.
2019-01-13 12:04:05 +00:00
2019-03-20 09:17:12 +00:00
### Settings
2019-01-13 12:04:05 +00:00
2019-03-20 09:17:12 +00:00
* `rust-analyzer.highlightingOn` : enables experimental syntax highlighting
* `rust-analyzer.showWorkspaceLoadedNotification` : to ease troubleshooting, a
notification is shown by default when a workspace is loaded
* `rust-analyzer.enableEnhancedTyping` : by default, rust-analyzer intercepts
2019-05-22 12:04:30 +00:00
`Enter` key to make it easier to continue comments. Note that it may conflict with VIM emulation plugin.
2019-03-20 09:17:12 +00:00
* `rust-analyzer.raLspServerPath` : path to `ra_lsp_server` executable
* `rust-analyzer.enableCargoWatchOnStartup` : prompt to install & enable `cargo
watch` for live error highlighting (note, this **does not** use rust-analyzer)
2019-05-11 11:22:44 +00:00
* `rust-analyzer.cargo-watch.check-arguments` : cargo-watch check arguments.
(e.g: `--features="shumway,pdf"` will run as `cargo watch -x "check --features="shumway,pdf""` )
2019-03-20 09:17:12 +00:00
* `rust-analyzer.trace.server` : enables internal logging
2019-04-02 05:07:40 +00:00
* `rust-analyzer.trace.cargo-watch` : enables cargo-watch logging
2019-01-13 12:04:05 +00:00
2018-10-09 13:00:20 +00:00
2019-03-20 09:17:12 +00:00
## Emacs
2018-09-16 12:36:09 +00:00
2019-03-20 09:17:12 +00:00
Prerequisites:
2019-01-13 14:13:54 +00:00
2019-03-20 09:17:12 +00:00
`emacs-lsp` , `dash` and `ht` packages.
2019-01-13 14:13:54 +00:00
2019-03-20 09:17:12 +00:00
Installation:
2019-01-13 14:13:54 +00:00
2019-03-20 09:17:12 +00:00
* add
[ra-emacs-lsp.el ](https://github.com/rust-analyzer/rust-analyzer/blob/69ee5c9c5ef212f7911028c9ddf581559e6565c3/editors/emacs/ra-emacs-lsp.el )
to load path and require it in `init.el`
* run `lsp` in a rust buffer
2019-03-20 12:25:05 +00:00
* (Optionally) bind commands like `rust-analyzer-join-lines` or `rust-analyzer-extend-selection` to keys
2019-04-19 09:50:01 +00:00
2019-05-25 19:24:47 +00:00
## Vim and NeoVim
* Install coc.nvim by following the instructions at [coc.nvim]
2019-06-18 14:25:59 +00:00
- You will need nodejs installed.
- You may want to include some of the sample vim configurations [from here][coc-vim-conf]
- Note that if you use a plugin manager other than `vim-plug` , you may need to manually
checkout the `release` branch wherever your plugin manager cloned it. Otherwise you will
get errors about a missing javascript file.
2019-05-25 19:24:47 +00:00
* Add rust analyzer using: [coc.nvim wiki][coc-wiki]
2019-06-18 14:25:59 +00:00
- Use `:CocConfig` in command mode to edit the config file.
2019-05-25 19:24:47 +00:00
```jsonc
"languageserver": {
"rust": {
"command": "ra_lsp_server",
"filetypes": ["rust"],
"rootPatterns": ["Cargo.toml"]
}
2019-06-18 14:25:59 +00:00
}
```
For those not familiar with js, the whole file should be enclosed in `{` and `}` , with all of your config options in between. So for example, if rust-analyzer was your only language server, you could do the following:
```jsonc
{
"languageserver": {
"rust": {
"command": "ra_lsp_server",
"filetypes": ["rust"],
"rootPatterns": ["Cargo.toml"]
}
}
2019-05-25 19:24:47 +00:00
}
```
[coc.nvim]: https://github.com/neoclide/coc.nvim
[coc-wiki]: https://github.com/neoclide/coc.nvim/wiki/Language-servers#rust
2019-06-18 14:25:59 +00:00
[coc-vim-conf]: https://github.com/neoclide/coc.nvim/#example-vim-configuration
2019-05-25 19:24:47 +00:00
2019-04-19 09:50:01 +00:00
## Sublime Text 3
Prequisites:
`LSP` package.
Installation:
* Invoke the command palette with < kbd > Ctrl+Shift+P</ kbd >
* Type `LSP Settings` to open the LSP preferences editor
* Add the following LSP client definition to your settings:
```json
"rust-analyzer": {
"command": ["rustup", "run", "stable", "ra_lsp_server"],
"languageId": "rust",
"scopes": ["source.rust"],
"syntaxes": [
"Packages/Rust/Rust.sublime-syntax",
"Packages/Rust Enhanced/RustEnhanced.sublime-syntax"
]
}
```
* You can now invoke the command palette and type LSP enable to locally/globally enable the rust-analyzer LSP (type LSP enable, then choose either locally or globally, then select rust-analyzer)