aboutsummaryrefslogtreecommitdiff
path: root/docs/user/manual.adoc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-02-08 04:38:34 +0000
committerGitHub <[email protected]>2021-02-08 04:38:34 +0000
commit984898329bb2e0ee8861d2363ca8622f7178b065 (patch)
tree150b02bc54dd0eb8e273ee7b88708a970fbdf896 /docs/user/manual.adoc
parent336909b63a14b801520c6627d90d750babcfe280 (diff)
parent9ffe4ca26ce473d165e2fb925c6dedf7abad1591 (diff)
Merge #7549
7549: Documentation: Explain how initial configuration is sent over LSP and document vim-lsp r=ilya-bobyr a=ilya-bobyr This request contains two related but independent changes. The first explains `rust-analyzer` initial configuration over LSP. The second - adds documentation on `vim-lsp` Vim plugin and provides an example of the initial configuration for `rust-analyzer` when using this particular LSP client. Let me know if you would prefer the changes to be reviewed in two separate pull requests. Co-authored-by: Ilya Bobyr <[email protected]>
Diffstat (limited to 'docs/user/manual.adoc')
-rw-r--r--docs/user/manual.adoc78
1 files changed, 73 insertions, 5 deletions
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc
index 10d4fd606..a1018b0cb 100644
--- a/docs/user/manual.adoc
+++ b/docs/user/manual.adoc
@@ -307,6 +307,52 @@ EOF
307 307
308See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started. 308See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started.
309 309
310==== vim-lsp
311
312vim-lsp is installed by following https://github.com/prabirshrestha/vim-lsp[the plugin instructions].
313It can be as simple as adding this line to your `.vimrc`:
314
315[source,vim]
316----
317Plug 'prabirshrestha/vim-lsp'
318----
319
320Next you need to register the `rust-analyzer` binary.
321If it is available in `$PATH`, you may want to add this to your `.vimrc`:
322
323[source,vim]
324----
325if executable('rust-analyzer')
326 au User lsp_setup call lsp#register_server({
327 \ 'name': 'Rust Language Server',
328 \ 'cmd': {server_info->['rust-analyzer']},
329 \ 'whitelist': ['rust'],
330 \ })
331endif
332----
333
334There 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.
335Here is an example of how to enable the proc-macro support:
336
337[source,vim]
338----
339if executable('rust-analyzer')
340 au User lsp_setup call lsp#register_server({
341 \ 'name': 'Rust Language Server',
342 \ 'cmd': {server_info->['rust-analyzer']},
343 \ 'whitelist': ['rust'],
344 \ 'initialization_options': {
345 \ 'cargo': {
346 \ 'loadOutDirsFromCheck': v:true,
347 \ },
348 \ 'procMacro': {
349 \ 'enable': v:true,
350 \ },
351 \ },
352 \ })
353endif
354----
355
310=== Sublime Text 3 356=== Sublime Text 3
311 357
312Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. 358Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>.
@@ -335,13 +381,35 @@ If the LSP binary is not available, GNOME Builder can install it when opening a
335 381
336**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs] 382**Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs]
337 383
338rust-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. 384The <<_installation,Installation>> section contains details on configuration for some of the editors.
339Please consult your editor's documentation to learn how to configure LSP servers. 385In 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.
386
387Some 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`.
388
389For 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].
390The 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.
391Name of the setting, ignoring the `rust-analyzer.` prefix, is used as a path, and value of the setting becomes the JSON property value.
392
393For example, a very common configuration is to enable proc-macro support, can be achieved by sending this JSON:
394
395[source,json]
396----
397{
398 "cargo": {
399 "loadOutDirsFromCheck": true,
400 },
401 "procMacro": {
402 "enable": true,
403 }
404}
405----
406
407Please consult your editor's documentation to learn more about how to configure https://microsoft.github.io/language-server-protocol/[LSP servers].
340 408
341To verify which configuration is actually used by rust-analyzer, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages. 409To verify which configuration is actually used by `rust-analyzer`, set `RA_LOG` environment variable to `rust_analyzer=info` and look for config-related messages.
342Logs should show both the JSON that rust-analyzer sees as well as the updated config. 410Logs should show both the JSON that `rust-analyzer` sees as well as the updated config.
343 411
344This is the list of config options rust-analyzer supports: 412This is the list of config options `rust-analyzer` supports:
345 413
346include::./generated_config.adoc[] 414include::./generated_config.adoc[]
347 415