diff options
Diffstat (limited to 'docs/user')
-rw-r--r-- | docs/user/generated_config.adoc | 14 | ||||
-rw-r--r-- | docs/user/manual.adoc | 125 |
2 files changed, 128 insertions, 11 deletions
diff --git a/docs/user/generated_config.adoc b/docs/user/generated_config.adoc index a76c99d1e..f91e04c31 100644 --- a/docs/user/generated_config.adoc +++ b/docs/user/generated_config.adoc | |||
@@ -7,7 +7,7 @@ | |||
7 | [[rust-analyzer.cargo.autoreload]]rust-analyzer.cargo.autoreload (default: `true`):: | 7 | [[rust-analyzer.cargo.autoreload]]rust-analyzer.cargo.autoreload (default: `true`):: |
8 | Automatically refresh project info via `cargo metadata` on `Cargo.toml` changes. | 8 | Automatically refresh project info via `cargo metadata` on `Cargo.toml` changes. |
9 | [[rust-analyzer.cargo.allFeatures]]rust-analyzer.cargo.allFeatures (default: `false`):: | 9 | [[rust-analyzer.cargo.allFeatures]]rust-analyzer.cargo.allFeatures (default: `false`):: |
10 | Activate all available features. | 10 | Activate all available features (`--all-features`). |
11 | [[rust-analyzer.cargo.features]]rust-analyzer.cargo.features (default: `[]`):: | 11 | [[rust-analyzer.cargo.features]]rust-analyzer.cargo.features (default: `[]`):: |
12 | List of features to activate. | 12 | List of features to activate. |
13 | [[rust-analyzer.cargo.loadOutDirsFromCheck]]rust-analyzer.cargo.loadOutDirsFromCheck (default: `false`):: | 13 | [[rust-analyzer.cargo.loadOutDirsFromCheck]]rust-analyzer.cargo.loadOutDirsFromCheck (default: `false`):: |
@@ -21,9 +21,9 @@ | |||
21 | [[rust-analyzer.checkOnSave.enable]]rust-analyzer.checkOnSave.enable (default: `true`):: | 21 | [[rust-analyzer.checkOnSave.enable]]rust-analyzer.checkOnSave.enable (default: `true`):: |
22 | Run specified `cargo check` command for diagnostics on save. | 22 | Run specified `cargo check` command for diagnostics on save. |
23 | [[rust-analyzer.checkOnSave.allFeatures]]rust-analyzer.checkOnSave.allFeatures (default: `null`):: | 23 | [[rust-analyzer.checkOnSave.allFeatures]]rust-analyzer.checkOnSave.allFeatures (default: `null`):: |
24 | Check with all features (will be passed as `--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`. | 24 | Check with all features (`--all-features`). Defaults to `#rust-analyzer.cargo.allFeatures#`. |
25 | [[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`):: | 25 | [[rust-analyzer.checkOnSave.allTargets]]rust-analyzer.checkOnSave.allTargets (default: `true`):: |
26 | Check all targets and tests (will be passed as `--all-targets`). | 26 | Check all targets and tests (`--all-targets`). |
27 | [[rust-analyzer.checkOnSave.command]]rust-analyzer.checkOnSave.command (default: `"check"`):: | 27 | [[rust-analyzer.checkOnSave.command]]rust-analyzer.checkOnSave.command (default: `"check"`):: |
28 | Cargo command to use for `cargo check`. | 28 | Cargo command to use for `cargo check`. |
29 | [[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`):: | 29 | [[rust-analyzer.checkOnSave.noDefaultFeatures]]rust-analyzer.checkOnSave.noDefaultFeatures (default: `null`):: |
@@ -56,6 +56,8 @@ | |||
56 | List of warnings that should be displayed with hint severity.\n\nThe warnings will be indicated by faded text or three dots in code and will not show up in the `Problems Panel`. | 56 | List of warnings that should be displayed with hint severity.\n\nThe warnings will be indicated by faded text or three dots in code and will not show up in the `Problems Panel`. |
57 | [[rust-analyzer.files.watcher]]rust-analyzer.files.watcher (default: `"client"`):: | 57 | [[rust-analyzer.files.watcher]]rust-analyzer.files.watcher (default: `"client"`):: |
58 | Controls file watching implementation. | 58 | Controls file watching implementation. |
59 | [[rust-analyzer.files.excludeDirs]]rust-analyzer.files.excludeDirs (default: `[]`):: | ||
60 | These directories will be ignored by rust-analyzer. | ||
59 | [[rust-analyzer.hoverActions.debug]]rust-analyzer.hoverActions.debug (default: `true`):: | 61 | [[rust-analyzer.hoverActions.debug]]rust-analyzer.hoverActions.debug (default: `true`):: |
60 | Whether to show `Debug` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set. | 62 | Whether to show `Debug` action. Only applies when `#rust-analyzer.hoverActions.enable#` is set. |
61 | [[rust-analyzer.hoverActions.enable]]rust-analyzer.hoverActions.enable (default: `true`):: | 63 | [[rust-analyzer.hoverActions.enable]]rust-analyzer.hoverActions.enable (default: `true`):: |
@@ -86,10 +88,12 @@ | |||
86 | Whether to show `Run` lens. Only applies when `#rust-analyzer.lens.enable#` is set. | 88 | Whether to show `Run` lens. Only applies when `#rust-analyzer.lens.enable#` is set. |
87 | [[rust-analyzer.lens.methodReferences]]rust-analyzer.lens.methodReferences (default: `false`):: | 89 | [[rust-analyzer.lens.methodReferences]]rust-analyzer.lens.methodReferences (default: `false`):: |
88 | Whether to show `Method References` lens. Only applies when `#rust-analyzer.lens.enable#` is set. | 90 | Whether to show `Method References` lens. Only applies when `#rust-analyzer.lens.enable#` is set. |
91 | [[rust-analyzer.lens.references]]rust-analyzer.lens.references (default: `false`):: | ||
92 | Whether to show `References` lens. Only applies when `#rust-analyzer.lens.enable#` is set. | ||
89 | [[rust-analyzer.linkedProjects]]rust-analyzer.linkedProjects (default: `[]`):: | 93 | [[rust-analyzer.linkedProjects]]rust-analyzer.linkedProjects (default: `[]`):: |
90 | Disable project auto-discovery in favor of explicitly specified set of projects.\n\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format. | 94 | Disable project auto-discovery in favor of explicitly specified set of projects.\n\nElements must be paths pointing to `Cargo.toml`, `rust-project.json`, or JSON objects in `rust-project.json` format. |
91 | [[rust-analyzer.lruCapacity]]rust-analyzer.lruCapacity (default: `null`):: | 95 | [[rust-analyzer.lruCapacity]]rust-analyzer.lruCapacity (default: `null`):: |
92 | Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. | 96 | Number of syntax trees rust-analyzer keeps in memory. Defaults to 128. |
93 | [[rust-analyzer.notifications.cargoTomlNotFound]]rust-analyzer.notifications.cargoTomlNotFound (default: `true`):: | 97 | [[rust-analyzer.notifications.cargoTomlNotFound]]rust-analyzer.notifications.cargoTomlNotFound (default: `true`):: |
94 | Whether to show `can't find Cargo.toml` error message. | 98 | Whether to show `can't find Cargo.toml` error message. |
95 | [[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `false`):: | 99 | [[rust-analyzer.procMacro.enable]]rust-analyzer.procMacro.enable (default: `false`):: |
@@ -101,7 +105,7 @@ | |||
101 | [[rust-analyzer.runnables.cargoExtraArgs]]rust-analyzer.runnables.cargoExtraArgs (default: `[]`):: | 105 | [[rust-analyzer.runnables.cargoExtraArgs]]rust-analyzer.runnables.cargoExtraArgs (default: `[]`):: |
102 | Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be `--release`. | 106 | Additional arguments to be passed to cargo for runnables such as tests or binaries.\nFor example, it may be `--release`. |
103 | [[rust-analyzer.rustcSource]]rust-analyzer.rustcSource (default: `null`):: | 107 | [[rust-analyzer.rustcSource]]rust-analyzer.rustcSource (default: `null`):: |
104 | Path to the rust compiler sources, for usage in rustc_private projects. | 108 | Path to the rust compiler sources, for usage in rustc_private projects, or "discover" to try to automatically find it. |
105 | [[rust-analyzer.rustfmt.extraArgs]]rust-analyzer.rustfmt.extraArgs (default: `[]`):: | 109 | [[rust-analyzer.rustfmt.extraArgs]]rust-analyzer.rustfmt.extraArgs (default: `[]`):: |
106 | Additional arguments to `rustfmt`. | 110 | Additional arguments to `rustfmt`. |
107 | [[rust-analyzer.rustfmt.overrideCommand]]rust-analyzer.rustfmt.overrideCommand (default: `null`):: | 111 | [[rust-analyzer.rustfmt.overrideCommand]]rust-analyzer.rustfmt.overrideCommand (default: `null`):: |
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index 990b11859..9f28237ff 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc | |||
@@ -194,6 +194,8 @@ $ pacman -S rust-analyzer | |||
194 | 194 | ||
195 | === Emacs | 195 | === Emacs |
196 | 196 | ||
197 | Note this excellent https://robert.kra.hn/posts/2021-02-07_rust-with-emacs/[guide] from https://github.com/rksm[@rksm]. | ||
198 | |||
197 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. | 199 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. |
198 | 200 | ||
199 | 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]. | 201 | 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]. |
@@ -272,7 +274,86 @@ let g:ale_linters = {'rust': ['analyzer']} | |||
272 | 274 | ||
273 | NeoVim 0.5 (not yet released) has built-in language server support. | 275 | NeoVim 0.5 (not yet released) has built-in language server support. |
274 | For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lspconfig#rust_analyzer[neovim/nvim-lspconfig]. | 276 | For a quick start configuration of rust-analyzer, use https://github.com/neovim/nvim-lspconfig#rust_analyzer[neovim/nvim-lspconfig]. |
275 | Once `neovim/nvim-lspconfig` is installed, use `+lua require'nvim_lsp'.rust_analyzer.setup({})+` in your `init.vim`. | 277 | Once `neovim/nvim-lspconfig` is installed, use `+lua require'lspconfig'.rust_analyzer.setup({})+` in your `init.vim`. |
278 | |||
279 | You can also pass LSP settings to the server: | ||
280 | |||
281 | [source,vim] | ||
282 | ---- | ||
283 | lua << EOF | ||
284 | local nvim_lsp = require'lspconfig' | ||
285 | |||
286 | local on_attach = function(client) | ||
287 | require'completion'.on_attach(client) | ||
288 | end | ||
289 | |||
290 | nvim_lsp.rust_analyzer.setup({ | ||
291 | on_attach=on_attach, | ||
292 | settings = { | ||
293 | ["rust-analyzer"] = { | ||
294 | assist = { | ||
295 | importMergeBehavior = "last", | ||
296 | importPrefix = "by_self", | ||
297 | }, | ||
298 | cargo = { | ||
299 | loadOutDirsFromCheck = true | ||
300 | }, | ||
301 | procMacro = { | ||
302 | enable = true | ||
303 | }, | ||
304 | } | ||
305 | } | ||
306 | }) | ||
307 | EOF | ||
308 | ---- | ||
309 | |||
310 | See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started. | ||
311 | |||
312 | ==== vim-lsp | ||
313 | |||
314 | vim-lsp is installed by following https://github.com/prabirshrestha/vim-lsp[the plugin instructions]. | ||
315 | It can be as simple as adding this line to your `.vimrc`: | ||
316 | |||
317 | [source,vim] | ||
318 | ---- | ||
319 | Plug 'prabirshrestha/vim-lsp' | ||
320 | ---- | ||
321 | |||
322 | Next you need to register the `rust-analyzer` binary. | ||
323 | If it is available in `$PATH`, you may want to add this to your `.vimrc`: | ||
324 | |||
325 | [source,vim] | ||
326 | ---- | ||
327 | if executable('rust-analyzer') | ||
328 | au User lsp_setup call lsp#register_server({ | ||
329 | \ 'name': 'Rust Language Server', | ||
330 | \ 'cmd': {server_info->['rust-analyzer']}, | ||
331 | \ 'whitelist': ['rust'], | ||
332 | \ }) | ||
333 | endif | ||
334 | ---- | ||
335 | |||
336 | There is no dedicated UI for the server configuration, so you would need to send any options as a value of the `initialization_options` field, as described in the <<_configuration,Configuration>> section. | ||
337 | Here is an example of how to enable the proc-macro support: | ||
338 | |||
339 | [source,vim] | ||
340 | ---- | ||
341 | if executable('rust-analyzer') | ||
342 | au User lsp_setup call lsp#register_server({ | ||
343 | \ 'name': 'Rust Language Server', | ||
344 | \ 'cmd': {server_info->['rust-analyzer']}, | ||
345 | \ 'whitelist': ['rust'], | ||
346 | \ 'initialization_options': { | ||
347 | \ 'cargo': { | ||
348 | \ 'loadOutDirsFromCheck': v:true, | ||
349 | \ }, | ||
350 | \ 'procMacro': { | ||
351 | \ 'enable': v:true, | ||
352 | \ }, | ||
353 | \ }, | ||
354 | \ }) | ||
355 | endif | ||
356 | ---- | ||
276 | 357 | ||
277 | === Sublime Text 3 | 358 | === Sublime Text 3 |
278 | 359 | ||
@@ -298,17 +379,49 @@ If you get an error saying `No such file or directory: 'rust-analyzer'`, see the | |||
298 | GNOME Builder 3.37.1 and newer has native `rust-analyzer` support. | 379 | GNOME Builder 3.37.1 and newer has native `rust-analyzer` support. |
299 | If the LSP binary is not available, GNOME Builder can install it when opening a Rust file. | 380 | If the LSP binary is not available, GNOME Builder can install it when opening a Rust file. |
300 | 381 | ||
382 | |||
383 | === Eclipse IDE | ||
384 | |||
385 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. | ||
386 | |||
387 | Support for Rust development in the Eclipse IDE is provided by link:https://github.com/eclipse/corrosion[Eclipse Corrosion]. | ||
388 | While it currently uses RLS as default, you can successfully configure it so the IDE will use `rust-analyzer` instead. | ||
389 | To do so, with an Eclipse IDE where Corrosion is installed, just go to __Window > Preferences > Rust__ and edit the __Path to Rust Language Server__ entry to reference the path to `rust-analyzer`. | ||
390 | You'll need to close and reopen all .rs and Cargo files, or to restart the IDE, for this change to take effect. | ||
391 | |||
301 | == Configuration | 392 | == Configuration |
302 | 393 | ||
303 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs] | 394 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs] |
304 | 395 | ||
305 | rust-analyzer is configured via LSP messages, which means that it's up to the editor to decide on the exact format and location of configuration files. | 396 | The <<_installation,Installation>> section contains details on configuration for some of the editors. |
306 | Please consult your editor's documentation to learn how to configure LSP servers. | 397 | In general `rust-analyzer` is configured via LSP messages, which means that it's up to the editor to decide on the exact format and location of configuration files. |
398 | |||
399 | Some clients, such as <<vs-code,VS Code>> or <<coc-rust-analyzer,COC plugin in Vim>> provide `rust-analyzer` specific configuration UIs. Others may require you to know a bit more about the interaction with `rust-analyzer`. | ||
400 | |||
401 | For the later category, it might help to know that the initial configuration is specified as a value of the `initializationOptions` field of the https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize[`InitializeParams` message, in the LSP protocol]. | ||
402 | The spec says that the field type is `any?`, but `rust-analyzer` is looking for a JSON object that is constructed using settings from the list below. | ||
403 | Name of the setting, ignoring the `rust-analyzer.` prefix, is used as a path, and value of the setting becomes the JSON property value. | ||
404 | |||
405 | For example, a very common configuration is to enable proc-macro support, can be achieved by sending this JSON: | ||
406 | |||
407 | [source,json] | ||
408 | ---- | ||
409 | { | ||
410 | "cargo": { | ||
411 | "loadOutDirsFromCheck": true, | ||
412 | }, | ||
413 | "procMacro": { | ||
414 | "enable": true, | ||
415 | } | ||
416 | } | ||
417 | ---- | ||
418 | |||
419 | Please consult your editor's documentation to learn more about how to configure https://microsoft.github.io/language-server-protocol/[LSP servers]. | ||
307 | 420 | ||
308 | To verify which configuration is actually used by rust-analyzer, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages. | 421 | To verify which configuration is actually used by `rust-analyzer`, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages. |
309 | Logs should show both the JSON that rust-analyzer sees as well as the updated config. | 422 | Logs should show both the JSON that `rust-analyzer` sees as well as the updated config. |
310 | 423 | ||
311 | This is the list of config options rust-analyzer supports: | 424 | This is the list of config options `rust-analyzer` supports: |
312 | 425 | ||
313 | include::./generated_config.adoc[] | 426 | include::./generated_config.adoc[] |
314 | 427 | ||