mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-28 12:55:11 +00:00
Watch both stdout and stderr in flycheck
This commit is contained in:
parent
3ba876a4a6
commit
209cf7dc61
1 changed files with 41 additions and 27 deletions
|
@ -456,42 +456,56 @@ impl CargoActor {
|
||||||
// simply skip a line if it doesn't parse, which just ignores any
|
// simply skip a line if it doesn't parse, which just ignores any
|
||||||
// erroneous output.
|
// erroneous output.
|
||||||
|
|
||||||
let mut error = String::new();
|
let mut stdout_errors = String::new();
|
||||||
let mut read_at_least_one_message = false;
|
let mut stderr_errors = String::new();
|
||||||
|
let mut read_at_least_one_stdout_message = false;
|
||||||
|
let mut read_at_least_one_stderr_message = false;
|
||||||
|
let process_line = |line: &str, error: &mut String| {
|
||||||
|
// Try to deserialize a message from Cargo or Rustc.
|
||||||
|
let mut deserializer = serde_json::Deserializer::from_str(line);
|
||||||
|
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
|
||||||
|
JsonMessage::Cargo(message) => match message {
|
||||||
|
cargo_metadata::Message::CompilerArtifact(artifact) if !artifact.fresh => {
|
||||||
|
self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap();
|
||||||
|
}
|
||||||
|
cargo_metadata::Message::CompilerMessage(msg) => {
|
||||||
|
self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap();
|
||||||
|
}
|
||||||
|
_ => (),
|
||||||
|
},
|
||||||
|
JsonMessage::Rustc(message) => {
|
||||||
|
self.sender.send(CargoMessage::Diagnostic(message)).unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
error.push_str(line);
|
||||||
|
error.push('\n');
|
||||||
|
return false;
|
||||||
|
};
|
||||||
let output = streaming_output(
|
let output = streaming_output(
|
||||||
self.stdout,
|
self.stdout,
|
||||||
self.stderr,
|
self.stderr,
|
||||||
&mut |line| {
|
&mut |line| {
|
||||||
read_at_least_one_message = true;
|
if process_line(line, &mut stdout_errors) {
|
||||||
|
read_at_least_one_stdout_message = true;
|
||||||
// Try to deserialize a message from Cargo or Rustc.
|
|
||||||
let mut deserializer = serde_json::Deserializer::from_str(line);
|
|
||||||
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
|
|
||||||
JsonMessage::Cargo(message) => match message {
|
|
||||||
cargo_metadata::Message::CompilerArtifact(artifact)
|
|
||||||
if !artifact.fresh =>
|
|
||||||
{
|
|
||||||
self.sender.send(CargoMessage::CompilerArtifact(artifact)).unwrap();
|
|
||||||
}
|
|
||||||
cargo_metadata::Message::CompilerMessage(msg) => {
|
|
||||||
self.sender.send(CargoMessage::Diagnostic(msg.message)).unwrap();
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
JsonMessage::Rustc(message) => {
|
|
||||||
self.sender.send(CargoMessage::Diagnostic(message)).unwrap();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
&mut |line| {
|
&mut |line| {
|
||||||
error.push_str(line);
|
if process_line(line, &mut stderr_errors) {
|
||||||
error.push('\n');
|
read_at_least_one_stderr_message = true;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let read_at_least_one_message =
|
||||||
|
read_at_least_one_stdout_message || read_at_least_one_stderr_message;
|
||||||
|
let mut error = stdout_errors;
|
||||||
|
error.push_str(&stderr_errors);
|
||||||
match output {
|
match output {
|
||||||
Ok(_) => Ok((read_at_least_one_message, error)),
|
Ok(_) => Ok((read_at_least_one_message, error)),
|
||||||
Err(e) => Err(io::Error::new(e.kind(), format!("{e:?}: {error}"))),
|
Err(e) => Err(io::Error::new(e.kind(), format!("{e:?}: {error}"))),
|
||||||
|
|
Loading…
Reference in a new issue