Skip to content

Commit

Permalink
prevent panic when receiving malformed LSP PublishDiagnostic (#2160)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
the-mikedavis authored Apr 18, 2022
1 parent 4b1fe36 commit 449d1df
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion helix-lsp/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 449d1df

Please sign in to comment.