mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-30 22:34:13 +00:00
Add more data into LSP header parsing error contexts (#7282)
Follow-up of https://github.com/zed-industries/zed/pull/6929 Release Notes: - N/A
This commit is contained in:
parent
33e5ba6278
commit
bacb2a266a
1 changed files with 17 additions and 15 deletions
|
@ -336,38 +336,40 @@ impl LanguageServer {
|
||||||
|
|
||||||
let message_len: usize = segments
|
let message_len: usize = segments
|
||||||
.next()
|
.next()
|
||||||
.context("unable to find the first line of the LSP message header")?
|
.with_context(|| {
|
||||||
|
format!("unable to find the first line of the LSP message header `{header}`")
|
||||||
|
})?
|
||||||
.strip_prefix(CONTENT_LEN_HEADER)
|
.strip_prefix(CONTENT_LEN_HEADER)
|
||||||
.context("invalid LSP message header")?
|
.with_context(|| format!("invalid LSP message header `{header}`"))?
|
||||||
.parse()
|
.parse()
|
||||||
.with_context(|| {
|
.with_context(|| {
|
||||||
format!(
|
format!("failed to parse Content-Length of LSP message header: `{header}`")
|
||||||
"failed to parse Content-Length of LSP message header: {}",
|
|
||||||
header
|
|
||||||
)
|
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(second_segment) = segments.next() {
|
if let Some(second_segment) = segments.next() {
|
||||||
match second_segment {
|
match second_segment {
|
||||||
"" => (), // Header end
|
"" => (), // Header end
|
||||||
header_field if header_field.starts_with("Content-Type:") => {
|
header_field => {
|
||||||
|
if header_field.starts_with("Content-Type:") {
|
||||||
stdout.read_until(b'\n', &mut buffer).await?;
|
stdout.read_until(b'\n', &mut buffer).await?;
|
||||||
}
|
} else {
|
||||||
_ => {
|
|
||||||
anyhow::bail!(
|
anyhow::bail!(
|
||||||
"expected a Content-Type header field or a header ending CRLF, got {second_segment:?}"
|
"inside `{header}`, expected a Content-Type header field or a header ending CRLF, got `{second_segment:?}`"
|
||||||
);
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
anyhow::bail!("unable to find the second line of the LSP message header");
|
anyhow::bail!(
|
||||||
|
"unable to find the second line of the LSP message header `{header}`"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.resize(message_len, 0);
|
buffer.resize(message_len, 0);
|
||||||
stdout.read_exact(&mut buffer).await?;
|
stdout.read_exact(&mut buffer).await?;
|
||||||
|
|
||||||
if let Ok(message) = str::from_utf8(&buffer) {
|
if let Ok(message) = str::from_utf8(&buffer) {
|
||||||
log::trace!("incoming message: {}", message);
|
log::trace!("incoming message: {message}");
|
||||||
for handler in io_handlers.lock().values_mut() {
|
for handler in io_handlers.lock().values_mut() {
|
||||||
handler(IoKind::StdOut, message);
|
handler(IoKind::StdOut, message);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue