Use experimental capability to enable color codes

This commit is contained in:
Ian Chamberlain 2023-01-04 12:04:45 -05:00
parent 738ce83d85
commit 65cf7abbe2
No known key found for this signature in database
GPG Key ID: BD7B25D58170E124
5 changed files with 24 additions and 11 deletions

View File

@ -47,6 +47,7 @@ pub enum FlycheckConfig {
features: Vec<String>,
extra_args: Vec<String>,
extra_env: FxHashMap<String, String>,
ansi_color_output: bool,
},
CustomCommand {
command: String,
@ -293,16 +294,21 @@ fn check_command(&self) -> Command {
extra_args,
features,
extra_env,
ansi_color_output,
} => {
let mut cmd = Command::new(toolchain::cargo());
cmd.arg(command);
cmd.current_dir(&self.root);
cmd.args([
"--workspace",
"--message-format=json-diagnostic-rendered-ansi",
"--manifest-path",
])
.arg(self.root.join("Cargo.toml").as_os_str());
cmd.arg("--workspace");
cmd.arg(if *ansi_color_output {
"--message-format=json-diagnostic-rendered-ansi"
} else {
"--message-format=json"
});
cmd.arg("--manifest-path");
cmd.arg(self.root.join("Cargo.toml").as_os_str());
for target in target_triples {
cmd.args(["--target", target.as_str()]);

View File

@ -161,8 +161,8 @@ struct ConfigData {
/// Override the command rust-analyzer uses instead of `cargo check` for
/// diagnostics on save. The command is required to output json and
/// should therefore include `--message-format=json` or a similar option
/// (for colored diagnostics, use
/// `--message-format=json-diagnostic-rendered-ansi`).
/// (if your client supports the `colorDiagnosticOutput` experimental
/// capability, you can use `--message-format=json-diagnostic-rendered-ansi`).
///
/// If you're changing this because you're using some tool wrapping
/// Cargo, you might also want to change
@ -1008,6 +1008,11 @@ pub fn server_status_notification(&self) -> bool {
self.experimental("serverStatusNotification")
}
/// Whether the client supports colored output for full diagnostics from `checkOnSave`.
pub fn color_diagnostic_output(&self) -> bool {
self.experimental("colorDiagnosticOutput")
}
pub fn publish_diagnostics(&self) -> bool {
self.data.diagnostics_enable
}
@ -1206,6 +1211,7 @@ pub fn flycheck(&self) -> FlycheckConfig {
},
extra_args: self.data.check_extraArgs.clone(),
extra_env: self.check_on_save_extra_env(),
ansi_color_output: self.color_diagnostic_output(),
},
}
}

View File

@ -174,8 +174,8 @@ Whether to pass `--no-default-features` to Cargo. Defaults to
Override the command rust-analyzer uses instead of `cargo check` for
diagnostics on save. The command is required to output json and
should therefore include `--message-format=json` or a similar option
(for colored diagnostics, use
`--message-format=json-diagnostic-rendered-ansi`).
(if your client supports the `colorDiagnosticOutput` experimental
capability, you can use `--message-format=json-diagnostic-rendered-ansi`).
If you're changing this because you're using some tool wrapping
Cargo, you might also want to change

View File

@ -644,7 +644,7 @@
]
},
"rust-analyzer.check.overrideCommand": {
"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.",
"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.",
"default": null,
"type": [
"null",

View File

@ -333,6 +333,7 @@ class ExperimentalFeatures implements lc.StaticFeature {
caps.codeActionGroup = true;
caps.hoverActions = true;
caps.serverStatusNotification = true;
caps.colorDiagnosticOutput = true;
caps.commands = {
commands: [
"rust-analyzer.runSingle",