nvim/diagnostic: configure neovim's diagnostics API

Basic run down is:

- Disable virtual_text
- Add severity icons
- Add key maps for goto prev/next diagnostic
- Add diagnostic popup on hover
This commit is contained in:
Paul Stemmet 2022-09-10 07:47:50 +00:00
parent ccf65fecb1
commit b3cbfbd26f
Signed by: Paul Stemmet
GPG Key ID: EDEA539F594E7E75
3 changed files with 66 additions and 0 deletions

View File

@ -0,0 +1,57 @@
local au, keys = require 'psoxizsh.autocmd', require 'psoxizsh.key.map'
local D = vim.diagnostic
local M = setmetatable({}, { __call = function(self, args) self.setup(args) end })
local sign = function(o)
vim.fn.sign_define(o.name, {
texthl = o.name,
text = o.text,
numhl = ''
})
end
function M.config()
-- Setup signs
sign({ name = 'DiagnosticSignError', text = '' })
sign({ name = 'DiagnosticSignWarn', text = '' })
sign({ name = 'DiagnosticSignHint', text = '' })
sign({ name = 'DiagnosticSignInfo', text = '' })
-- Define base diagnostic configuration
D.config({
virtual_text = false,
signs = true,
update_in_insert = true,
underline = true,
severity_sort = true,
float = {
border = 'rounded',
source = 'if_many',
header = '',
prefix = '',
},
})
end
-- Key maps
function M.keymaps()
keys.Global.N.DiagnosticPrev { action = D.goto_prev }
keys.Global.N.DiagnosticNext { action = D.goto_next }
end
function M.autocmds()
au.PsoxDiagnosticHover {
{ 'CursorHold', '*', function() D.open_float({ focusable = false, scope = 'cursor' }) end }
}
end
function M.setup(_)
M.config()
M.keymaps()
M.autocmds()
end
return M

View File

@ -1,5 +1,6 @@
local o, g, fn, cmd = vim.opt, vim.g, vim.fn, vim.cmd
local au, util = require 'psoxizsh.autocmd', require 'psoxizsh.util'
local diagnostic = require 'psoxizsh.diagnostic'
local keys = require 'psoxizsh.key.map'
local function psoxizsh_early_config()
@ -73,6 +74,9 @@ local function psoxizsh_early_config()
-- Set global statusline (0.7+ only)
if fn.has('nvim-0.7') == 1 then o.laststatus = 3 end
-- Setup vim.diagnostic APIs
diagnostic.setup {}
-- Local pre plugin configuration
util.try_mreload('pre')
end

View File

@ -40,6 +40,11 @@ M.Global.N {
--
BufferNext = B { 'Next buffer or tab' , key = '<Tab>' , action = '<cmd>BufferLineCycleNext<CR>' , } ,
BufferPrev = B { 'Previous buffer or tab' , key = '<S-Tab>' , action = '<cmd>BufferLineCyclePrev<CR>' , } ,
--
-- Diagnostics
--
DiagnosticNext = B { 'Next buffer diagnostic' , key = ']g' , } ,
DiagnosticPrev = B { 'Previous buffer diagnostic' , key = '[g' , } ,
}
-- #############################