From 7b61c63ece4384f75fa41f6c052b3d9e506ff3aa Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Fri, 3 Sep 2021 13:26:10 +0900 Subject: Handle stderr --- helix-dap/src/client.rs | 8 ++++++-- helix-dap/src/transport.rs | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) (limited to 'helix-dap') diff --git a/helix-dap/src/client.rs b/helix-dap/src/client.rs index 5d9916c9..9f274002 100644 --- a/helix-dap/src/client.rs +++ b/helix-dap/src/client.rs @@ -62,10 +62,11 @@ impl Client { pub fn streams( rx: Box, tx: Box, + err: Option>, id: usize, process: Option, ) -> Result<(Self, UnboundedReceiver)> { - let (server_rx, server_tx) = Transport::start(rx, tx, id); + let (server_rx, server_tx) = Transport::start(rx, tx, err, id); let (client_rx, client_tx) = unbounded_channel(); let client = Self { @@ -92,7 +93,7 @@ impl Client { ) -> Result<(Self, UnboundedReceiver)> { let stream = TcpStream::connect(addr).await?; let (rx, tx) = stream.into_split(); - Self::streams(Box::new(BufReader::new(rx)), Box::new(tx), id, None) + Self::streams(Box::new(BufReader::new(rx)), Box::new(tx), None, id, None) } pub fn stdio( @@ -113,10 +114,12 @@ impl Client { // TODO: do we need bufreader/writer here? or do we use async wrappers on unblock? let writer = BufWriter::new(process.stdin.take().expect("Failed to open stdin")); let reader = BufReader::new(process.stdout.take().expect("Failed to open stdout")); + let errors = BufReader::new(process.stderr.take().expect("Failed to open stderr")); Self::streams( Box::new(BufReader::new(reader)), Box::new(writer), + Some(Box::new(BufReader::new(errors))), id, Some(process), ) @@ -167,6 +170,7 @@ impl Client { Self::streams( Box::new(BufReader::new(rx)), Box::new(tx), + None, id, Some(process), ) diff --git a/helix-dap/src/transport.rs b/helix-dap/src/transport.rs index afb7694d..a20dfbe1 100644 --- a/helix-dap/src/transport.rs +++ b/helix-dap/src/transport.rs @@ -53,6 +53,7 @@ impl Transport { pub fn start( server_stdout: Box, server_stdin: Box, + server_stderr: Option>, id: usize, ) -> (UnboundedReceiver, UnboundedSender) { let (client_tx, rx) = unbounded_channel(); @@ -67,6 +68,9 @@ impl Transport { tokio::spawn(Self::recv(transport.clone(), server_stdout, client_tx)); tokio::spawn(Self::send(transport, server_stdin, client_rx)); + if let Some(stderr) = server_stderr { + tokio::spawn(Self::err(stderr)); + } (rx, tx) } @@ -117,6 +121,17 @@ impl Transport { Ok(output?) } + async fn recv_server_error( + err: &mut (impl AsyncBufRead + Unpin + Send), + buffer: &mut String, + ) -> Result<()> { + buffer.truncate(0); + err.read_line(buffer).await?; + error!("err <- {}", buffer); + + Ok(()) + } + async fn send_payload_to_server( &self, server_stdin: &mut Box, @@ -243,4 +258,17 @@ impl Transport { .unwrap() } } + + async fn err(mut server_stderr: Box) { + let mut recv_buffer = String::new(); + loop { + match Self::recv_server_error(&mut server_stderr, &mut recv_buffer).await { + Ok(_) => {} + Err(err) => { + error!("err: <- {:?}", err); + break; + } + } + } + } } -- cgit v1.2.3-70-g09d2