From aae1e97590138be6891ad1518e536a5aaa0f78bd Mon Sep 17 00:00:00 2001 From: Dorian Peake Date: Sun, 5 Sep 2021 16:32:05 +0100 Subject: [PATCH 1/2] Add rust-project.json + cargo check info to docs Add information about how to configure compilation errors/checks when using rust-project.json. --- docs/user/manual.adoc | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index 8567b81b0058..b74e498f6474 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -616,6 +616,27 @@ See https://github.com/rust-analyzer/rust-project.json-example for a small examp You can set `RA_LOG` environmental variable to `rust_analyzer=info` to inspect how rust-analyzer handles config and project loading. +Note that calls to `cargo check` are disabled when using `rust-project.json` by default, so compilation errors and warnings will no longer be sent to your LSP client. To enable these compilation errors you will need to specify explicitly what command rust-analyzer should run to perform the checks using the `checkOnSave.overrideCommand` configuration. The following example, explicitly enables calls to `cargo check` in neovim's configuration: + +[source,vim] +---- +lua << EOF +nvim_lsp['rust_analyzer'].setup { + on_attach = on_attach, + settings = { + ["rust-analyzer"] = { + checkOnSave = { + overrideCommand = {"cargo", "check", "--message-format=json"}, + enable = true, + } + } + } +} +EOF +---- + +The `checkOnSave.overrideCommand` requires the command specified to output json error messages for rust-analyzer to consume. The `--message-format=json` flag does this for `cargo check` so whichever command you use must also output errors in this format. See the <> section for more information. + == Security At the moment, rust-analyzer assumes that all code is trusted. From a2bc57c28f02b219c806501d6a847dfcfccd9560 Mon Sep 17 00:00:00 2001 From: Dorian Peake Date: Sun, 5 Sep 2021 16:59:38 +0100 Subject: [PATCH 2/2] Update manual.adoc --- docs/user/manual.adoc | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/docs/user/manual.adoc b/docs/user/manual.adoc index b74e498f6474..ee4270266086 100644 --- a/docs/user/manual.adoc +++ b/docs/user/manual.adoc @@ -616,23 +616,11 @@ See https://github.com/rust-analyzer/rust-project.json-example for a small examp You can set `RA_LOG` environmental variable to `rust_analyzer=info` to inspect how rust-analyzer handles config and project loading. -Note that calls to `cargo check` are disabled when using `rust-project.json` by default, so compilation errors and warnings will no longer be sent to your LSP client. To enable these compilation errors you will need to specify explicitly what command rust-analyzer should run to perform the checks using the `checkOnSave.overrideCommand` configuration. The following example, explicitly enables calls to `cargo check` in neovim's configuration: +Note that calls to `cargo check` are disabled when using `rust-project.json` by default, so compilation errors and warnings will no longer be sent to your LSP client. To enable these compilation errors you will need to specify explicitly what command rust-analyzer should run to perform the checks using the `checkOnSave.overrideCommand` configuration. As an example, the following configuration explicitly sets `cargo check` as the `checkOnSave` command. -[source,vim] +[source,json] ---- -lua << EOF -nvim_lsp['rust_analyzer'].setup { - on_attach = on_attach, - settings = { - ["rust-analyzer"] = { - checkOnSave = { - overrideCommand = {"cargo", "check", "--message-format=json"}, - enable = true, - } - } - } -} -EOF +{ "rust-analyzer.checkOnSave.overrideCommand": ["cargo", "check", "--message-format=json"] } ---- The `checkOnSave.overrideCommand` requires the command specified to output json error messages for rust-analyzer to consume. The `--message-format=json` flag does this for `cargo check` so whichever command you use must also output errors in this format. See the <> section for more information.