Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify rust-analyzer binary install #4158

Merged
merged 4 commits into from
Apr 26, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Clarify rust-analyzer binary install
  • Loading branch information
zoechi authored Apr 26, 2020
commit 49d494c03307cff75057a856eadc5ebb5ff1ea9d
30 changes: 23 additions & 7 deletions docs/user/readme.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 23,7 @@ https://github.com/rust-analyzer/rust-analyzer/blob/master/docs/user/readme.adoc

== Installation

In theory, one should be able to just install the server binary and have it automatically work with any editor.
In theory, one should be able to just install the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> and have it automatically work with any editor.
We are not there yet, so some editor specific setup is required.

Additionally, rust-analyzer needs the sources of the standard library.
Expand Down Expand Up @@ -94,7 94,8 @@ $ git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyz
$ cargo xtask install
----

You'll need Cargo, nodejs and npm for this.
You'll need Cargo, xtask, nodejs and npm for this.
Cargo-xtask can be found at https://github.com/matklad/cargo-xtask
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The xtask binary is part of the rust-analyzer repository. It'll automatically build when calling cargo xtask from inside the rust-analyzer folder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out. I changed it.


Note that installing via `xtask install` does not work for VS Code Remote, instead you'll need to install the `.vsix` manually.

Expand All @@ -108,18 109,29 @@ Here are some useful self-diagnostic commands:
* To log all LSP requests, add `"rust-analyzer.trace.server": "verbose"` to the settings and look for `Server Trace` in the panel.
* To enable client-side logging, add `"rust-analyzer.trace.extension": true` to the settings and open the `Console` tab of VS Code developer tools.

=== Language Server Binary
=== rust-analyzer Language Server Binary

Other editors generally require the `rust-analyzer` binary to be in `$PATH`.
You can download the pre-built binary from the https://github.com/rust-analyzer/rust-analyzer/releases[releases] page. Typically, you then need to rename the binary for your platform, e.g. `rust-analyzer-mac` if you're on Mac OS, to `rust-analzyer` and make it executable in addition to moving it into a directory in your `$PATH`.

On Linux to install the `rust-analyzer` binary into `~/.cargo/bin` which usually is already added to `$PATH`, this commands could be used
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think putting binaries not installed by cargo into ~/.cargo/bin is a good idea.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What fo you think is a better place?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe ~/.local/bin? There are a lot of programs that install themselves there. It isn't in PATH by default though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. I also think this is a better suggestion. I changed it.


[source,bash]
----
$ curl -L https://github.com/rust-analyzer/rust-analyzer/releases/latest/download/rust-analyzer-linux -o ~/.cargo/bin/rust-analyzer
$ chmod x ~/.cargo/bin/rust-analyzer
----

Alternatively, you can install it from source using the following command:

[source,bash]
----
$ git clone https://github.com/rust-analyzer/rust-analyzer.git && cd rust-analyzer
$ cargo xtask install --server
----

Cargo-xtask can be found at https://github.com/matklad/cargo-xtask

If your editor can't find the binary even though the binary is on your `$PATH`, the likely explanation is that it doesn't see the same `$PATH` as the shell, see https://github.com/rust-analyzer/rust-analyzer/issues/1811[this issue]. On Unix, running the editor from a shell or changing the `.desktop` file to set the environment should help.

==== Arch Linux
Expand All @@ -139,15 151,19 @@ $ yay -S rust-analyzer-bin

=== Emacs

Emacs support is maintained https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-rust.el[upstream].
Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.

1. Install the most recent version of `emacs-lsp` package by following the instructions https://github.com/emacs-lsp/lsp-mode[here].
Emacs support is maintained as part of the https://github.com/emacs-lsp/lsp-mode[Emacs-LSP] package in https://github.com/emacs-lsp/lsp-mode/blob/master/lsp-rust.el[lsp-rust.el].

1. Install the most recent version of `emacs-lsp` package by following the https://github.com/emacs-lsp/lsp-mode[Emacs-LSP instructions].
2. Set `lsp-rust-server` to `'rust-analyzer`.
3. Run `lsp` in a Rust buffer.
4. (Optionally) bind commands like `lsp-rust-analyzer-join-lines`, `lsp-extend-selection` and `lsp-rust-analyzer-expand-macro` to keys.

=== Vim

Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.

The are several LSP client implementations for vim:

==== coc-rust-analyzer
Expand Down Expand Up @@ -205,7 221,7 @@ Once `neovim/nvim-lsp` is installed, use ` lua require'nvim_lsp'.rust_analyzer.s

=== Sublime Text 3

Prerequisites: You have installed the <<language-server-binary,`rust-analyzer` binary>>.
Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.

You also need the `LSP` package. To install it:

Expand All @@ -218,7 234,7 @@ Finally, with your Rust project open, in the command palette, run `LSP: Enable L

If it worked, you should see "rust-analzyer, Line X, Column Y" on the left side of the bottom bar, and after waiting a bit, functionality like tooltips on hovering over variables should become available.

If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<language-server-binary,section on installing the language server binary>>.
If you get an error saying `No such file or directory: 'rust-analyzer'`, see the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>> section on installing the language server binary.

== Usage

Expand Down