diff options
author | Mathias Fußenegger <mfussenegger@users.noreply.github.com> | 2020-04-26 23:56:30 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-26 14:56:30 -0700 |
commit | 50ff37308abde6c33c2800529cd58f1d7413d7b3 (patch) | |
tree | d7aebce15db80c399e6f7a4d71d60158a57ae5ce | |
parent | 05a07ff7afd4e5ffd5be0a0e14338a23af6044f3 (diff) | |
download | rneovim-50ff37308abde6c33c2800529cd58f1d7413d7b3.tar.gz rneovim-50ff37308abde6c33c2800529cd58f1d7413d7b3.tar.bz2 rneovim-50ff37308abde6c33c2800529cd58f1d7413d7b3.zip |
LSP: Fix show_line_diagnostics #12186
Messed this up in ef0398fe88e6cc74f33fb20519997774168d7832
-rw-r--r-- | runtime/lua/vim/lsp/util.lua | 3 | ||||
-rw-r--r-- | test/functional/plugin/lsp_spec.lua | 25 |
2 files changed, 27 insertions, 1 deletions
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua index be391c8b5b..e45104789e 100644 --- a/runtime/lua/vim/lsp/util.lua +++ b/runtime/lua/vim/lsp/util.lua @@ -696,7 +696,7 @@ do local buffer_diagnostics = M.diagnostics_by_buf[bufnr] if not buffer_diagnostics then return end - local line_diagnostics = M.diagnostics_group_by_line(buffer_diagnostics[line]) + local line_diagnostics = M.diagnostics_group_by_line(buffer_diagnostics)[line] if not line_diagnostics then return end for i, diagnostic in ipairs(line_diagnostics) do @@ -707,6 +707,7 @@ do -- TODO(ashkan) make format configurable? local prefix = string.format("%d. ", i) local hiname = severity_highlights[diagnostic.severity] + assert(hiname, 'unknown severity: ' .. tostring(diagnostic.severity)) local message_lines = split_lines(diagnostic.message) table.insert(lines, prefix..message_lines[1]) table.insert(highlights, {#prefix + 1, hiname}) diff --git a/test/functional/plugin/lsp_spec.lua b/test/functional/plugin/lsp_spec.lua index a57443f909..e53fb5b9e2 100644 --- a/test/functional/plugin/lsp_spec.lua +++ b/test/functional/plugin/lsp_spec.lua @@ -861,4 +861,29 @@ describe('LSP', function() ]]) end) end) + describe('lsp.util.show_line_diagnostics', function() + it('creates floating window and returns popup bufnr and winnr if current line contains diagnostics', function() + eq(3, exec_lua [[ + local buffer = vim.api.nvim_create_buf(false, true) + vim.api.nvim_buf_set_lines(buffer, 0, -1, false, { + "testing"; + "123"; + }) + local diagnostics = { + { + range = { + start = { line = 0; character = 1; }; + ["end"] = { line = 0; character = 3; }; + }; + severity = vim.lsp.protocol.DiagnosticSeverity.Error; + message = "Syntax error"; + }, + } + vim.api.nvim_win_set_buf(0, buffer) + vim.lsp.util.buf_diagnostics_save_positions(vim.fn.bufnr(buffer), diagnostics) + local popup_bufnr, winnr = vim.lsp.util.show_line_diagnostics() + return popup_bufnr + ]]) + end) + end) end) |