From 449d1dfdfbf56ace564182dc85802e57b8494975 Mon Sep 17 00:00:00 2001 From: Michael Davis Date: Mon, 18 Apr 2022 10:11:28 -0500 Subject: [PATCH] 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. --- helix-lsp/src/lib.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/helix-lsp/src/lib.rs b/helix-lsp/src/lib.rs index 13ac32ff..47a376bb 100644 --- a/helix-lsp/src/lib.rs +++ b/helix-lsp/src/lib.rs @@ -276,7 +276,13 @@ impl Notification { lsp::notification::PublishDiagnostics::METHOD => { let params: lsp::PublishDiagnosticsParams = params .parse() - .expect("Failed to parse PublishDiagnostics params"); + .map_err(|err| { + log::error!( + "received malformed PublishDiagnostic from Language Server: {}", + err + ) + }) + .ok()?; // TODO: need to loop over diagnostics and distinguish them by URI Self::PublishDiagnostics(params)