Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

lsp: if language server closes stdout/stderr, break loop (#7229)

Thorsten Ball3107ed847a15
diff --git a/crates/lsp/src/lsp.rs b/crates/lsp/src/lsp.rs
index 0d88e1507c7..f9cd138217c 100644
--- a/crates/lsp/src/lsp.rs
+++ b/crates/lsp/src/lsp.rs
@@ -322,8 +322,15 @@ impl LanguageServer {
let mut buffer = Vec::new();
loop {
buffer.clear();
- stdout.read_until(b'\n', &mut buffer).await?;
- stdout.read_until(b'\n', &mut buffer).await?;
+
+ if stdout.read_until(b'\n', &mut buffer).await? == 0 {
+ break;
+ };
+
+ if stdout.read_until(b'\n', &mut buffer).await? == 0 {
+ break;
+ };
+
let header = std::str::from_utf8(&buffer)?;
let message_len: usize = header
.strip_prefix(CONTENT_LEN_HEADER)
@@ -378,6 +385,8 @@ impl LanguageServer {
// Don't starve the main thread when receiving lots of messages at once.
smol::future::yield_now().await;
}
+
+ Ok(())
}
async fn handle_stderr<Stderr>(
@@ -393,7 +402,12 @@ impl LanguageServer {
loop {
buffer.clear();
- stderr.read_until(b'\n', &mut buffer).await?;
+
+ let bytes_read = stderr.read_until(b'\n', &mut buffer).await?;
+ if bytes_read == 0 {
+ return Ok(());
+ }
+
if let Ok(message) = str::from_utf8(&buffer) {
log::trace!("incoming stderr message:{message}");
for handler in io_handlers.lock().values_mut() {