on master help sign in
prevent panic when receiving malformed LSP PublishDiagnostic (#2160)

Instead of panicing we can discard the malformed diagnostic. This `.parse()` fails commonly when a non-conformant language server gives a diagnostic with a location that breaks the spec: { "character": 0, "line": -1 } can currently be returned by ElixirLS and the python LS. Other messages in this block are discarded but this one feels special enough to log.

commit449d1dfdfbf56ace564182dc85802e57b8494975 authorMichael Davis <mcarsondavis@gmail.com> dateMon 18 Apr 2022, 10:11 (5 years ago) parent4b1fe36
1 file changed+7−1
helix-lsp/src/lib.rs+7−1
helix-lsp/src/lib.rs+7−1
@@ -276,7 +276,13 @@ impl Notification {
276276 lsp::notification::PublishDiagnostics::METHOD => {
277277 let params: lsp::PublishDiagnosticsParams = params
278278 .parse()
279− .expect("Failed to parse PublishDiagnostics params");
279+ .map_err(|err| {
280+ log::error!(
281+ "received malformed PublishDiagnostic from Language Server: {}",
282+ err
283+ )
284+ })
285+ .ok()?;
280286
281287 // TODO: need to loop over diagnostics and distinguish them by URI
282288 Self::PublishDiagnostics(params)