feat(diagnostic)!: make DiagnosticChanged a first class autocmd (#16098)

This allows users to hook into diagnostic events with finer granularity
(e.g. per-buffer or file).

BREAKING CHANGE: DiagnosticsChanged and LspDiagnosticsChanged user
autocommands are removed.
This commit is contained in:
Gregory Anders 2021-11-25 11:55:11 -07:00 committed by GitHub
parent 1a60580925
commit 150a5922aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 9 deletions

View File

@ -289,11 +289,11 @@ option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).
==============================================================================
EVENTS *diagnostic-events*
*DiagnosticsChanged*
DiagnosticsChanged After diagnostics have changed.
*DiagnosticChanged*
DiagnosticChanged After diagnostics have changed.
Example: >
autocmd User DiagnosticsChanged lua vim.diagnostic.setqflist({open = false })
autocmd DiagnosticChanged * lua vim.diagnostic.setqflist({open = false })
<
==============================================================================
==============================================================================

View File

@ -671,12 +671,14 @@ function M.set(namespace, bufnr, diagnostics, opts)
M.show(namespace, bufnr, diagnostics, opts)
end
vim.api.nvim_command("doautocmd <nomodeline> User DiagnosticsChanged")
vim.api.nvim_command(
string.format("doautocmd <nomodeline> DiagnosticChanged %s", vim.api.nvim_buf_get_name(bufnr))
)
end
--- Get namespace metadata.
---
---@param ns number Diagnostic namespace
---@param namespace number Diagnostic namespace
---@return table Namespace metadata
function M.get_namespace(namespace)
vim.validate { namespace = { namespace, 'n' } }
@ -1331,7 +1333,9 @@ function M.reset(namespace, bufnr)
end
end
vim.api.nvim_command("doautocmd <nomodeline> User DiagnosticsChanged")
vim.api.nvim_command(
string.format("doautocmd <nomodeline> DiagnosticChanged %s", vim.api.nvim_buf_get_name(bufnr))
)
end
--- Add all diagnostics to the quickfix list.

View File

@ -220,9 +220,6 @@ function M.on_publish_diagnostics(_, result, ctx, config)
end
vim.diagnostic.set(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id))
-- Keep old autocmd for back compat. This should eventually be removed.
vim.api.nvim_command("doautocmd <nomodeline> User LspDiagnosticsChanged")
end
--- Clear diagnotics and diagnostic cache.

View File

@ -37,6 +37,7 @@ return {
'CursorHoldI', -- idem, in Insert mode
'CursorMoved', -- cursor was moved
'CursorMovedI', -- cursor was moved in Insert mode
'DiagnosticChanged', -- diagnostics in a buffer were modified
'DiffUpdated', -- diffs have been updated
'DirChanged', -- directory changed
'EncodingChanged', -- after changing the 'encoding' option
@ -126,6 +127,7 @@ return {
-- syntax file
nvim_specific = {
BufModifiedSet=true,
DiagnosticChanged=true,
DirChanged=true,
Signal=true,
TabClosed=true,