Compare commits
No commits in common. "bdb6d88fc5bcac6f86e909b3d02cfced3859f779" and "264a7f121028e632bdedce7474f4ae4922f888a7" have entirely different histories.
bdb6d88fc5
...
264a7f1210
2 changed files with 72 additions and 47 deletions
|
@ -1,5 +1,40 @@
|
|||
local M = {}
|
||||
|
||||
-- Show/navigate warning and errors by default.
|
||||
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 {}, {
|
||||
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)
|
||||
vim.cmd("normal zz")
|
||||
else
|
||||
local level = vim.diagnostic.severity[M.severity] or "???"
|
||||
local msg = string.format("No more diagnostics [level: %s]", level)
|
||||
vim.notify(msg, vim.log.levels.WARN)
|
||||
end
|
||||
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
|
||||
|
||||
---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
|
||||
|
||||
---Show diagnostics in a floating window.
|
||||
---@param opts table|nil: options passed along to `vim.diagnostic.open_float`.
|
||||
M.open_float = function(opts) vim.diagnostic.open_float(opts) end
|
||||
|
@ -21,49 +56,6 @@ M.hide = function(bufnr) vim.diagnostic.hide(nil, bufnr or 0) end
|
|||
|
||||
local icons = require("fschauen.util.icons")
|
||||
|
||||
local diagnostics_opts = function(severity)
|
||||
severity = severity or vim.diagnostic.severity.WARN
|
||||
return {
|
||||
underline = false,
|
||||
|
||||
virtual_text = {
|
||||
spacing = 6,
|
||||
prefix = icons.ui.Circle,
|
||||
severity = {
|
||||
min = severity,
|
||||
},
|
||||
},
|
||||
|
||||
virtual_lines = {
|
||||
severity = {
|
||||
min = severity,
|
||||
},
|
||||
},
|
||||
|
||||
jump = {
|
||||
wrap = false,
|
||||
severity = {
|
||||
min = severity,
|
||||
},
|
||||
},
|
||||
|
||||
float = {
|
||||
border = "rounded",
|
||||
},
|
||||
|
||||
severity_sort = true,
|
||||
|
||||
signs = {
|
||||
text = {
|
||||
[vim.diagnostic.severity.ERROR] = icons.diagnostics.Error,
|
||||
[vim.diagnostic.severity.HINT] = icons.diagnostics.Hint,
|
||||
[vim.diagnostic.severity.INFO] = icons.diagnostics.Info,
|
||||
[vim.diagnostic.severity.WARN] = icons.diagnostics.Warn,
|
||||
},
|
||||
},
|
||||
}
|
||||
end
|
||||
|
||||
---Select minimum diagnostic severity for which to show virtual text.
|
||||
M.select_virtual_text_severity = function()
|
||||
if not pcall(require, "telescope") then
|
||||
|
@ -124,7 +116,12 @@ M.select_virtual_text_severity = function()
|
|||
actions.select_default:replace(function()
|
||||
actions.close(prompt_bufnr)
|
||||
local selection = require("telescope.actions.state").get_selected_entry()
|
||||
vim.diagnostic.config(diagnostics_opts(selection.value.severity))
|
||||
M.severity = selection.value.severity or M.severity
|
||||
vim.diagnostic.config {
|
||||
virtual_text = {
|
||||
severity = { min = M.severity },
|
||||
},
|
||||
}
|
||||
end)
|
||||
return true
|
||||
end,
|
||||
|
@ -133,6 +130,26 @@ M.select_virtual_text_severity = function()
|
|||
end
|
||||
|
||||
---Customize nvim's diagnostics display.
|
||||
M.setup = function() vim.diagnostic.config(diagnostics_opts()) end
|
||||
M.setup = function()
|
||||
vim.diagnostic.config {
|
||||
underline = false,
|
||||
virtual_text = {
|
||||
spacing = 6,
|
||||
prefix = icons.ui.Circle,
|
||||
severity = {
|
||||
min = M.severity,
|
||||
},
|
||||
},
|
||||
float = {
|
||||
border = "rounded",
|
||||
},
|
||||
severity_sort = true,
|
||||
}
|
||||
|
||||
for type, icon in pairs(icons.diagnostics) do
|
||||
local hl = "DiagnosticSign" .. type
|
||||
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
|
@ -91,14 +91,22 @@ 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", "<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" })
|
||||
map("n", "<leader>ds", diagnostic.select_virtual_text_severity, { desc = ui.Diagnostic.." [d]iagnostic [s]everity" })
|
||||
|
||||
-- navigate items in quickfix and location lists
|
||||
map("n", "<leader>j", "<cmd>cnext<cr>zz")
|
||||
map("n", "<leader>k", "<cmd>cprevious<cr>zz")
|
||||
map("n", "<localleader>j", "<cmd>lnext<cr>zz")
|
||||
map("n", "<localleader>k", "<cmd>lprevious<cr>zz")
|
||||
|
||||
-- toggle quickfix and loclist
|
||||
map("n", "<leader>q", window.toggle_quickfix, { desc = ui.Toggle.." toggle quickfix" })
|
||||
map("n", "<localleader>q", window.toggle_loclist, { desc = ui.Toggle.." toggle loclist" })
|
||||
map("n", "<leader>ll", window.toggle_quickfix, { desc = ui.Toggle.." toggle quickfix" })
|
||||
map("n", "<localleader>ll", window.toggle_loclist, { desc = ui.Toggle.." toggle loclist" })
|
||||
|
||||
local options = require("fschauen.util.options")
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue