From dab7a8a38af62460f66fa503dc8a6bf6269b8475 Mon Sep 17 00:00:00 2001 From: Ismo Vuorinen Date: Tue, 14 Jan 2025 06:50:15 +0200 Subject: [PATCH] chore(nvim): lsp sign definitions, icons, settings --- config/nvim/lua/plugins/lsp.lua | 53 +++++++++++++++++++-------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/config/nvim/lua/plugins/lsp.lua b/config/nvim/lua/plugins/lsp.lua index 1c35ce9..01fa060 100644 --- a/config/nvim/lua/plugins/lsp.lua +++ b/config/nvim/lua/plugins/lsp.lua @@ -302,30 +302,39 @@ return { } -- Diagnostic configuration - vim.diagnostic.config { - virtual_text = false, - float = { - source = true, - }, + local signs = { + { name = 'DiagnosticSignError', text = '' }, -- Error icon + { name = 'DiagnosticSignWarn', text = '' }, -- Warning icon + { name = 'DiagnosticSignHint', text = '' }, -- Hint icon + { name = 'DiagnosticSignInfo', text = '' }, -- Information icon } - -- Sign configuration - vim.fn.sign_define( - 'DiagnosticSignError', - { text = '', texthl = 'DiagnosticSignError' } - ) - vim.fn.sign_define( - 'DiagnosticSignWarn', - { text = '', texthl = 'DiagnosticSignWarn' } - ) - vim.fn.sign_define( - 'DiagnosticSignInfo', - { text = '', texthl = 'DiagnosticSignInfo' } - ) - vim.fn.sign_define( - 'DiagnosticSignHint', - { text = '', texthl = 'DiagnosticSignHint' } - ) + local function ensure_sign_defined(name, sign_opts) + if vim.tbl_isempty(vim.fn.sign_getdefined(name)) then + vim.fn.sign_define(name, sign_opts) + end + end + + for _, sign in ipairs(signs) do + ensure_sign_defined(sign.name, { + text = sign.text, + texthl = sign.texthl or sign.name, + numhl = sign.numhl or sign.name, + }) + end + + ---@type vim.diagnostic.Opts + local diagnostics_config = { + signs = { + active = signs, -- show signs + }, + update_in_insert = false, + underline = true, + severity_sort = true, + virtual_text = true, + } + + vim.diagnostic.config(diagnostics_config) -- end of junnplus/lsp-setup config end,