Skip to content

Commit e5a1dac

Browse files
Use experimental capability to enable color codes
1 parent 23383c6 commit e5a1dac

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

crates/flycheck/src/lib.rs

Lines changed: 12 additions & 6 deletions
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

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

1005+
/// Whether the client supports colored output for full diagnostics from `checkOnSave`.
1006+
pub fn color_diagnostic_output(&self) -> bool {
1007+
self.experimental("colorDiagnosticOutput")
1008+
}
1009+
10051010
pub fn publish_diagnostics(&self) -> bool {
10061011
self.data.diagnostics_enable
10071012
}
@@ -1200,6 +1205,7 @@ impl Config {
12001205
},
12011206
extra_args: self.data.checkOnSave_extraArgs.clone(),
12021207
extra_env: self.check_on_save_extra_env(),
1208+
ansi_color_output: self.color_diagnostic_output(),
12031209
},
12041210
}
12051211
}

docs/user/generated_config.adoc

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@
644644
]
645645
},
646646
"rust-analyzer.checkOnSave.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

Lines changed: 1 addition & 0 deletions
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)