mirror of
https://github.com/neovim/neovim.git
synced 2024-12-19 02:34:59 -07:00
fix(diagnostic): vim.diagnostic.setqflist() opens loclist on first call #31585
Problem:
Regression from de794f2d24
: `vim.diagnostic.setqflist{open=true}` attempts to
open the location list instead of the diagnostics quickfix list if it didn't
exist before. This is because we are using `qf_id` to decide which to open, but
`qf_id=nil` when there is no existing diagnostics quickfix list with a given
title ("Diagnostics" by default).
Solution:
- Revert to using `loclist` to decide which to open.
- Add tests.
This commit is contained in:
parent
798f928479
commit
6c975515c5
@ -871,7 +871,7 @@ local function set_list(loclist, opts)
|
||||
end
|
||||
|
||||
if open then
|
||||
if qf_id then
|
||||
if not loclist then
|
||||
-- First navigate to the diagnostics quickfix list.
|
||||
local nr = vim.fn.getqflist({ id = qf_id, nr = 0 }).nr
|
||||
api.nvim_command(nr .. 'chistory')
|
||||
|
@ -5,6 +5,7 @@ local command = n.command
|
||||
local clear = n.clear
|
||||
local exec_lua = n.exec_lua
|
||||
local eq = t.eq
|
||||
local neq = t.neq
|
||||
local matches = t.matches
|
||||
local api = n.api
|
||||
local pcall_err = t.pcall_err
|
||||
@ -3212,6 +3213,74 @@ describe('vim.diagnostic', function()
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('setqflist()', function()
|
||||
it('updates existing diagnostics quickfix if one already exists', function()
|
||||
local result = exec_lua(function()
|
||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||
|
||||
vim.fn.setqflist({}, ' ', { title = 'Diagnostics' })
|
||||
local diagnostics_qf_id = vim.fn.getqflist({ id = 0 }).id
|
||||
|
||||
vim.diagnostic.setqflist({ title = 'Diagnostics' })
|
||||
local qf_id = vim.fn.getqflist({ id = 0, nr = '$' }).id
|
||||
|
||||
return { diagnostics_qf_id, qf_id }
|
||||
end)
|
||||
|
||||
eq(result[1], result[2])
|
||||
end)
|
||||
|
||||
it('navigates to existing diagnostics quickfix if one already exists and open=true', function()
|
||||
local result = exec_lua(function()
|
||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||
|
||||
vim.fn.setqflist({}, ' ', { title = 'Diagnostics' })
|
||||
local diagnostics_qf_id = vim.fn.getqflist({ id = 0 }).id
|
||||
|
||||
vim.fn.setqflist({}, ' ', { title = 'Other' })
|
||||
|
||||
vim.diagnostic.setqflist({ title = 'Diagnostics', open = true })
|
||||
local qf_id = vim.fn.getqflist({ id = 0 }).id
|
||||
|
||||
return { diagnostics_qf_id, qf_id }
|
||||
end)
|
||||
|
||||
eq(result[1], result[2])
|
||||
end)
|
||||
|
||||
it('sets new diagnostics quickfix as active when open=true', function()
|
||||
local result = exec_lua(function()
|
||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||
|
||||
vim.fn.setqflist({}, ' ', { title = 'Other' })
|
||||
local other_qf_id = vim.fn.getqflist({ id = 0 }).id
|
||||
|
||||
vim.diagnostic.setqflist({ title = 'Diagnostics', open = true })
|
||||
local qf_id = vim.fn.getqflist({ id = 0 }).id
|
||||
|
||||
return { other_qf_id, qf_id }
|
||||
end)
|
||||
|
||||
neq(result[1], result[2])
|
||||
end)
|
||||
|
||||
it('opens quickfix window when open=true', function()
|
||||
local qf_winid = exec_lua(function()
|
||||
vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr)
|
||||
|
||||
vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, {
|
||||
_G.make_error('Error', 1, 1, 1, 1),
|
||||
})
|
||||
|
||||
vim.diagnostic.setqflist({ open = true })
|
||||
|
||||
return vim.fn.getqflist({ winid = 0 }).winid
|
||||
end)
|
||||
|
||||
neq(0, qf_winid)
|
||||
end)
|
||||
end)
|
||||
|
||||
describe('match()', function()
|
||||
it('matches a string', function()
|
||||
local msg = 'ERROR: george.txt:19:84:Two plus two equals five'
|
||||
|
Loading…
Reference in New Issue
Block a user