diff options
-rw-r--r-- | crates/completion/src/completions/keyword.rs | 8 | ||||
-rw-r--r-- | docs/user/manual.adoc | 78 |
2 files changed, 81 insertions, 5 deletions
diff --git a/crates/completion/src/completions/keyword.rs b/crates/completion/src/completions/keyword.rs index 47e146128..eb81f9765 100644 --- a/crates/completion/src/completions/keyword.rs +++ b/crates/completion/src/completions/keyword.rs | |||
@@ -88,6 +88,7 @@ pub(crate) fn complete_expr_keyword(acc: &mut Completions, ctx: &CompletionConte | |||
88 | add_keyword(ctx, acc, "loop", "loop {$0}"); | 88 | add_keyword(ctx, acc, "loop", "loop {$0}"); |
89 | add_keyword(ctx, acc, "if", "if $0 {}"); | 89 | add_keyword(ctx, acc, "if", "if $0 {}"); |
90 | add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); | 90 | add_keyword(ctx, acc, "if let", "if let $1 = $0 {}"); |
91 | add_keyword(ctx, acc, "for", "for $1 in $0 {}"); | ||
91 | } | 92 | } |
92 | 93 | ||
93 | if ctx.if_is_prev || ctx.block_expr_parent { | 94 | if ctx.if_is_prev || ctx.block_expr_parent { |
@@ -258,6 +259,7 @@ mod tests { | |||
258 | kw loop | 259 | kw loop |
259 | kw if | 260 | kw if |
260 | kw if let | 261 | kw if let |
262 | kw for | ||
261 | kw let | 263 | kw let |
262 | kw mod | 264 | kw mod |
263 | kw const | 265 | kw const |
@@ -284,6 +286,7 @@ mod tests { | |||
284 | kw loop | 286 | kw loop |
285 | kw if | 287 | kw if |
286 | kw if let | 288 | kw if let |
289 | kw for | ||
287 | kw let | 290 | kw let |
288 | kw mod | 291 | kw mod |
289 | kw const | 292 | kw const |
@@ -310,6 +313,7 @@ mod tests { | |||
310 | kw loop | 313 | kw loop |
311 | kw if | 314 | kw if |
312 | kw if let | 315 | kw if let |
316 | kw for | ||
313 | kw let | 317 | kw let |
314 | kw else | 318 | kw else |
315 | kw else if | 319 | kw else if |
@@ -343,6 +347,7 @@ fn quux() -> i32 { | |||
343 | kw loop | 347 | kw loop |
344 | kw if | 348 | kw if |
345 | kw if let | 349 | kw if let |
350 | kw for | ||
346 | kw unsafe | 351 | kw unsafe |
347 | kw return | 352 | kw return |
348 | "#]], | 353 | "#]], |
@@ -391,6 +396,7 @@ fn quux() -> i32 { | |||
391 | kw loop | 396 | kw loop |
392 | kw if | 397 | kw if |
393 | kw if let | 398 | kw if let |
399 | kw for | ||
394 | kw let | 400 | kw let |
395 | kw mod | 401 | kw mod |
396 | kw const | 402 | kw const |
@@ -549,6 +555,7 @@ pub mod future { | |||
549 | kw loop | 555 | kw loop |
550 | kw if | 556 | kw if |
551 | kw if let | 557 | kw if let |
558 | kw for | ||
552 | kw return | 559 | kw return |
553 | "#]], | 560 | "#]], |
554 | ) | 561 | ) |
@@ -607,6 +614,7 @@ fn foo() { | |||
607 | kw loop | 614 | kw loop |
608 | kw if | 615 | kw if |
609 | kw if let | 616 | kw if let |
617 | kw for | ||
610 | kw return | 618 | kw return |
611 | "#]], | 619 | "#]], |
612 | ); | 620 | ); |
diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index cb698a3a2..020e4c937 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc | |||
@@ -307,6 +307,52 @@ EOF | |||
307 | 307 | ||
308 | See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started. | 308 | See https://sharksforarms.dev/posts/neovim-rust/ for more tips on getting started. |
309 | 309 | ||
310 | ==== vim-lsp | ||
311 | |||
312 | vim-lsp is installed by following https://github.com/prabirshrestha/vim-lsp[the plugin instructions]. | ||
313 | It can be as simple as adding this line to your `.vimrc`: | ||
314 | |||
315 | [source,vim] | ||
316 | ---- | ||
317 | Plug 'prabirshrestha/vim-lsp' | ||
318 | ---- | ||
319 | |||
320 | Next you need to register the `rust-analyzer` binary. | ||
321 | If it is available in `$PATH`, you may want to add this to your `.vimrc`: | ||
322 | |||
323 | [source,vim] | ||
324 | ---- | ||
325 | if 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 | \ }) | ||
331 | endif | ||
332 | ---- | ||
333 | |||
334 | 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. | ||
335 | Here is an example of how to enable the proc-macro support: | ||
336 | |||
337 | [source,vim] | ||
338 | ---- | ||
339 | if 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 | \ }) | ||
353 | endif | ||
354 | ---- | ||
355 | |||
310 | === Sublime Text 3 | 356 | === Sublime Text 3 |
311 | 357 | ||
312 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. | 358 | Prerequisites: You have installed the <<rust-analyzer-language-server-binary,`rust-analyzer` binary>>. |
@@ -345,13 +391,35 @@ You'll need to close and reopen all .rs and Cargo files, or to restart the IDE, | |||
345 | 391 | ||
346 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs] | 392 | **Source:** https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/rust-analyzer/src/config.rs[config.rs] |
347 | 393 | ||
348 | 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. | 394 | The <<_installation,Installation>> section contains details on configuration for some of the editors. |
349 | Please consult your editor's documentation to learn how to configure LSP servers. | 395 | 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. |
396 | |||
397 | 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`. | ||
398 | |||
399 | 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]. | ||
400 | 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. | ||
401 | Name of the setting, ignoring the `rust-analyzer.` prefix, is used as a path, and value of the setting becomes the JSON property value. | ||
402 | |||
403 | For example, a very common configuration is to enable proc-macro support, can be achieved by sending this JSON: | ||
404 | |||
405 | [source,json] | ||
406 | ---- | ||
407 | { | ||
408 | "cargo": { | ||
409 | "loadOutDirsFromCheck": true, | ||
410 | }, | ||
411 | "procMacro": { | ||
412 | "enable": true, | ||
413 | } | ||
414 | } | ||
415 | ---- | ||
416 | |||
417 | Please consult your editor's documentation to learn more about how to configure https://microsoft.github.io/language-server-protocol/[LSP servers]. | ||
350 | 418 | ||
351 | 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. | 419 | 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. |
352 | Logs should show both the JSON that rust-analyzer sees as well as the updated config. | 420 | Logs should show both the JSON that `rust-analyzer` sees as well as the updated config. |
353 | 421 | ||
354 | This is the list of config options rust-analyzer supports: | 422 | This is the list of config options `rust-analyzer` supports: |
355 | 423 | ||
356 | include::./generated_config.adoc[] | 424 | include::./generated_config.adoc[] |
357 | 425 | ||