Compare commits
3 commits
264a7f1210
...
bdb6d88fc5
Author | SHA1 | Date | |
---|---|---|---|
bdb6d88fc5 | |||
c850f7edb9 | |||
e9623f6865 |
2 changed files with 47 additions and 72 deletions
|
@ -1,40 +1,5 @@
|
||||||
local M = {}
|
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.
|
---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`.
|
||||||
M.open_float = function(opts) vim.diagnostic.open_float(opts) end
|
M.open_float = function(opts) vim.diagnostic.open_float(opts) end
|
||||||
|
@ -56,6 +21,49 @@ M.hide = function(bufnr) vim.diagnostic.hide(nil, bufnr or 0) end
|
||||||
|
|
||||||
local icons = require("fschauen.util.icons")
|
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.
|
---Select minimum diagnostic severity for which to show virtual text.
|
||||||
M.select_virtual_text_severity = function()
|
M.select_virtual_text_severity = function()
|
||||||
if not pcall(require, "telescope") then
|
if not pcall(require, "telescope") then
|
||||||
|
@ -116,12 +124,7 @@ M.select_virtual_text_severity = function()
|
||||||
actions.select_default:replace(function()
|
actions.select_default:replace(function()
|
||||||
actions.close(prompt_bufnr)
|
actions.close(prompt_bufnr)
|
||||||
local selection = require("telescope.actions.state").get_selected_entry()
|
local selection = require("telescope.actions.state").get_selected_entry()
|
||||||
M.severity = selection.value.severity or M.severity
|
vim.diagnostic.config(diagnostics_opts(selection.value.severity))
|
||||||
vim.diagnostic.config {
|
|
||||||
virtual_text = {
|
|
||||||
severity = { min = M.severity },
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end)
|
end)
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
@ -130,26 +133,6 @@ M.select_virtual_text_severity = function()
|
||||||
end
|
end
|
||||||
|
|
||||||
---Customize nvim's diagnostics display.
|
---Customize nvim's diagnostics display.
|
||||||
M.setup = function()
|
M.setup = function() vim.diagnostic.config(diagnostics_opts()) end
|
||||||
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
|
return M
|
||||||
|
|
|
@ -91,22 +91,14 @@ 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_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>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" })
|
||||||
map("n", "<leader>ds", diagnostic.select_virtual_text_severity, { desc = ui.Diagnostic.." [d]iagnostic [s]everity" })
|
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
|
-- toggle quickfix and loclist
|
||||||
map("n", "<leader>ll", window.toggle_quickfix, { desc = ui.Toggle.." toggle quickfix" })
|
map("n", "<leader>q", window.toggle_quickfix, { desc = ui.Toggle.." toggle quickfix" })
|
||||||
map("n", "<localleader>ll", window.toggle_loclist, { desc = ui.Toggle.." toggle loclist" })
|
map("n", "<localleader>q", window.toggle_loclist, { desc = ui.Toggle.." toggle loclist" })
|
||||||
|
|
||||||
local options = require("fschauen.util.options")
|
local options = require("fschauen.util.options")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue