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

View file

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

View file

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

View file

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