diff options
author | James Leitch <[email protected]> | 2021-04-19 20:26:04 +0100 |
---|---|---|
committer | James Leitch <[email protected]> | 2021-04-19 20:26:04 +0100 |
commit | b3a7953cae4f14f74934cc64ba7ccf7b3eb6cd08 (patch) | |
tree | 258daac81f857d6023b5f8e31b4c9b31fb4b6646 /crates/flycheck/src | |
parent | b5c194f3f7c1dd38d4743ca65d5a55dfb5b648fc (diff) |
Code review feedback.
Diffstat (limited to 'crates/flycheck/src')
-rw-r--r-- | crates/flycheck/src/lib.rs | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/crates/flycheck/src/lib.rs b/crates/flycheck/src/lib.rs index 4c75396f5..1682d8bde 100644 --- a/crates/flycheck/src/lib.rs +++ b/crates/flycheck/src/lib.rs | |||
@@ -319,13 +319,13 @@ impl CargoActor { | |||
319 | 319 | ||
320 | read_at_least_one_message = true; | 320 | read_at_least_one_message = true; |
321 | 321 | ||
322 | // Try to deserialize a message from Cargo. | 322 | // Try to deserialize a message from Cargo or Rustc. |
323 | { | 323 | let mut deserializer = serde_json::Deserializer::from_str(&message); |
324 | let mut deserializer = serde_json::Deserializer::from_str(&message); | 324 | deserializer.disable_recursion_limit(); |
325 | deserializer.disable_recursion_limit(); | 325 | if let Ok(message) = JsonMessage::deserialize(&mut deserializer) { |
326 | if let Ok(message) = cargo_metadata::Message::deserialize(&mut deserializer) { | 326 | match message { |
327 | // Skip certain kinds of messages to only spend time on what's useful | 327 | // Skip certain kinds of messages to only spend time on what's useful |
328 | match message { | 328 | JsonMessage::Cargo(message) => match message { |
329 | cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => { | 329 | cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => { |
330 | self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap() | 330 | self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap() |
331 | } | 331 | } |
@@ -338,18 +338,12 @@ impl CargoActor { | |||
338 | | cargo_metadata::Message::BuildFinished(_) | 338 | | cargo_metadata::Message::BuildFinished(_) |
339 | | cargo_metadata::Message::TextLine(_) | 339 | | cargo_metadata::Message::TextLine(_) |
340 | | _ => (), | 340 | | _ => (), |
341 | }, | ||
342 | JsonMessage::Rustc(message) => { | ||
343 | self.sender.send(CargoMessage::Diagnostic(message)).unwrap() | ||
341 | } | 344 | } |
342 | } | 345 | } |
343 | } | 346 | } |
344 | |||
345 | // Try to deserialize a Diagnostic directly from Rustc. | ||
346 | { | ||
347 | let mut deserializer = serde_json::Deserializer::from_str(&message); | ||
348 | deserializer.disable_recursion_limit(); | ||
349 | if let Ok(message) = Diagnostic::deserialize(&mut deserializer) { | ||
350 | self.sender.send(CargoMessage::Diagnostic(message)).unwrap() | ||
351 | } | ||
352 | } | ||
353 | } | 347 | } |
354 | Ok(read_at_least_one_message) | 348 | Ok(read_at_least_one_message) |
355 | } | 349 | } |
@@ -359,3 +353,10 @@ enum CargoMessage { | |||
359 | CompilerArtifact(cargo_metadata::Artifact), | 353 | CompilerArtifact(cargo_metadata::Artifact), |
360 | Diagnostic(Diagnostic), | 354 | Diagnostic(Diagnostic), |
361 | } | 355 | } |
356 | |||
357 | #[derive(Deserialize)] | ||
358 | #[serde(untagged)] | ||
359 | enum JsonMessage { | ||
360 | Cargo(cargo_metadata::Message), | ||
361 | Rustc(Diagnostic), | ||
362 | } | ||