Unnamed repository; edit this file 'description' to name the repository.
internal: Make stdout/stderr explicit in JsonLinesParser
Currently JsonLinesParser::from_line is called for both stdout and
stderr, so trait implementers cannot distinguish stdout and stderr.
Define a separate JsonLinesParser::from_stderr_line to make the
stdout/stderr distinction explicit, and update use sites. This is not
a behaviour change.
AI disclosure: Partially written by Codex and GPT-5.5.
| -rw-r--r-- | crates/rust-analyzer/src/command.rs | 4 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/discover.rs | 4 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/flycheck.rs | 14 | ||||
| -rw-r--r-- | crates/rust-analyzer/src/test_runner.rs | 4 |
4 files changed, 23 insertions, 3 deletions
diff --git a/crates/rust-analyzer/src/command.rs b/crates/rust-analyzer/src/command.rs index ff2e21c865..bc3fa21c66 100644 --- a/crates/rust-analyzer/src/command.rs +++ b/crates/rust-analyzer/src/command.rs @@ -23,6 +23,7 @@ use stdx::process::streaming_output; /// well as custom discover commands. pub(crate) trait JsonLinesParser<T>: Send + 'static { fn from_line(&self, line: &str, error: &mut String) -> Option<T>; + fn from_stderr_line(&self, line: &str, error: &mut String) -> Option<T>; fn from_eof(&self) -> Option<T>; } @@ -95,7 +96,8 @@ impl<T: Sized + Send + 'static> CommandActor<T> { _ = stderr.write_all(line.as_bytes()); _ = stderr.write_all(b"\n"); } - if process_line(line, &mut stderr_errors) { + if let Some(t) = self.parser.from_stderr_line(line, &mut stderr_errors) { + self.sender.send(t).unwrap(); read_at_least_one_stderr_message = true; } }, diff --git a/crates/rust-analyzer/src/discover.rs b/crates/rust-analyzer/src/discover.rs index 098b6a4d98..459a799320 100644 --- a/crates/rust-analyzer/src/discover.rs +++ b/crates/rust-analyzer/src/discover.rs @@ -136,6 +136,10 @@ impl JsonLinesParser<DiscoverProjectMessage> for DiscoverProjectParser { fn from_eof(&self) -> Option<DiscoverProjectMessage> { None } + + fn from_stderr_line(&self, line: &str, error: &mut String) -> Option<DiscoverProjectMessage> { + self.from_line(line, error) + } } #[test] diff --git a/crates/rust-analyzer/src/flycheck.rs b/crates/rust-analyzer/src/flycheck.rs index f73ffb24ee..b927a11604 100644 --- a/crates/rust-analyzer/src/flycheck.rs +++ b/crates/rust-analyzer/src/flycheck.rs @@ -1011,8 +1011,8 @@ enum CheckMessage { struct CheckParser; -impl JsonLinesParser<CheckMessage> for CheckParser { - fn from_line(&self, line: &str, error: &mut String) -> Option<CheckMessage> { +impl CheckParser { + fn parse_line(&self, line: &str, error: &mut String) -> Option<CheckMessage> { let mut deserializer = serde_json::Deserializer::from_str(line); deserializer.disable_recursion_limit(); if let Ok(message) = JsonMessage::deserialize(&mut deserializer) { @@ -1042,6 +1042,16 @@ impl JsonLinesParser<CheckMessage> for CheckParser { error.push('\n'); None } +} + +impl JsonLinesParser<CheckMessage> for CheckParser { + fn from_line(&self, line: &str, error: &mut String) -> Option<CheckMessage> { + self.parse_line(line, error) + } + + fn from_stderr_line(&self, line: &str, error: &mut String) -> Option<CheckMessage> { + self.parse_line(line, error) + } fn from_eof(&self) -> Option<CheckMessage> { None diff --git a/crates/rust-analyzer/src/test_runner.rs b/crates/rust-analyzer/src/test_runner.rs index 31f35df5c7..4f5c00192d 100644 --- a/crates/rust-analyzer/src/test_runner.rs +++ b/crates/rust-analyzer/src/test_runner.rs @@ -72,6 +72,10 @@ impl JsonLinesParser<CargoTestMessage> for CargoTestOutputParser { }) } + fn from_stderr_line(&self, line: &str, error: &mut String) -> Option<CargoTestMessage> { + self.from_line(line, error) + } + fn from_eof(&self) -> Option<CargoTestMessage> { Some(CargoTestMessage { target: self.target.clone(), output: CargoTestOutput::Finished }) } |