From b3a7953cae4f14f74934cc64ba7ccf7b3eb6cd08 Mon Sep 17 00:00:00 2001 From: James Leitch Date: Mon, 19 Apr 2021 12:26:04 -0700 Subject: [PATCH] Code review feedback. --- crates/flycheck/src/lib.rs | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 4c75396f57..1682d8bde2 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs @@ -319,13 +319,13 @@ impl CargoActor { read_at_least_one_message = true; - // Try to deserialize a message from Cargo. - { - let mut deserializer = serde_json::Deserializer::from_str(&message); - deserializer.disable_recursion_limit(); - if let Ok(message) = cargo_metadata::Message::deserialize(&mut deserializer) { + // Try to deserialize a message from Cargo or Rustc. + let mut deserializer = serde_json::Deserializer::from_str(&message); + deserializer.disable_recursion_limit(); + if let Ok(message) = JsonMessage::deserialize(&mut deserializer) { + match message { // Skip certain kinds of messages to only spend time on what's useful - match message { + JsonMessage::Cargo(message) => match message { cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => { self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap() } @@ -338,18 +338,12 @@ impl CargoActor { | cargo_metadata::Message::BuildFinished(_) | cargo_metadata::Message::TextLine(_) | _ => (), + }, + JsonMessage::Rustc(message) => { + self.sender.send(CargoMessage::Diagnostic(message)).unwrap() } } } - - // Try to deserialize a Diagnostic directly from Rustc. - { - let mut deserializer = serde_json::Deserializer::from_str(&message); - deserializer.disable_recursion_limit(); - if let Ok(message) = Diagnostic::deserialize(&mut deserializer) { - self.sender.send(CargoMessage::Diagnostic(message)).unwrap() - } - } } Ok(read_at_least_one_message) } @@ -359,3 +353,10 @@ enum CargoMessage { CompilerArtifact(cargo_metadata::Artifact), Diagnostic(Diagnostic), } + +#[derive(Deserialize)] +#[serde(untagged)] +enum JsonMessage { + Cargo(cargo_metadata::Message), + Rustc(Diagnostic), +}