mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
lsp: add vim.lsp.diagnostic.set_qflist() function (#14831)
* Add vim.lsp.diagnostic.set_qflist() function * replaces opts.open_loclist with unified opts.open
This commit is contained in:
parent
ea35584bac
commit
a8c3d50fad
@ -1470,12 +1470,36 @@ save({diagnostics}, {bufnr}, {client_id}) *vim.lsp.diagnostic.save()*
|
||||
save_extmarks({bufnr}, {client_id})
|
||||
TODO: Documentation
|
||||
|
||||
set_qflist({opts}) *vim.lsp.diagnostic.set_qflist()*
|
||||
Sets the quickfix list
|
||||
|
||||
Parameters: ~
|
||||
{opts} table|nil Configuration table. Keys:
|
||||
• {open}: (boolean, default true)
|
||||
• Open quickfix list after set
|
||||
|
||||
• {client_id}: (number)
|
||||
• If nil, will consider all clients attached to
|
||||
buffer.
|
||||
|
||||
• {severity}: (DiagnosticSeverity)
|
||||
• Exclusive severity to consider. Overrides
|
||||
{severity_limit}
|
||||
|
||||
• {severity_limit}: (DiagnosticSeverity)
|
||||
• Limit severity of diagnostics found. E.g.
|
||||
"Warning" means { "Error", "Warning" } will be
|
||||
valid.
|
||||
|
||||
• {workspace}: (boolean, default true)
|
||||
• Set the list with workspace diagnostics
|
||||
|
||||
set_loclist({opts}) *vim.lsp.diagnostic.set_loclist()*
|
||||
Sets the location list
|
||||
|
||||
Parameters: ~
|
||||
{opts} table|nil Configuration table. Keys:
|
||||
• {open_loclist}: (boolean, default true)
|
||||
• {open}: (boolean, default true)
|
||||
• Open loclist after set
|
||||
|
||||
• {client_id}: (number)
|
||||
|
@ -1249,10 +1249,10 @@ function M.reset(client_id, buffer_client_map)
|
||||
end)
|
||||
end
|
||||
|
||||
--- Sets the location list
|
||||
--- Gets diagnostics, converts them to quickfix/location list items, and applies the item_handler callback to the items.
|
||||
---@param item_handler function Callback to apply to the diagnostic items
|
||||
---@param command string|nil Command to execute after applying the item_handler
|
||||
---@param opts table|nil Configuration table. Keys:
|
||||
--- - {open_loclist}: (boolean, default true)
|
||||
--- - Open loclist after set
|
||||
--- - {client_id}: (number)
|
||||
--- - If nil, will consider all clients attached to buffer.
|
||||
--- - {severity}: (DiagnosticSeverity)
|
||||
@ -1261,9 +1261,8 @@ end
|
||||
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
|
||||
--- - {workspace}: (boolean, default false)
|
||||
--- - Set the list with workspace diagnostics
|
||||
function M.set_loclist(opts)
|
||||
local function apply_to_diagnostic_items(item_handler, command, opts)
|
||||
opts = opts or {}
|
||||
local open_loclist = if_nil(opts.open_loclist, true)
|
||||
local current_bufnr = api.nvim_get_current_buf()
|
||||
local diags = opts.workspace and M.get_all(opts.client_id) or {
|
||||
[current_bufnr] = M.get(current_bufnr, opts.client_id)
|
||||
@ -1280,13 +1279,51 @@ function M.set_loclist(opts)
|
||||
return true
|
||||
end
|
||||
local items = util.diagnostics_to_items(diags, predicate)
|
||||
local win_id = vim.api.nvim_get_current_win()
|
||||
util.set_loclist(items, win_id)
|
||||
if open_loclist then
|
||||
vim.cmd [[lopen]]
|
||||
item_handler(items)
|
||||
if command then
|
||||
vim.cmd(command)
|
||||
end
|
||||
end
|
||||
|
||||
--- Sets the quickfix list
|
||||
---@param opts table|nil Configuration table. Keys:
|
||||
--- - {open}: (boolean, default true)
|
||||
--- - Open quickfix list after set
|
||||
--- - {client_id}: (number)
|
||||
--- - If nil, will consider all clients attached to buffer.
|
||||
--- - {severity}: (DiagnosticSeverity)
|
||||
--- - Exclusive severity to consider. Overrides {severity_limit}
|
||||
--- - {severity_limit}: (DiagnosticSeverity)
|
||||
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
|
||||
--- - {workspace}: (boolean, default true)
|
||||
--- - Set the list with workspace diagnostics
|
||||
function M.set_qflist(opts)
|
||||
opts = opts or {}
|
||||
opts.workspace = if_nil(opts.workspace, true)
|
||||
local open_qflist = if_nil(opts.open, true)
|
||||
local command = open_qflist and [[copen]] or nil
|
||||
apply_to_diagnostic_items(util.set_qflist, command, opts)
|
||||
end
|
||||
|
||||
--- Sets the location list
|
||||
---@param opts table|nil Configuration table. Keys:
|
||||
--- - {open}: (boolean, default true)
|
||||
--- - Open loclist after set
|
||||
--- - {client_id}: (number)
|
||||
--- - If nil, will consider all clients attached to buffer.
|
||||
--- - {severity}: (DiagnosticSeverity)
|
||||
--- - Exclusive severity to consider. Overrides {severity_limit}
|
||||
--- - {severity_limit}: (DiagnosticSeverity)
|
||||
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
|
||||
--- - {workspace}: (boolean, default false)
|
||||
--- - Set the list with workspace diagnostics
|
||||
function M.set_loclist(opts)
|
||||
opts = opts or {}
|
||||
local open_loclist = if_nil(opts.open, true)
|
||||
local command = open_loclist and [[lopen]] or nil
|
||||
apply_to_diagnostic_items(util.set_loclist, command, opts)
|
||||
end
|
||||
|
||||
--- Disable diagnostics for the given buffer and client
|
||||
--- @param bufnr (optional, number): Buffer handle, defaults to current
|
||||
--- @param client_id (optional, number): Disable diagnostics for the given
|
||||
|
Loading…
Reference in New Issue
Block a user