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.
|
-- 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.
|
-- If we can move, then also center screen at target location.
|
||||||
local conditional_goto = function(condition, move, opts)
|
local conditional_jump = function(count)
|
||||||
opts = vim.tbl_extend("keep", opts or {}, {
|
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
|
wrap = false, -- don't wrap around the begin/end of file
|
||||||
severity = { -- only navigate items with visible virtual text
|
severity = { -- only navigate items with visible virtual text
|
||||||
min = M.severity,
|
min = M.severity,
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
if condition(opts) then
|
if diagnostic then
|
||||||
move(opts)
|
vim.diagnostic.jump { diagnostic = diagnostic, float = true }
|
||||||
vim.cmd("normal zz")
|
vim.cmd("normal zz")
|
||||||
else
|
else
|
||||||
local level = vim.diagnostic.severity[M.severity] or "???"
|
local level = vim.diagnostic.severity[M.severity] or "???"
|
||||||
|
@ -24,16 +27,10 @@ local conditional_goto = function(condition, move, opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
---Move to the next diagnostic.
|
---Move to the next diagnostic.
|
||||||
---@param opts table\nil: options passed along to `vim.diagnostic.goto_next`.
|
M.goto_next = function() conditional_jump(1) end
|
||||||
M.goto_next = function(opts)
|
|
||||||
conditional_goto(vim.diagnostic.get_next_pos, vim.diagnostic.goto_next, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Move to the previous diagnostic.
|
---Move to the previous diagnostic.
|
||||||
---@param opts table|nil: options passed along to `vim.diagnostic.goto_prev`.
|
M.goto_prev = function() conditional_jump(-1) end
|
||||||
M.goto_prev = function(opts)
|
|
||||||
conditional_goto(vim.diagnostic.get_prev_pos, vim.diagnostic.goto_prev, opts)
|
|
||||||
end
|
|
||||||
|
|
||||||
---Show diagnostics in a floating window.
|
---Show diagnostics in a floating window.
|
||||||
---@param opts table|nil: options passed along to `vim.diagnostic.open_float`.
|
---@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
|
local ui = require("fschauen.util.icons").ui
|
||||||
|
|
||||||
-- navigate diagnostics
|
-- navigate diagnostics
|
||||||
map("n", "]d", diagnostic.goto_next, { desc = ui.Diagnostic.." [d]iagnostic [n]ext" })
|
map("n", "]d", diagnostic.goto_next, { desc = ui.Diagnostic.." next [d]iagnostic" })
|
||||||
map("n", "[d", diagnostic.goto_prev, { desc = ui.Diagnostic.." [d]iagnostic [p]revious" })
|
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>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>do", diagnostic.open_float, { desc = ui.Diagnostic.." [d]iagnostic [o]pen" })
|
||||||
map("n", "<leader>dh", diagnostic.hide, { desc = ui.Diagnostic.." [d]iagnostic [h]ide" })
|
map("n", "<leader>dh", diagnostic.hide, { desc = ui.Diagnostic.." [d]iagnostic [h]ide" })
|
||||||
|
|
Loading…
Add table
Reference in a new issue