Skip to content

Commit

Permalink
Handle multiple headers
Browse files Browse the repository at this point in the history
  • Loading branch information
agent3bood committed Feb 2, 2024
1 parent a7462f6 commit b8a1416
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions crates/lsp/src/lsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,21 +320,26 @@ impl LanguageServer {
}
});
let mut buffer = Vec::new();
loop {
'outer: loop {
buffer.clear();

if stdout.read_until(b'\n', &mut buffer).await? == 0 {
break;
};

if stdout.read_until(b'\n', &mut buffer).await? == 0 {
break;
};
while let Ok(bytes_read) = stdout.read_until(b'\n', &mut buffer).await {
if bytes_read == 0 {
break 'outer;
}
if buffer.ends_with(b"\r\n\r\n") {
break;
}
}

let header = std::str::from_utf8(&buffer)?;
let message_len: usize = header
.strip_prefix(CONTENT_LEN_HEADER)
.ok_or_else(|| anyhow!("invalid LSP message header {header:?}"))?
.split_whitespace()
.collect::<Vec<&str>>()
.get_mut(0)
.ok_or_else(|| anyhow!("invalid LSP message header {header:?}"))?
.trim_end()
.parse()?;

Expand Down

0 comments on commit b8a1416

Please sign in to comment.