refactor(diagnostics): always make 'set' go through 'show'

Always make calls to `vim.diagnostic.set` call `vim.diagnostic.show`.
This creates an easier to reason about code path and is also less
surprising when users wish to override override `vim.diagnostic.show`
with custom behavior and `vim.diagnostic.set` is called with empty
diagnostics.

Functionally, the end result is the same: when `show` is called with an
empty diagnostics list, it just calls `hide` and then returns, which is
exactly what `reset` does right now.
This commit is contained in:
Gregory Anders
2021-09-27 07:57:53 -07:00
parent 1124439954
commit 0f554ef6f8

View File

@@ -620,23 +620,22 @@ function M.set(namespace, bufnr, diagnostics, opts)
}
if vim.tbl_isempty(diagnostics) then
return M.reset(namespace, bufnr)
clear_diagnostic_cache(namespace, bufnr)
else
if not diagnostic_cleanup[bufnr][namespace] then
diagnostic_cleanup[bufnr][namespace] = true
-- Clean up our data when the buffer unloads.
vim.api.nvim_buf_attach(bufnr, false, {
on_detach = function(_, b)
clear_diagnostic_cache(b, namespace)
diagnostic_cleanup[b][namespace] = nil
end
})
end
set_diagnostic_cache(namespace, bufnr, diagnostics)
end
if not diagnostic_cleanup[bufnr][namespace] then
diagnostic_cleanup[bufnr][namespace] = true
-- Clean up our data when the buffer unloads.
vim.api.nvim_buf_attach(bufnr, false, {
on_detach = function(_, b)
clear_diagnostic_cache(b, namespace)
diagnostic_cleanup[b][namespace] = nil
end
})
end
set_diagnostic_cache(namespace, bufnr, diagnostics)
if vim.api.nvim_buf_is_loaded(bufnr) then
M.show(namespace, bufnr, diagnostics, opts)
elseif opts then