nvim: select diagnostic virtual text severity with custom telescope picker
This commit is contained in:
parent
fdf94be847
commit
801f0cc7b3
1 changed files with 73 additions and 17 deletions
|
@ -54,24 +54,80 @@ end
|
||||||
---@param bufnr integer|nil: Buffer number (0 for current buffer, nil for all buffers.
|
---@param bufnr integer|nil: Buffer number (0 for current buffer, nil for all buffers.
|
||||||
M.hide = function(bufnr) vim.diagnostic.hide(nil, bufnr or 0) end
|
M.hide = function(bufnr) vim.diagnostic.hide(nil, bufnr or 0) end
|
||||||
|
|
||||||
|
local icons = require("fschauen.util.icons")
|
||||||
|
|
||||||
|
---Select minimum diagnostic severity for which to show virtual text.
|
||||||
M.select_virtual_text_severity = function()
|
M.select_virtual_text_severity = function()
|
||||||
vim.ui.select(
|
if not pcall(require, "telescope") then
|
||||||
{ "ERROR", "WARN", "INFO", "HINT" },
|
vim.notify("Telescope not available!", vim.log.levels.ERROR)
|
||||||
{ prompt = "Min. severity for virtual text:" },
|
return
|
||||||
function(choice)
|
end
|
||||||
if choice then
|
|
||||||
M.severity = vim.diagnostic.severity[choice] or M.severity
|
local display_row = require("telescope.pickers.entry_display").create {
|
||||||
|
separator = "",
|
||||||
|
items = { { width = 3 }, { remaining = true } },
|
||||||
|
}
|
||||||
|
|
||||||
|
local make_display = function(entry)
|
||||||
|
return display_row {
|
||||||
|
{ entry.value.icon, entry.value.highlight },
|
||||||
|
{ entry.value.title, entry.value.highlight },
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local opts = require("telescope.themes").get_dropdown()
|
||||||
|
require("telescope.pickers")
|
||||||
|
.new(opts, {
|
||||||
|
prompt_title = "Min. severity for virtual text:",
|
||||||
|
finder = require("telescope.finders").new_table {
|
||||||
|
results = {
|
||||||
|
{
|
||||||
|
title = "Error",
|
||||||
|
severity = vim.diagnostic.severity.ERROR,
|
||||||
|
icon = icons.diagnostics_bold.Error,
|
||||||
|
highlight = "DiagnosticError",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = "Warning",
|
||||||
|
severity = vim.diagnostic.severity.WARN,
|
||||||
|
icon = icons.diagnostics_bold.Warn,
|
||||||
|
highlight = "DiagnosticWarn",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = "Info",
|
||||||
|
severity = vim.diagnostic.severity.INFO,
|
||||||
|
icon = icons.diagnostics_bold.Info,
|
||||||
|
highlight = "DiagnosticInfo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
title = "Hint",
|
||||||
|
severity = vim.diagnostic.severity.HINT,
|
||||||
|
icon = icons.diagnostics_bold.Hint,
|
||||||
|
highlight = "DiagnosticHint",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
entry_maker = function(entry)
|
||||||
|
return { value = entry, ordinal = entry.title, display = make_display }
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
sorter = require("telescope.config").values.generic_sorter(opts),
|
||||||
|
attach_mappings = function(prompt_bufnr, _)
|
||||||
|
local actions = require("telescope.actions")
|
||||||
|
actions.select_default:replace(function()
|
||||||
|
actions.close(prompt_bufnr)
|
||||||
|
local selection = require("telescope.actions.state").get_selected_entry()
|
||||||
|
M.severity = selection.value.severity or M.severity
|
||||||
vim.diagnostic.config {
|
vim.diagnostic.config {
|
||||||
virtual_text = {
|
virtual_text = {
|
||||||
severity = { min = M.severity },
|
severity = { min = M.severity },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
end)
|
||||||
|
return true
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
:find()
|
||||||
end
|
end
|
||||||
end
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
local icons = require("fschauen.util.icons")
|
|
||||||
|
|
||||||
---Customize nvim's diagnostics display.
|
---Customize nvim's diagnostics display.
|
||||||
M.setup = function()
|
M.setup = function()
|
||||||
|
|
Loading…
Add table
Reference in a new issue