From e009f823e414fd20b80109ae7342b652444e7c60 Mon Sep 17 00:00:00 2001 From: Matthew Leong Date: Tue, 2 Aug 2022 11:15:54 -0700 Subject: [PATCH] feat: lsp diagnostics line formatting --- lua/cosmic/lsp/diagnostics.lua | 24 +++++++++++++++++++++--- lua/cosmic/lsp/providers/null_ls.lua | 1 - 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lua/cosmic/lsp/diagnostics.lua b/lua/cosmic/lsp/diagnostics.lua index 57183c8..9ae64d1 100644 --- a/lua/cosmic/lsp/diagnostics.lua +++ b/lua/cosmic/lsp/diagnostics.lua @@ -15,6 +15,20 @@ for type, icon in pairs(signs) do vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = '' }) 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 -- vim.diagnostic.config opts vim.diagnostic.config(u.merge({ @@ -26,13 +40,17 @@ vim.diagnostic.config(u.merge({ border = config.border, focusable = false, header = { icons.debug .. ' Diagnostics:', 'Normal' }, - source = 'always', + scope = 'line', + source = false, + format = format, }, virtual_text = { - spacing = 4, - source = 'always', + prefix = '•', + spacing = 2, + source = false, severity = { min = vim.diagnostic.severity.HINT, }, + format = format, }, }, config.diagnostic or {})) diff --git a/lua/cosmic/lsp/providers/null_ls.lua b/lua/cosmic/lsp/providers/null_ls.lua index 5c330be..667a4eb 100644 --- a/lua/cosmic/lsp/providers/null_ls.lua +++ b/lua/cosmic/lsp/providers/null_ls.lua @@ -5,7 +5,6 @@ local config = require('cosmic.core.user') local config_opts = u.merge(config.lsp.servers.null_ls or {}, { default_cosmic_sources = true, - diagnostics_format = '#{m} (#{s}) [#{c}]', }) -- how to disable sources?