LSP: Expose diagnostics grouped by bufnr (#11932)

Expose `vim.lsp.buf.diagnostics_by_buf`

This makes it easier to customize the diagnostics behavior. For example
to defer the update they can override the
`textDocument/publishDiagnostics` callback to only call
`buf_diagnostics_save_positions` and then defer the other actions to a
autocmd event.
This commit is contained in:
Mathias Fußenegger
2020-04-25 15:46:58 +02:00
committed by GitHub
parent 78d58eaf61
commit ef0398fe88
3 changed files with 92 additions and 34 deletions

View File

@@ -845,4 +845,20 @@ describe('LSP', function()
eq({}, exec_lua([[return vim.lsp.util.text_document_completion_list_to_complete_items(...)]], {}, prefix))
end)
end)
describe('buf_diagnostics_save_positions', function()
it('stores the diagnostics in diagnostics_by_buf', function ()
local diagnostics = {
{ range = {}; message = "diag1" },
{ range = {}; message = "diag2" },
}
exec_lua([[
vim.lsp.util.buf_diagnostics_save_positions(...)]], 0, diagnostics)
eq(1, exec_lua [[ return #vim.lsp.util.diagnostics_by_buf ]])
eq(diagnostics, exec_lua [[
for _, diagnostics in pairs(vim.lsp.util.diagnostics_by_buf) do
return diagnostics
end
]])
end)
end)
end)