aboutsummaryrefslogtreecommitdiff
path: root/helix-lsp
diff options
context:
space:
mode:
authorBlaž Hrastnik2021-08-29 03:40:21 +0000
committerBlaž Hrastnik2021-08-29 03:40:21 +0000
commit7eff9056802d3d4f67fbaef7ba7dc03e874564c1 (patch)
tree0f766bf8befc88b80ed994de802e42fbc2cd24e5 /helix-lsp
parentd6a9c2c0f6f4af98146b52d1c886a1ca99d15676 (diff)
lsp: slightly refactor header parsing, add more logging
Diffstat (limited to 'helix-lsp')
-rw-r--r--helix-lsp/src/transport.rs22
1 files changed, 9 insertions, 13 deletions
diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs
index 5be694c8..068ea230 100644
--- a/helix-lsp/src/transport.rs
+++ b/helix-lsp/src/transport.rs
@@ -1,7 +1,7 @@
use crate::Result;
-use anyhow::Context;
+use anyhow::{anyhow, Context};
use jsonrpc_core as jsonrpc;
-use log::{error, info};
+use log::{debug, error, info};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::collections::HashMap;
@@ -83,20 +83,16 @@ impl Transport {
break;
}
- let mut parts = header.split(": ");
+ debug!("<- header {}", header);
- match (parts.next(), parts.next(), parts.next()) {
- (Some("Content-Length"), Some(value), None) => {
+ let parts = header.split_once(": ");
+
+ match parts {
+ Some(("Content-Length", value)) => {
content_length = Some(value.parse().context("invalid content length")?);
}
- (Some(_), Some(_), None) => {}
- _ => {
- return Err(std::io::Error::new(
- std::io::ErrorKind::Other,
- "Failed to parse header",
- )
- .into());
- }
+ Some((_, _)) => {}
+ None => return Err(anyhow!("Failed to parse header: {:?}", header).into()),
}
}