From e380732f90ee82fe52d777157a7225f90f70289f Mon Sep 17 00:00:00 2001 From: imxyy_soope_ Date: Sat, 10 May 2025 12:38:29 +0800 Subject: [PATCH] fix(nvim): diagnostic sign --- .../neovim/nvim/lua/plugins/lsp/lspconfig.lua | 27 ----------- .../neovim/nvim/lua/plugins/lsp/others.lua | 45 ++++++++++++++----- 2 files changed, 33 insertions(+), 39 deletions(-) diff --git a/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua b/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua index fa87b09..efd79fa 100644 --- a/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua +++ b/modules/coding/editor/neovim/nvim/lua/plugins/lsp/lspconfig.lua @@ -67,30 +67,3 @@ for _, server in ipairs(servers) do end lspconfig[server].setup(config) end - -local diag_config1 = { - virtual_text = { - severity = { - max = vim.diagnostic.severity.WARN, - }, - }, - virtual_lines = { - severity = { - min = vim.diagnostic.severity.ERROR, - }, - }, -} -local diag_config2 = { - virtual_text = true, - virtual_lines = false, -} -vim.diagnostic.config(diag_config1) -local diag_config_basic = false -vim.keymap.set("n", "ll", function() - diag_config_basic = not diag_config_basic - if diag_config_basic then - vim.diagnostic.config(diag_config2) - else - vim.diagnostic.config(diag_config1) - end -end, { desc = "Toggle diagnostic virtual_lines" }) diff --git a/modules/coding/editor/neovim/nvim/lua/plugins/lsp/others.lua b/modules/coding/editor/neovim/nvim/lua/plugins/lsp/others.lua index 31d18f5..075d856 100644 --- a/modules/coding/editor/neovim/nvim/lua/plugins/lsp/others.lua +++ b/modules/coding/editor/neovim/nvim/lua/plugins/lsp/others.lua @@ -4,26 +4,47 @@ local opt = require("core.globals").keymap_opt vim.keymap.set("n", "K", vim.lsp.buf.hover, opt) vim.keymap.set("n", "lR", vim.lsp.buf.rename, opt) +local icons = { Error = " ", Warn = " ", Hint = " ", Info = " " } +local signs = {} +for type, icon in pairs(icons) do + local hl = "DiagnosticSign" .. type + signs[hl] = { text = icon, texthl = hl, numhl = hl } +end vim.diagnostic.config({ virtual_text = { spacing = 4, prefix = "●" }, - signs = true, + signs = signs, underline = true, update_in_insert = true, severity_sort = true, }) -local signs = { Error = " ", Warn = " ", Hint = " ", Info = " " } -for type, icon in pairs(signs) do - local hl = "DiagnosticSign" .. type - vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) -end - vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(vim.lsp.handlers.hover, { border = "single", }) ---[[ vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(vim.lsp.handlers.signature_help, { - border = "single", - focusable = false, - relative = "cursor", -}) ]] +local diag_config1 = { + virtual_text = { + severity = { + max = vim.diagnostic.severity.WARN, + }, + }, + virtual_lines = { + severity = { + min = vim.diagnostic.severity.ERROR, + }, + }, +} +local diag_config2 = { + virtual_text = true, + virtual_lines = false, +} +vim.diagnostic.config(diag_config1) +local diag_config_basic = false +vim.keymap.set("n", "ll", function() + diag_config_basic = not diag_config_basic + if diag_config_basic then + vim.diagnostic.config(diag_config2) + else + vim.diagnostic.config(diag_config1) + end +end, { desc = "Toggle diagnostic virtual_lines" })