Skip to content

Commit

Permalink
fix: lsp: Terminate transport on EOF
Browse files Browse the repository at this point in the history
If stdout/stderr is closed, read_line will return 0 indicating EOF.
  • Loading branch information
archseer committed Sep 6, 2021
1 parent fe17b99 commit 41f1e8e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions helix-lsp/src/transport.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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(": ");

Expand Down Expand Up @@ -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(())
}
Expand Down

0 comments on commit 41f1e8e

Please sign in to comment.