From 7d4451c65785ef7e781bf5029da059fb77b728b7 Mon Sep 17 00:00:00 2001 From: Ghjuvan Lacambre Date: Sat, 18 Apr 2020 18:21:08 +0200 Subject: [PATCH] LSP: fix breakage when severity isn't specified (#12027) Before this commit, the LSP client would throw errors when messages without severity would be sent by the server. We make severity default to `Error` as a kludge before proper heuristics to discover the severity of a message are found. --- runtime/lua/vim/lsp/callbacks.lua | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/runtime/lua/vim/lsp/callbacks.lua b/runtime/lua/vim/lsp/callbacks.lua index 644c12f98c..c403a3fd51 100644 --- a/runtime/lua/vim/lsp/callbacks.lua +++ b/runtime/lua/vim/lsp/callbacks.lua @@ -29,6 +29,17 @@ M['textDocument/publishDiagnostics'] = function(_, _, result) return end util.buf_clear_diagnostics(bufnr) + + -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#diagnostic + -- The diagnostic's severity. Can be omitted. If omitted it is up to the + -- client to interpret diagnostics as error, warning, info or hint. + -- TODO: Replace this with server-specific heuristics to infer severity. + for _, diagnostic in ipairs(result.diagnostics) do + if diagnostic.severity == nil then + diagnostic.severity = protocol.DiagnosticSeverity.Error + end + end + util.buf_diagnostics_save_positions(bufnr, result.diagnostics) util.buf_diagnostics_underline(bufnr, result.diagnostics) util.buf_diagnostics_virtual_text(bufnr, result.diagnostics)