feat(diagnostic): don't open quickfix/loclist if no diagnostics #21397

This commit is contained in:
李晓辉 2022-12-31 02:23:54 +08:00 committed by GitHub
parent 849f544d62
commit 4ace9e7e41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -478,13 +478,17 @@ local function set_list(loclist, opts)
-- numbers beyond the end of the buffer -- numbers beyond the end of the buffer
local diagnostics = get_diagnostics(bufnr, opts, false) local diagnostics = get_diagnostics(bufnr, opts, false)
local items = M.toqflist(diagnostics) local items = M.toqflist(diagnostics)
if next(items) == nil then
vim.notify('No diagnostics available')
return
end
if loclist then if loclist then
vim.fn.setloclist(winnr, {}, ' ', { title = title, items = items }) vim.fn.setloclist(winnr, {}, ' ', { title = title, items = items })
else else
vim.fn.setqflist({}, ' ', { title = title, items = items }) vim.fn.setqflist({}, ' ', { title = title, items = items })
end end
if open then if open then
api.nvim_command(loclist and 'lopen' or 'botright copen') api.nvim_command(loclist and 'lwindow' or 'botright cwindow')
end end
end end