on master help sign in
fix: Work around crashes on LSPs that don't just emit JSON-RPC
commit847d1fa496f157c1a9640c5cedd92d6593e33b08 authorBlaž Hrastnik <blaz@mxxn.io> dateSun 29 Aug 2021, 18:38 (5 years ago) parent7eff905
1 file changed+8−3
helix-lsp/src/transport.rs+8−3
helix-lsp/src/transport.rs+8−3
@@ -1,7 +1,7 @@
11use crate::Result;
2−use anyhow::{anyhow, Context};
2+use anyhow::Context;
33use jsonrpc_core as jsonrpc;
4−use log::{debug, error, info};
4+use log::{debug, error, info, warn};
55use serde::{Deserialize, Serialize};
66use serde_json::Value;
77use std::collections::HashMap;
@@ -92,7 +92,12 @@ impl Transport {
9292 content_length = Some(value.parse().context("invalid content length")?);
9393 }
9494 Some((_, _)) => {}
95− None => return Err(anyhow!("Failed to parse header: {:?}", header).into()),
95+ None => {
96+ // Workaround: Some non-conformant language servers will output logging and other garbage
97+ // into the same stream as JSON-RPC messages. This can also happen from shell scripts that spawn
98+ // the server. Skip such lines and log a warning.
99+ warn!("Failed to parse header: {:?}", header);
100+ }
96101 }
97102 }
98103