feat: lsp diagnostics line formatting

This commit is contained in:
Matthew Leong 2022-08-02 11:15:54 -07:00
parent 6f73a28b79
commit e009f823e4
2 changed files with 21 additions and 4 deletions

View file

@ -15,6 +15,20 @@ for type, icon in pairs(signs) do
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' }) vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' })
end end
local function format(diagnostic)
local icon = icons.error
if diagnostic.severity == vim.diagnostic.severity.WARN then
icon = icons.warn
end
if diagnostic.severity == vim.diagnostic.severity.HINT then
icon = icons.hint
end
local message = string.format(' %s [%s][%s] %s', icon, diagnostic.code, diagnostic.source, diagnostic.message)
return message
end
-- set up vim.diagnostics -- set up vim.diagnostics
-- vim.diagnostic.config opts -- vim.diagnostic.config opts
vim.diagnostic.config(u.merge({ vim.diagnostic.config(u.merge({
@ -26,13 +40,17 @@ vim.diagnostic.config(u.merge({
border = config.border, border = config.border,
focusable = false, focusable = false,
header = { icons.debug .. ' Diagnostics:', 'Normal' }, header = { icons.debug .. ' Diagnostics:', 'Normal' },
source = 'always', scope = 'line',
source = false,
format = format,
}, },
virtual_text = { virtual_text = {
spacing = 4, prefix = '',
source = 'always', spacing = 2,
source = false,
severity = { severity = {
min = vim.diagnostic.severity.HINT, min = vim.diagnostic.severity.HINT,
}, },
format = format,
}, },
}, config.diagnostic or {})) }, config.diagnostic or {}))

View file

@ -5,7 +5,6 @@ local config = require('cosmic.core.user')
local config_opts = u.merge(config.lsp.servers.null_ls or {}, { local config_opts = u.merge(config.lsp.servers.null_ls or {}, {
default_cosmic_sources = true, default_cosmic_sources = true,
diagnostics_format = '#{m} (#{s}) [#{c}]',
}) })
-- how to disable sources? -- how to disable sources?