Skip to content

Commit 65cf7ab

Browse files
Use experimental capability to enable color codes
1 parent 738ce83 commit 65cf7ab

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

crates/flycheck/src/lib.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub enum FlycheckConfig {
4747
features: Vec<String>,
4848
extra_args: Vec<String>,
4949
extra_env: FxHashMap<String, String>,
50+
ansi_color_output: bool,
5051
},
5152
CustomCommand {
5253
command: String,
@@ -293,16 +294,21 @@ impl FlycheckActor {
293294
extra_args,
294295
features,
295296
extra_env,
297+
ansi_color_output,
296298
} => {
297299
let mut cmd = Command::new(toolchain::cargo());
298300
cmd.arg(command);
299301
cmd.current_dir(&self.root);
300-
cmd.args([
301-
"--workspace",
302-
"--message-format=json-diagnostic-rendered-ansi",
303-
"--manifest-path",
304-
])
305-
.arg(self.root.join("Cargo.toml").as_os_str());
302+
cmd.arg("--workspace");
303+
304+
cmd.arg(if *ansi_color_output {
305+
"--message-format=json-diagnostic-rendered-ansi"
306+
} else {
307+
"--message-format=json"
308+
});
309+
310+
cmd.arg("--manifest-path");
311+
cmd.arg(self.root.join("Cargo.toml").as_os_str());
306312

307313
for target in target_triples {
308314
cmd.args(["--target", target.as_str()]);

crates/rust-analyzer/src/config.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ config_data! {
161161
/// Override the command rust-analyzer uses instead of `cargo check` for
162162
/// diagnostics on save. The command is required to output json and
163163
/// should therefore include `--message-format=json` or a similar option
164-
/// (for colored diagnostics, use
165-
/// `--message-format=json-diagnostic-rendered-ansi`).
164+
/// (if your client supports the `colorDiagnosticOutput` experimental
165+
/// capability, you can use `--message-format=json-diagnostic-rendered-ansi`).
166166
///
167167
/// If you're changing this because you're using some tool wrapping
168168
/// Cargo, you might also want to change
@@ -1008,6 +1008,11 @@ impl Config {
10081008
self.experimental("serverStatusNotification")
10091009
}
10101010

1011+
/// Whether the client supports colored output for full diagnostics from `checkOnSave`.
1012+
pub fn color_diagnostic_output(&self) -> bool {
1013+
self.experimental("colorDiagnosticOutput")
1014+
}
1015+
10111016
pub fn publish_diagnostics(&self) -> bool {
10121017
self.data.diagnostics_enable
10131018
}
@@ -1206,6 +1211,7 @@ impl Config {
12061211
},
12071212
extra_args: self.data.check_extraArgs.clone(),
12081213
extra_env: self.check_on_save_extra_env(),
1214+
ansi_color_output: self.color_diagnostic_output(),
12091215
},
12101216
}
12111217
}

docs/user/generated_config.adoc

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,8 @@ Whether to pass `--no-default-features` to Cargo. Defaults to
174174
Override the command rust-analyzer uses instead of `cargo check` for
175175
diagnostics on save. The command is required to output json and
176176
should therefore include `--message-format=json` or a similar option
177-
(for colored diagnostics, use
178-
`--message-format=json-diagnostic-rendered-ansi`).
177+
(if your client supports the `colorDiagnosticOutput` experimental
178+
capability, you can use `--message-format=json-diagnostic-rendered-ansi`).
179179

180180
If you're changing this because you're using some tool wrapping
181181
Cargo, you might also want to change

editors/code/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@
644644
]
645645
},
646646
"rust-analyzer.check.overrideCommand": {
647-
"markdownDescription": "Override the command rust-analyzer uses instead of `cargo check` for\ndiagnostics on save. The command is required to output json and\nshould therefore include `--message-format=json` or a similar option\n(for colored diagnostics, use\n`--message-format=json-diagnostic-rendered-ansi`).\n\nIf you're changing this because you're using some tool wrapping\nCargo, you might also want to change\n`#rust-analyzer.cargo.buildScripts.overrideCommand#`.\n\nIf there are multiple linked projects, this command is invoked for\neach of them, with the working directory being the project root\n(i.e., the folder containing the `Cargo.toml`).\n\nAn example command would be:\n\n```bash\ncargo check --workspace --message-format=json --all-targets\n```\n.",
647+
"markdownDescription": "Override the command rust-analyzer uses instead of `cargo check` for\ndiagnostics on save. The command is required to output json and\nshould therefore include `--message-format=json` or a similar option\n(if your client supports the `colorDiagnosticOutput` experimental\ncapability, you can use `--message-format=json-diagnostic-rendered-ansi`).\n\nIf you're changing this because you're using some tool wrapping\nCargo, you might also want to change\n`#rust-analyzer.cargo.buildScripts.overrideCommand#`.\n\nIf there are multiple linked projects, this command is invoked for\neach of them, with the working directory being the project root\n(i.e., the folder containing the `Cargo.toml`).\n\nAn example command would be:\n\n```bash\ncargo check --workspace --message-format=json --all-targets\n```\n.",
648648
"default": null,
649649
"type": [
650650
"null",

editors/code/src/client.ts

+1
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
333333
caps.codeActionGroup = true;
334334
caps.hoverActions = true;
335335
caps.serverStatusNotification = true;
336+
caps.colorDiagnosticOutput = true;
336337
caps.commands = {
337338
commands: [
338339
"rust-analyzer.runSingle",

0 commit comments

Comments
 (0)