diff options
Diffstat (limited to 'docs')
-rw-r--r-- | docs/user/manual.adoc | 90 |
1 files changed, 85 insertions, 5 deletions
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index 10d4fd606..a2c7f56b3 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]. |
@@ -307,6 +309,52 @@ EOF | |||
307 | 309 | ||
308 | See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started. | 310 | See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started. |
309 | 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 | ---- | ||
357 | |||
310 | === Sublime Text 3 | 358 | === Sublime Text 3 |
311 | 359 | ||
312 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. | 360 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. |
@@ -331,17 +379,49 @@ If you get an error saying `No such file or directory: 'rust-analyzer'`, see the | |||
331 | 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. |
332 | 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. |
333 | 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 | |||
334 | == Configuration | 392 | == Configuration |
335 | 393 | ||
336 | **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] |
337 | 395 | ||
338 | 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. |
339 | 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 `intializationOptions` 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]. | ||
340 | 420 | ||
341 | 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. |
342 | 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. |
343 | 423 | ||
344 | This is the list of config options rust-analyzer supports: | 424 | This is the list of config options `rust-analyzer` supports: |
345 | 425 | ||
346 | include::./generated_config.adoc[] | 426 | include::./generated_config.adoc[] |
347 | 427 | ||