diff --git a/home/editors/neovim/default.nix b/home/editors/neovim/default.nix index d0e400a..5b2aa7a 100644 --- a/home/editors/neovim/default.nix +++ b/home/editors/neovim/default.nix @@ -71,6 +71,7 @@ in { ./gitsigns.lua ./test.lua ./completion.lua + ./diagnostic.lua ./lsp/extensions.lua ./lsp/lsp.lua ./lsp/mappings.lua diff --git a/home/editors/neovim/diagnostic.lua b/home/editors/neovim/diagnostic.lua new file mode 100644 index 0000000..6001eac --- /dev/null +++ b/home/editors/neovim/diagnostic.lua @@ -0,0 +1,37 @@ +-- don't show underline & virtual_text for HINT severity +local min_info_severity = { + min = vim.diagnostic.severity.INFO +} + +local format = function(diagnostic) + if diagnostic.code ~= nil then + return string.format("%s [%s]", diagnostic.message, diagnostic.code) + end + return diagnostic.message +end + +vim.diagnostic.config { + severity_sort = true, + underline = { + severity = min_info_severity, + }, + virtual_text = { + severity = min_info_severity, + format = format, + }, + signs = true, + float = true, +} + +vim.keymap.set("n", "q", vim.diagnostic.setloclist, { silent = true }) +vim.keymap.set("n", "i", function() + vim.diagnostic.open_float({ format = format }) +end, { silent = true }) +vim.keymap.set("n", "[d", function() + vim.diagnostic.goto_prev({ format = format }) +end, { silent = true }) +vim.keymap.set("n", "]d", function() + vim.diagnostic.goto_next({ format = format }) +end, { silent = true }) +vim.keymap.set("n", "[d", vim.diagnostic.goto_prev, { silent = true }) +vim.keymap.set("n", "]d", vim.diagnostic.goto_next, { silent = true })