Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ semver = "1.0.26"
serde = { version = "1.0.219" }
serde_derive = { version = "1.0.219" }
serde_json = "1.0.140"
strip-ansi-escapes = "0.2.1"
rustc-hash = "2.1.1"
rustc-literal-escaper = "0.0.4"
smallvec = { version = "1.15.1", features = [
Expand Down
1 change: 1 addition & 0 deletions crates/rust-analyzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ semver.workspace = true
memchr = "2.7.5"
cargo_metadata.workspace = true
process-wrap.workspace = true
strip-ansi-escapes.workspace = true

cfg.workspace = true
hir-def.workspace = true
Expand Down
35 changes: 26 additions & 9 deletions crates/rust-analyzer/src/flycheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,11 +421,16 @@ impl FlycheckActor {

let formatted_command = format!("{command:?}");

let strip_ansi_color_codes = !matches!(
self.config,
FlycheckConfig::CargoCommand { ansi_color_output: false, .. }
);

tracing::debug!(?command, "will restart flycheck");
let (sender, receiver) = unbounded();
match CommandHandle::spawn(
command,
CargoCheckParser,
CargoCheckParser { strip_ansi_color_codes },
sender,
match &self.config {
FlycheckConfig::CargoCommand { options, .. } => Some(
Expand Down Expand Up @@ -655,11 +660,12 @@ impl FlycheckActor {
};
}

cmd.arg(if *ansi_color_output {
"--message-format=json-diagnostic-rendered-ansi"
if *ansi_color_output {
cmd.arg("--message-format=json-diagnostic-rendered-ansi");
} else {
"--message-format=json"
});
cmd.arg("--message-format=json");
cmd.arg("--color=never");
}

if let Some(manifest_path) = &self.manifest_path {
cmd.arg("--manifest-path");
Expand Down Expand Up @@ -725,7 +731,9 @@ enum CargoCheckMessage {
Diagnostic { diagnostic: Diagnostic, package_id: Option<Arc<PackageId>> },
}

struct CargoCheckParser;
struct CargoCheckParser {
strip_ansi_color_codes: bool,
}

impl CargoParser<CargoCheckMessage> for CargoCheckParser {
fn from_line(&self, line: &str, error: &mut String) -> Option<CargoCheckMessage> {
Expand All @@ -739,15 +747,24 @@ impl CargoParser<CargoCheckMessage> for CargoCheckParser {
Some(CargoCheckMessage::CompilerArtifact(artifact))
}
cargo_metadata::Message::CompilerMessage(msg) => {
let mut diagnostic = msg.message;
if self.strip_ansi_color_codes {
diagnostic.rendered =
diagnostic.rendered.map(strip_ansi_escapes::strip_str);
}
Some(CargoCheckMessage::Diagnostic {
diagnostic: msg.message,
diagnostic,
package_id: Some(Arc::new(msg.package_id)),
})
}
_ => None,
},
JsonMessage::Rustc(message) => {
Some(CargoCheckMessage::Diagnostic { diagnostic: message, package_id: None })
JsonMessage::Rustc(mut diagnostic) => {
if self.strip_ansi_color_codes {
diagnostic.rendered =
diagnostic.rendered.map(strip_ansi_escapes::strip_str);
}
Some(CargoCheckMessage::Diagnostic { diagnostic, package_id: None })
}
};
}
Expand Down