mirror of
https://github.com/neovim/neovim
synced 2025-07-20 21:32:16 +00:00
feat(diagnostic): vim.diagnostic.setqflist improvements #30868
1. Use the new "u" action to update the quickfix list so we don't lose our position in the quickfix list when updating it. 2. Rather than creating a new quickfix list each time, update the exiting one if we've already created one.
This commit is contained in:
committed by
GitHub
parent
e2a91876ac
commit
7579af3c51
@ -303,6 +303,8 @@ UI
|
|||||||
|hl-PmenuSel| and |hl-PmenuMatch| both inherit from |hl-Pmenu|, and
|
|hl-PmenuSel| and |hl-PmenuMatch| both inherit from |hl-Pmenu|, and
|
||||||
|hl-PmenuMatchSel| inherits highlights from both |hl-PmenuSel| and
|
|hl-PmenuMatchSel| inherits highlights from both |hl-PmenuSel| and
|
||||||
|hl-PmenuMatch|.
|
|hl-PmenuMatch|.
|
||||||
|
• |vim.diagnostic.setqflist()| updates existing diagnostics quickfix list if one
|
||||||
|
exists.
|
||||||
|
|
||||||
• |ui-messages| content chunks now also contain the highlight group ID.
|
• |ui-messages| content chunks now also contain the highlight group ID.
|
||||||
|
|
||||||
|
@ -2,6 +2,8 @@ local api, if_nil = vim.api, vim.F.if_nil
|
|||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local _qf_id = nil
|
||||||
|
|
||||||
--- [diagnostic-structure]()
|
--- [diagnostic-structure]()
|
||||||
---
|
---
|
||||||
--- Diagnostics use the same indexing as the rest of the Nvim API (i.e. 0-based
|
--- Diagnostics use the same indexing as the rest of the Nvim API (i.e. 0-based
|
||||||
@ -848,9 +850,24 @@ local function set_list(loclist, opts)
|
|||||||
local diagnostics = get_diagnostics(bufnr, opts --[[@as vim.diagnostic.GetOpts]], false)
|
local diagnostics = get_diagnostics(bufnr, opts --[[@as vim.diagnostic.GetOpts]], false)
|
||||||
local items = M.toqflist(diagnostics)
|
local items = M.toqflist(diagnostics)
|
||||||
if loclist then
|
if loclist then
|
||||||
vim.fn.setloclist(winnr, {}, ' ', { title = title, items = items })
|
vim.fn.setloclist(winnr, {}, 'u', { title = title, items = items })
|
||||||
else
|
else
|
||||||
vim.fn.setqflist({}, ' ', { title = title, items = items })
|
-- 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
|
||||||
|
|
||||||
|
-- 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 ' ', {
|
||||||
|
title = title,
|
||||||
|
items = items,
|
||||||
|
id = _qf_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Get the id of the newly created quickfix list.
|
||||||
|
_qf_id = vim.fn.getqflist({ id = 0 }).id
|
||||||
end
|
end
|
||||||
if open then
|
if open then
|
||||||
api.nvim_command(loclist and 'lwindow' or 'botright cwindow')
|
api.nvim_command(loclist and 'lwindow' or 'botright cwindow')
|
||||||
|
Reference in New Issue
Block a user