diff options
author | Marc Jakobi <mrcjkb89@outlook.com> | 2021-07-22 17:48:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-22 08:48:28 -0700 |
commit | a8c3d50fad94971ebfe9eeedf933bdd829e66787 (patch) | |
tree | 33e841aa1ac05cecbd18f30b8b4d9948521a420b | |
parent | ea35584bac6f33d4cb4fd59f5dcd0113e568c5a1 (diff) | |
download | rneovim-a8c3d50fad94971ebfe9eeedf933bdd829e66787.tar.gz rneovim-a8c3d50fad94971ebfe9eeedf933bdd829e66787.tar.bz2 rneovim-a8c3d50fad94971ebfe9eeedf933bdd829e66787.zip |
lsp: add vim.lsp.diagnostic.set_qflist() function (#14831)
* Add vim.lsp.diagnostic.set_qflist() function
* replaces opts.open_loclist with unified opts.open
-rw-r--r-- | runtime/doc/lsp.txt | 26 | ||||
-rw-r--r-- | runtime/lua/vim/lsp/diagnostic.lua | 55 |
2 files changed, 71 insertions, 10 deletions
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt index 62f529b463..a15c74d148 100644 --- a/runtime/doc/lsp.txt +++ b/runtime/doc/lsp.txt @@ -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) diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua index 9a97e5db2f..246665602d 100644 --- a/runtime/lua/vim/lsp/diagnostic.lua +++ b/runtime/lua/vim/lsp/diagnostic.lua @@ -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 |