fix(diagnostic): make set() go through cache when calling show()

When `vim.diagnostic.set()` is called, the diagnostics passed to it are
added to the diagnostic cache. `set()` then calls `show()` and passes
those diagnostics along exactly as they were given to `set()`. However,
we sometimes want to do some kind of post-processing on diagnostics when
they come out of the cache, e.g. clamping line numbers. By forwarding
the diagnostics to `show()` verbatim, `set()` skips this post-processing
which can cause other bugs downstream.

Instead of passing the diagnostics directly, make the `show()` call from
within `set()` retrieve diagnostics from the cache. In general, all
diagnostics operations should follow the pattern of "producers put
things in the cache" and "consumers get things out of the cache" and
this change better adheres to that pattern.
This commit is contained in:
Gregory Anders 2021-11-27 12:32:40 -07:00
parent 03d250eb45
commit d93f47dc83

View File

@ -650,7 +650,7 @@ function M.set(namespace, bufnr, diagnostics, opts)
end
if vim.api.nvim_buf_is_loaded(bufnr) then
M.show(namespace, bufnr, diagnostics, opts)
M.show(namespace, bufnr, nil, opts)
end
vim.api.nvim_command(