nvim: fix deprecated vim.diagnostic
navigation
This commit is contained in:
parent
264a7f1210
commit
e9623f6865
2 changed files with 12 additions and 15 deletions
|
@ -5,16 +5,19 @@ M.severity = vim.diagnostic.severity.WARN
|
|||
|
||||
-- Go to next/prev diagnostic, but only if next item has a visible virtual text.
|
||||
-- If we can move, then also center screen at target location.
|
||||
local conditional_goto = function(condition, move, opts)
|
||||
opts = vim.tbl_extend("keep", opts or {}, {
|
||||
local conditional_jump = function(count)
|
||||
vim.validate("count", count, "number")
|
||||
|
||||
local get_diagnostic = count > 0 and vim.diagnostic.get_next or vim.diagnostic.get_prev
|
||||
local diagnostic = get_diagnostic {
|
||||
wrap = false, -- don't wrap around the begin/end of file
|
||||
severity = { -- only navigate items with visible virtual text
|
||||
min = M.severity,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
if condition(opts) then
|
||||
move(opts)
|
||||
if diagnostic then
|
||||
vim.diagnostic.jump { diagnostic = diagnostic, float = true }
|
||||
vim.cmd("normal zz")
|
||||
else
|
||||
local level = vim.diagnostic.severity[M.severity] or "???"
|
||||
|
@ -24,16 +27,10 @@ local conditional_goto = function(condition, move, opts)
|
|||
end
|
||||
|
||||
---Move to the next diagnostic.
|
||||
---@param opts table\nil: options passed along to `vim.diagnostic.goto_next`.
|
||||
M.goto_next = function(opts)
|
||||
conditional_goto(vim.diagnostic.get_next_pos, vim.diagnostic.goto_next, opts)
|
||||
end
|
||||
M.goto_next = function() conditional_jump(1) end
|
||||
|
||||
---Move to the previous diagnostic.
|
||||
---@param opts table|nil: options passed along to `vim.diagnostic.goto_prev`.
|
||||
M.goto_prev = function(opts)
|
||||
conditional_goto(vim.diagnostic.get_prev_pos, vim.diagnostic.goto_prev, opts)
|
||||
end
|
||||
M.goto_prev = function() conditional_jump(-1) end
|
||||
|
||||
---Show diagnostics in a floating window.
|
||||
---@param opts table|nil: options passed along to `vim.diagnostic.open_float`.
|
||||
|
|
|
@ -91,8 +91,8 @@ M.setup = function()
|
|||
local ui = require("fschauen.util.icons").ui
|
||||
|
||||
-- navigate diagnostics
|
||||
map("n", "]d", diagnostic.goto_next, { desc = ui.Diagnostic.." [d]iagnostic [n]ext" })
|
||||
map("n", "[d", diagnostic.goto_prev, { desc = ui.Diagnostic.." [d]iagnostic [p]revious" })
|
||||
map("n", "]d", diagnostic.goto_next, { desc = ui.Diagnostic.." next [d]iagnostic" })
|
||||
map("n", "[d", diagnostic.goto_prev, { desc = ui.Diagnostic.." previous [d]iagnostic" })
|
||||
map("n", "<leader>dd", diagnostic.toggle, { desc = ui.Diagnostic.." [d]iagnostic enable/[d]isable" })
|
||||
map("n", "<leader>do", diagnostic.open_float, { desc = ui.Diagnostic.." [d]iagnostic [o]pen" })
|
||||
map("n", "<leader>dh", diagnostic.hide, { desc = ui.Diagnostic.." [d]iagnostic [h]ide" })
|
||||
|
|
Loading…
Add table
Reference in a new issue