Skip to content

Commit

Permalink
lsp: slightly refactor header parsing, add more logging
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Aug 29, 2021
1 parent d6a9c2c commit 7eff905
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions helix-lsp/src/transport.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()),
}
}

Expand Down

0 comments on commit 7eff905

Please sign in to comment.