summaryrefslogtreecommitdiffstats
path: root/src/tools/rust-analyzer/docs/user
diff options
context:
space:
mode:
Diffstat (limited to 'src/tools/rust-analyzer/docs/user')
-rw-r--r--src/tools/rust-analyzer/docs/user/manual.adoc93
1 files changed, 51 insertions, 42 deletions
diff --git a/src/tools/rust-analyzer/docs/user/manual.adoc b/src/tools/rust-analyzer/docs/user/manual.adoc
index b5c095fd9..5dafd1a4c 100644
--- a/src/tools/rust-analyzer/docs/user/manual.adoc
+++ b/src/tools/rust-analyzer/docs/user/manual.adoc
@@ -64,22 +64,8 @@ You can install the latest release of the plugin from
https://marketplace.visualstudio.com/items?itemName=rust-lang.rust-analyzer[the marketplace].
Note that the plugin may cause conflicts with the
-https://marketplace.visualstudio.com/items?itemName=rust-lang.rust[official Rust plugin].
-It is recommended to disable the Rust plugin when using the rust-analyzer extension.
-
-By default, the plugin will prompt you to download the matching version of the server as well:
-
-image::https://user-images.githubusercontent.com/9021944/75067008-17502500-54ba-11ea-835a-f92aac50e866.png[]
-
-[NOTE]
-====
-To disable this notification put the following to `settings.json`
-
-[source,json]
-----
-{ "rust-analyzer.updates.askBeforeDownload": false }
-----
-====
+https://marketplace.visualstudio.com/items?itemName=rust-lang.rust[previous official Rust plugin].
+The latter is no longer maintained and should be uninstalled.
The server binary is stored in the extension install directory, which starts with `rust-lang.rust-analyzer-` and is located under:
@@ -141,6 +127,9 @@ If you're not using Code, you can compile and install only the LSP server:
$ cargo xtask install --server
----
+Make sure that `.cargo/bin` is in `$PATH` and precedes paths where `rust-analyzer` may also be installed.
+Specifically, `rustup` includes a proxy called `rust-analyzer`, which can cause problems if you're planning to use a source build or even a downloaded binary.
+
=== rust-analyzer Language Server Binary
Other editors generally require the `rust-analyzer` binary to be in `$PATH`.
@@ -280,12 +269,12 @@ Also see the https://emacs-lsp.github.io/lsp-mode/page/lsp-rust-analyzer/[rust-a
Note the excellent https://robert.kra.hn/posts/2021-02-07_rust-with-emacs/[guide] from https://github.com/rksm[@rksm] on how to set-up Emacs for Rust development with LSP mode and several other packages.
-=== Vim/NeoVim
+=== Vim/Neovim
Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.
Not needed if the extension can install/update it on its own, coc-rust-analyzer is one example.
-There are several LSP client implementations for vim or neovim:
+There are several LSP client implementations for Vim or Neovim:
==== coc-rust-analyzer
@@ -308,7 +297,7 @@ Note: for code actions, use `coc-codeaction-cursor` and `coc-codeaction-selected
https://github.com/autozimu/LanguageClient-neovim[here]
* The GitHub project wiki has extra tips on configuration
-2. Configure by adding this to your vim/neovim config file (replacing the existing Rust-specific line if it exists):
+2. Configure by adding this to your Vim/Neovim config file (replacing the existing Rust-specific line if it exists):
+
[source,vim]
----
@@ -335,7 +324,7 @@ let g:ale_linters = {'rust': ['analyzer']}
==== nvim-lsp
-NeoVim 0.5 has built-in language server support.
+Neovim 0.5 has built-in language server support.
For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lspconfig#rust_analyzer[neovim/nvim-lspconfig].
Once `neovim/nvim-lspconfig` is installed, use `+lua require'lspconfig'.rust_analyzer.setup({})+` in your `init.vim`.
@@ -376,7 +365,7 @@ EOF
See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started.
-Check out https://github.com/simrat39/rust-tools.nvim for a batteries included rust-analyzer setup for neovim.
+Check out https://github.com/simrat39/rust-tools.nvim for a batteries included rust-analyzer setup for Neovim.
==== vim-lsp
@@ -460,27 +449,24 @@ You'll need to close and reopen all .rs and Cargo files, or to restart the IDE,
Support for the language server protocol is built into Kate through the LSP plugin, which is included by default.
It is preconfigured to use rust-analyzer for Rust sources since Kate 21.12.
-Earlier versions allow you to use rust-analyzer through a simple settings change.
-In the LSP Client settings of Kate, copy the content of the third tab "default parameters" to the second tab "server configuration".
-Then in the configuration replace:
-[source,json]
-----
- "rust": {
- "command": ["rls"],
- "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"],
- "url": "https://github.com/rust-lang/rls",
- "highlightingModeRegex": "^Rust$"
- },
-----
-With
+To change rust-analyzer config options, start from the following example and put it into Kate's "User Server Settings" tab (located under the LSP Client settings):
[source,json]
----
+{
+ "servers": {
"rust": {
- "command": ["rust-analyzer"],
- "rootIndicationFileNames": ["Cargo.lock", "Cargo.toml"],
- "url": "https://github.com/rust-lang/rust-analyzer",
- "highlightingModeRegex": "^Rust$"
- },
+ "initializationOptions": {
+ "cachePriming": {
+ "enable": false
+ },
+ "check": {
+ "allTargets": false
+ },
+ "checkOnSave": false
+ }
+ }
+ }
+}
----
Then click on apply, and restart the LSP server for your rust project.
@@ -933,17 +919,17 @@ For example:
More about `when` clause contexts https://code.visualstudio.com/docs/getstarted/keybindings#_when-clause-contexts[here].
==== Setting runnable environment variables
-You can use "rust-analyzer.runnableEnv" setting to define runnable environment-specific substitution variables.
+You can use "rust-analyzer.runnables.extraEnv" setting to define runnable environment-specific substitution variables.
The simplest way for all runnables in a bunch:
```jsonc
-"rust-analyzer.runnableEnv": {
+"rust-analyzer.runnables.extraEnv": {
"RUN_SLOW_TESTS": "1"
}
```
Or it is possible to specify vars more granularly:
```jsonc
-"rust-analyzer.runnableEnv": [
+"rust-analyzer.runnables.extraEnv": [
{
// "mask": null, // null mask means that this rule will be applied for all runnables
env: {
@@ -963,6 +949,29 @@ Or it is possible to specify vars more granularly:
You can use any valid regular expression as a mask.
Also note that a full runnable name is something like *run bin_or_example_name*, *test some::mod::test_name* or *test-mod some::mod*, so it is possible to distinguish binaries, single tests, and test modules with this masks: `"^run"`, `"^test "` (the trailing space matters!), and `"^test-mod"` respectively.
+If needed, you can set different values for different platforms:
+```jsonc
+"rust-analyzer.runnables.extraEnv": [
+ {
+ "platform": "win32", // windows only
+ env: {
+ "APP_DATA": "windows specific data"
+ }
+ },
+ {
+ "platform": ["linux"],
+ "env": {
+ "APP_DATA": "linux data",
+ }
+ },
+ { // for all platforms
+ "env": {
+ "APP_COMMON_DATA": "xxx",
+ }
+ }
+]
+```
+
==== Compiler feedback from external commands
Instead of relying on the built-in `cargo check`, you can configure Code to run a command in the background and use the `$rustc-watch` problem matcher to generate inline error markers from its output.