fix(lsp): better support for diagnostics icons on Neovim nightly/stable

This commit is contained in:
Folke Lemaitre 2024-03-29 09:44:38 +01:00
parent 64f86147f9
commit aaa10e717d
No known key found for this signature in database
GPG key ID: 41F8B1FBACAE2040

View file

@ -12,6 +12,7 @@ return {
---@class PluginLspOpts
opts = {
-- options for vim.diagnostic.config()
---@type vim.diagnostic.Opts
diagnostics = {
underline = true,
update_in_insert = false,
@ -101,12 +102,6 @@ return {
-- setup autoformat
LazyVim.format.register(LazyVim.lsp.formatter())
-- deprecated options
if opts.autoformat ~= nil then
vim.g.autoformat = opts.autoformat
LazyVim.deprecate("nvim-lspconfig.opts.autoformat", "vim.g.autoformat")
end
-- setup keymaps
LazyVim.lsp.on_attach(function(client, buffer)
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
@ -115,10 +110,9 @@ return {
local register_capability = vim.lsp.handlers["client/registerCapability"]
vim.lsp.handlers["client/registerCapability"] = function(err, res, ctx)
---@diagnostic disable-next-line: no-unknown
local ret = register_capability(err, res, ctx)
local client_id = ctx.client_id
---@type lsp.Client
local client = vim.lsp.get_client_by_id(client_id)
local client = vim.lsp.get_client_by_id(ctx.client_id)
local buffer = vim.api.nvim_get_current_buf()
require("lazyvim.plugins.lsp.keymaps").on_attach(client, buffer)
return ret
@ -126,8 +120,7 @@ return {
-- diagnostics signs
if vim.fn.has("nvim-0.10.0") == 0 then
local text = vim.tbl_get(opts, "diagnostics", "signs", "text") or {}
for severity, icon in pairs(text) do
for severity, icon in pairs(opts.diagnostics.signs.text) do
local name = vim.diagnostic.severity[severity]:lower():gsub("^%l", string.upper)
name = "DiagnosticSign" .. name
vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" })