diff --git a/config/nvim/lua/fschauen/diagnostic.lua b/config/nvim/lua/fschauen/diagnostic.lua index 9a3a943..be587f5 100644 --- a/config/nvim/lua/fschauen/diagnostic.lua +++ b/config/nvim/lua/fschauen/diagnostic.lua @@ -21,63 +21,25 @@ 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() +---Use `Telescope` to set a new diagnostic severity. +M.set_severity = function() if not pcall(require, "telescope") then vim.notify("Telescope not available!", vim.log.levels.ERROR) return end - local display_row = require("telescope.pickers.entry_display").create { + local displayer = require("telescope.pickers.entry_display").create { separator = "", - items = { { width = 3 }, { remaining = true } }, + items = { { width = 3 }, { width = 3 }, { remaining = true } }, } local make_display = function(entry) - return display_row { + local severity = vim.F.npcall( + function() return vim.diagnostic.config().signs.severity.min end + ) + local marker = severity == entry.value.severity and icons.ui.Checkbox or "" + return displayer { + { marker, "Comment" }, { entry.value.icon, entry.value.highlight }, { entry.value.title, entry.value.highlight }, } @@ -89,6 +51,12 @@ M.select_virtual_text_severity = function() prompt_title = "Min. severity for virtual text:", finder = require("telescope.finders").new_table { results = { + { + title = "Off", + severity = 0, + icon = icons.ui.Off, + highlight = "Comment", + }, { title = "Error", severity = vim.diagnostic.severity.ERROR, @@ -124,7 +92,7 @@ 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.setup { severity = { min = selection.value.severity } } end) return true end, @@ -133,6 +101,40 @@ M.select_virtual_text_severity = function() end ---Customize nvim's diagnostics display. -M.setup = function() vim.diagnostic.config(diagnostics_opts()) end +M.setup = function(opts) + opts = vim.tbl_deep_extend("keep", opts or {}, { + severity = { + min = vim.diagnostic.severity.HINT, + }, + }) + + vim.diagnostic.config { + underline = false, + severity_sort = true, + signs = { + severity = opts.severity, + text = { + [vim.diagnostic.severity.ERROR] = icons.diagnostics.Error, + [vim.diagnostic.severity.WARN] = icons.diagnostics.Warn, + [vim.diagnostic.severity.INFO] = icons.diagnostics.Info, + [vim.diagnostic.severity.HINT] = icons.diagnostics.Hint, + }, + }, + virtual_text = { + severity = opts.severity, + prefix = function(_, index, total) return index == total and "▰" or "▱" end, + }, + float = { + border = "rounded", + header = { " " .. icons.ui.Diagnostic .. " Diagnostics:", "Comment" }, + prefix = function(_, index, _) return string.format("%2d. ", index), "Comment" end, + }, + jump = { + severity = opts.severity, + wrap = false, + float = true, + }, + } +end return M diff --git a/config/nvim/lua/fschauen/keymap.lua b/config/nvim/lua/fschauen/keymap.lua index 8dc07c0..9b52925 100644 --- a/config/nvim/lua/fschauen/keymap.lua +++ b/config/nvim/lua/fschauen/keymap.lua @@ -91,10 +91,10 @@ M.setup = function() local ui = require("fschauen.util.icons").ui -- navigate diagnostics - map("n", "dd", diagnostic.toggle, { desc = ui.Diagnostic.." [d]iagnostic enable/[d]isable" }) - map("n", "do", diagnostic.open_float, { desc = ui.Diagnostic.." [d]iagnostic [o]pen" }) - map("n", "dh", diagnostic.hide, { desc = ui.Diagnostic.." [d]iagnostic [h]ide" }) - map("n", "ds", diagnostic.select_virtual_text_severity, { desc = ui.Diagnostic.." [d]iagnostic [s]everity" }) + map("n", "dd", diagnostic.toggle, { desc = ui.Diagnostic.." [d]iagnostic enable/[d]isable" }) + map("n", "do", diagnostic.open_float, { desc = ui.Diagnostic.." [d]iagnostic [o]pen" }) + map("n", "dh", diagnostic.hide, { desc = ui.Diagnostic.." [d]iagnostic [h]ide" }) + map("n", "ds", diagnostic.set_severity, { desc = ui.Diagnostic.." [d]iagnostic [s]everity" }) -- toggle quickfix and loclist map("n", "q", window.toggle_quickfix, { desc = ui.Toggle.." toggle quickfix" }) diff --git a/config/nvim/lua/fschauen/util/icons.lua b/config/nvim/lua/fschauen/util/icons.lua index 0737243..0709a63 100644 --- a/config/nvim/lua/fschauen/util/icons.lua +++ b/config/nvim/lua/fschauen/util/icons.lua @@ -114,6 +114,7 @@ M.ui = { Markdown = "", Modified = "", Note = "", --  + Off = "", Paste = "", Play = "", ReadOnly = "", -- "RO",