repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by bugabinga
neovim/lua/bugabinga/diagnostic.lua
Rawlocal map = require 'std.map'
local auto = require 'std.auto'
local icon = require 'std.icon'
local diagnostic_icons = {
error = icon.error,
warn = icon.warn,
info = icon.info,
hint = icon.hint,
}
local display_name = {
'Error',
'Warning',
'Information',
'Hint',
}
local diagnostic = vim.diagnostic
diagnostic.enable(false)
auto 'disable_diagnostic_initially' {
description = 'Disable Diagnostics initially, when attaching an LSP client to a buffer',
events = 'LspAttach',
command = function() diagnostic.enable(false, { bufnr = 0 }) end,
}
local diagnostic_format = function(context)
return string.format('%s: %s', display_name[context.severity], context.message)
end
local prefix_format = function(context, index, total)
local severity_name = diagnostic.severity[context.severity]
return string.format('%s/%s %s %s ', index, total, context.source, diagnostic_icons[severity_name]),
'DiagnosticVirtualText' .. display_name[context.severity]
end
diagnostic.config {
underline = true,
virtual_text = {
severity = { min = diagnostic.severity.WARN },
source = false,
spacing = 2,
prefix = '⦿ ',
format = diagnostic_format,
},
float = {
focusable = false,
style = 'minimal',
source = 'if_many',
header = 'Diagnostic',
prefix = prefix_format,
},
update_in_insert = false,
signs = {
text = {
[vim.diagnostic.severity.ERROR] = diagnostic_icons.error,
[vim.diagnostic.severity.WARN] = diagnostic_icons.warn,
[vim.diagnostic.severity.INFO] = diagnostic_icons.info,
[vim.diagnostic.severity.HINT] = diagnostic_icons.hint,
}
},
severity_sort = true,
}
map.normal {
description = 'Toggle diagnostics',
category = 'diagnostic',
keys = '<leader>td',
command = function()
if not diagnostic.is_enabled() then
diagnostic.enable()
vim.notify 'Enabling Diagnostics'
else
diagnostic.enable(false)
vim.notify 'Disabling Diagnostics'
end
end,
}
map.normal {
description = 'Show diagnostics under cursor',
category = 'diagnostic',
keys = 'H',
command = diagnostic.open_float,
}
map.normal {
description = 'Open diagnostics in quickfix list.',
category = 'diagnostic',
keys = 'HH',
command = diagnostic.setqflist,
}