aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp/src
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-31 05:27:55 +0000
committerBlaž Hrastnik2021-09-06 06:25:46 +0000
commit41f1e8e4fb4b3b387f34ef5d2e913e7ebc7fd888 (patch)
tree2ed8fca0486d7956bddeaf93f9d67f58a777271d /helix-lsp/src
parentfe17b99ab399d1ee5483ad54c6b124af869afdb6 (diff)
fix: lsp: Terminate transport on EOF
If stdout/stderr is closed, read_line will return 0 indicating EOF.
Diffstat (limited to 'helix-lsp/src')
-rw-r--r--helix-lsp/src/transport.rs17
1 files changed, 11 insertions, 6 deletions
diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs
index 67b7b48f..9353de20 100644
--- a/helix-lsp/src/transport.rs
+++ b/helix-lsp/src/transport.rs
@@ -1,4 +1,4 @@
-use crate::Result;
+use crate::{Error, Result};
use anyhow::Context;
use jsonrpc_core as jsonrpc;
use log::{debug, error, info, warn};
@@ -76,14 +76,17 @@ impl Transport {
let mut content_length = None;
loop {
buffer.truncate(0);
- reader.read_line(buffer).await?;
- let header = buffer.trim();
+ if reader.read_line(buffer).await? == 0 {
+ return Err(Error::StreamClosed);
+ };
+
+ // debug!("<- header {:?}", buffer);
if header.is_empty() {
break;
}
- debug!("<- header {}", header);
+ let header = buffer.trim();
let parts = header.split_once(": ");
@@ -121,8 +124,10 @@ impl Transport {
buffer: &mut String,
) -> Result<()> {
buffer.truncate(0);
- err.read_line(buffer).await?;
- error!("err <- {}", buffer);
+ if err.read_line(buffer).await? == 0 {
+ return Err(Error::StreamClosed);
+ };
+ error!("err <- {:?}", buffer);
Ok(())
}