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:
parent
ccf65fecb1
commit
b3cbfbd26f
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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' , } ,
|
||||
}
|
||||
|
||||
-- #############################
|
||||
|
|
Loading…
Reference in New Issue