mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 18:55:14 -07:00
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:
parent
1a60580925
commit
150a5922aa
@ -289,11 +289,11 @@ option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).
|
|||||||
==============================================================================
|
==============================================================================
|
||||||
EVENTS *diagnostic-events*
|
EVENTS *diagnostic-events*
|
||||||
|
|
||||||
*DiagnosticsChanged*
|
*DiagnosticChanged*
|
||||||
DiagnosticsChanged After diagnostics have changed.
|
DiagnosticChanged After diagnostics have changed.
|
||||||
|
|
||||||
Example: >
|
Example: >
|
||||||
autocmd User DiagnosticsChanged lua vim.diagnostic.setqflist({open = false })
|
autocmd DiagnosticChanged * lua vim.diagnostic.setqflist({open = false })
|
||||||
<
|
<
|
||||||
==============================================================================
|
==============================================================================
|
||||||
==============================================================================
|
==============================================================================
|
||||||
|
@ -671,12 +671,14 @@ function M.set(namespace, bufnr, diagnostics, opts)
|
|||||||
M.show(namespace, bufnr, diagnostics, opts)
|
M.show(namespace, bufnr, diagnostics, opts)
|
||||||
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
|
end
|
||||||
|
|
||||||
--- Get namespace metadata.
|
--- Get namespace metadata.
|
||||||
---
|
---
|
||||||
---@param ns number Diagnostic namespace
|
---@param namespace number Diagnostic namespace
|
||||||
---@return table Namespace metadata
|
---@return table Namespace metadata
|
||||||
function M.get_namespace(namespace)
|
function M.get_namespace(namespace)
|
||||||
vim.validate { namespace = { namespace, 'n' } }
|
vim.validate { namespace = { namespace, 'n' } }
|
||||||
@ -1331,7 +1333,9 @@ function M.reset(namespace, bufnr)
|
|||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|
||||||
--- Add all diagnostics to the quickfix list.
|
--- Add all diagnostics to the quickfix list.
|
||||||
|
@ -220,9 +220,6 @@ function M.on_publish_diagnostics(_, result, ctx, config)
|
|||||||
end
|
end
|
||||||
|
|
||||||
vim.diagnostic.set(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id))
|
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
|
end
|
||||||
|
|
||||||
--- Clear diagnotics and diagnostic cache.
|
--- Clear diagnotics and diagnostic cache.
|
||||||
|
@ -37,6 +37,7 @@ return {
|
|||||||
'CursorHoldI', -- idem, in Insert mode
|
'CursorHoldI', -- idem, in Insert mode
|
||||||
'CursorMoved', -- cursor was moved
|
'CursorMoved', -- cursor was moved
|
||||||
'CursorMovedI', -- cursor was moved in Insert mode
|
'CursorMovedI', -- cursor was moved in Insert mode
|
||||||
|
'DiagnosticChanged', -- diagnostics in a buffer were modified
|
||||||
'DiffUpdated', -- diffs have been updated
|
'DiffUpdated', -- diffs have been updated
|
||||||
'DirChanged', -- directory changed
|
'DirChanged', -- directory changed
|
||||||
'EncodingChanged', -- after changing the 'encoding' option
|
'EncodingChanged', -- after changing the 'encoding' option
|
||||||
@ -126,6 +127,7 @@ return {
|
|||||||
-- syntax file
|
-- syntax file
|
||||||
nvim_specific = {
|
nvim_specific = {
|
||||||
BufModifiedSet=true,
|
BufModifiedSet=true,
|
||||||
|
DiagnosticChanged=true,
|
||||||
DirChanged=true,
|
DirChanged=true,
|
||||||
Signal=true,
|
Signal=true,
|
||||||
TabClosed=true,
|
TabClosed=true,
|
||||||
|
Loading…
Reference in New Issue
Block a user