From 7eff9056802d3d4f67fbaef7ba7dc03e874564c1 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sun, 29 Aug 2021 12:40:21 +0900 Subject: lsp: slightly refactor header parsing, add more logging --- helix-lsp/src/transport.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'helix-lsp') 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()), } } -- cgit v1.2.3-70-g09d2 From 847d1fa496f157c1a9640c5cedd92d6593e33b08 Mon Sep 17 00:00:00 2001 From: Blaž Hrastnik Date: Sun, 29 Aug 2021 18:38:28 +0900 Subject: fix: Work around crashes on LSPs that don't just emit JSON-RPC --- helix-lsp/src/transport.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'helix-lsp') diff --git a/helix-lsp/src/transport.rs b/helix-lsp/src/transport.rs index 068ea230..67b7b48f 100644 --- a/helix-lsp/src/transport.rs +++ b/helix-lsp/src/transport.rs @@ -1,7 +1,7 @@ use crate::Result; -use anyhow::{anyhow, Context}; +use anyhow::Context; use jsonrpc_core as jsonrpc; -use log::{debug, error, info}; +use log::{debug, error, info, warn}; use serde::{Deserialize, Serialize}; use serde_json::Value; use std::collections::HashMap; @@ -92,7 +92,12 @@ impl Transport { content_length = Some(value.parse().context("invalid content length")?); } Some((_, _)) => {} - None => return Err(anyhow!("Failed to parse header: {:?}", header).into()), + None => { + // Workaround: Some non-conformant language servers will output logging and other garbage + // into the same stream as JSON-RPC messages. This can also happen from shell scripts that spawn + // the server. Skip such lines and log a warning. + warn!("Failed to parse header: {:?}", header); + } } } -- cgit v1.2.3-70-g09d2 From 9d83a4483d66deac956eb6c673bcb68ba33d71dc Mon Sep 17 00:00:00 2001 From: dependabot[bot] Date: Mon, 30 Aug 2021 23:07:19 +0000 Subject: build(deps): bump tokio from 1.10.0 to 1.10.1 Bumps [tokio](https://github.com/tokio-rs/tokio) from 1.10.0 to 1.10.1. - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.10.0...tokio-1.10.1) --- updated-dependencies: - dependency-name: tokio dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- Cargo.lock | 4 ++-- helix-lsp/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'helix-lsp') diff --git a/Cargo.lock b/Cargo.lock index 15ef348b..f7d8108f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -983,9 +983,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cf844b23c6131f624accf65ce0e4e9956a8bb329400ea5bcc26ae3a5c20b0b" +checksum = "92036be488bb6594459f2e03b60e42df6f937fe6ca5c5ffdcb539c6b84dc40f5" dependencies = [ "autocfg", "bytes", diff --git a/helix-lsp/Cargo.toml b/helix-lsp/Cargo.toml index 2d4a16c6..52e995f5 100644 --- a/helix-lsp/Cargo.toml +++ b/helix-lsp/Cargo.toml @@ -23,5 +23,5 @@ lsp-types = { version = "0.89", features = ["proposed"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" thiserror = "1.0" -tokio = { version = "1.9", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } +tokio = { version = "1.10", features = ["rt", "rt-multi-thread", "io-util", "io-std", "time", "process", "macros", "fs", "parking_lot"] } tokio-stream = "0.1.7" -- cgit v1.2.3-70-g09d2