aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua')
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua55
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua4
-rw-r--r--runtime/lua/vim/treesitter/query.lua5
3 files changed, 53 insertions, 11 deletions
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
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index 84b6a5f135..cf3cdf4505 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -248,7 +248,7 @@ local function on_line_impl(self, buf, line)
end
while line >= state.next_row do
- local capture, node = state.iter()
+ local capture, node, metadata = state.iter()
if capture == nil then break end
@@ -260,7 +260,7 @@ local function on_line_impl(self, buf, line)
{ end_line = end_row, end_col = end_col,
hl_group = hl,
ephemeral = true,
- priority = 100 -- Low but leaves room below
+ priority = tonumber(metadata.priority) or 100 -- Low but leaves room below
})
end
if start_row > line then
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index b81eb18945..0ba44ced1a 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -351,6 +351,11 @@ function M.add_directive(name, handler, force)
directive_handlers[name] = handler
end
+--- Returns the list of currently supported directives
+function M.list_directives()
+ return vim.tbl_keys(directive_handlers)
+end
+
--- Returns the list of currently supported predicates
function M.list_predicates()
return vim.tbl_keys(predicate_handlers)