diff options
author | Jeremy Fleischman <jeremyfleischman@gmail.com> | 2024-12-11 17:29:54 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-11 17:29:54 -0800 |
commit | 21961967ffef6d49512b83a23b6c93bb8b80389a (patch) | |
tree | 0a3178d768c1085fc46294aca167110b56bf16e3 /runtime/lua/vim | |
parent | 442d338cb50e4cf08c58cb82b6d33b6d5df9fb1b (diff) | |
download | rneovim-21961967ffef6d49512b83a23b6c93bb8b80389a.tar.gz rneovim-21961967ffef6d49512b83a23b6c93bb8b80389a.tar.bz2 rneovim-21961967ffef6d49512b83a23b6c93bb8b80389a.zip |
feat(diagnostic): update quickfix list by title #31486
Previously, there was a singleton diagnostics quickfix list. Now there's
effectively one per title (up to vim's internal limit on quickfix
lists).
Suggested by mfussenegger https://github.com/neovim/neovim/pull/30868#pullrequestreview-2385761374.
Diffstat (limited to 'runtime/lua/vim')
-rw-r--r-- | runtime/lua/vim/diagnostic.lua | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua index 340bca4f6b..1b61cf8f71 100644 --- a/runtime/lua/vim/diagnostic.lua +++ b/runtime/lua/vim/diagnostic.lua @@ -2,7 +2,19 @@ local api, if_nil = vim.api, vim.F.if_nil local M = {} -local _qf_id = nil +--- @param title string +--- @return integer? +local function get_qf_id_for_title(title) + local lastqflist = vim.fn.getqflist({ nr = '$' }) + for i = 1, lastqflist.nr do + local qflist = vim.fn.getqflist({ nr = i, id = 0, title = 0 }) + if qflist.title == title then + return qflist.id + end + end + + return nil +end --- [diagnostic-structure]() --- @@ -845,24 +857,16 @@ local function set_list(loclist, opts) if loclist then vim.fn.setloclist(winnr, {}, 'u', { title = title, items = items }) else - -- Check if the diagnostics quickfix list no longer exists. - if _qf_id and vim.fn.getqflist({ id = _qf_id }).id == 0 then - _qf_id = nil - end + local qf_id = get_qf_id_for_title(title) -- If we already have a diagnostics quickfix, update it rather than creating a new one. -- This avoids polluting the finite set of quickfix lists, and preserves the currently selected -- entry. - vim.fn.setqflist({}, _qf_id and 'u' or ' ', { + vim.fn.setqflist({}, qf_id and 'u' or ' ', { title = title, items = items, - id = _qf_id, + id = qf_id, }) - - -- Get the id of the newly created quickfix list. - if _qf_id == nil then - _qf_id = vim.fn.getqflist({ id = 0 }).id - end end if open then api.nvim_command(loclist and 'lwindow' or 'botright cwindow') @@ -2037,7 +2041,8 @@ end --- (default: `true`) --- @field open? boolean --- ---- Title of quickfix list. Defaults to "Diagnostics". +--- Title of quickfix list. Defaults to "Diagnostics". If there's already a quickfix list with this +--- title, it's updated. If not, a new quickfix list is created. --- @field title? string --- --- See |diagnostic-severity|. |