on master help sign in
fix: Work around crashes on LSPs that don't just emit JSON-RPC
847d1faBlaž Hrastnik
helix-lsp/src/transport.rs+8−3
@@ -1,7 +1,7 @@
1use crate::Result;
1use crate::Result;
2−use anyhow::{anyhow, Context};
2+use anyhow::Context;
3use jsonrpc_core as jsonrpc;
3use jsonrpc_core as jsonrpc;
4−use log::{debug, error, info};
4+use log::{debug, error, info, warn};
5use serde::{Deserialize, Serialize};
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
6use serde_json::Value;
7use std::collections::HashMap;
7use std::collections::HashMap;
@@ -92,7 +92,12 @@ impl Transport {
92 content_length = Some(value.parse().context("invalid content length")?);
92 content_length = Some(value.parse().context("invalid content length")?);
93 }
93 }
94 Some((_, _)) => {}
94 Some((_, _)) => {}
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.
95− None => return Err(anyhow!("Failed to parse header: {:?}", header).into()),
99+ warn!("Failed to parse header: {:?}", header);
100+ }
96 }
101 }
97 }
102 }
98
103