fix(lspconfig): make opts a function (#3311)

`LazyVim.config` gets evaluated during the parsing phase with `opts`
as a table (thus not taking into account changes made in the user's
personal configuration for the icons), so make `opts` a function to
defer the evaluation until the plugin loads.
This commit is contained in:
Iordanis Petkakis
2024-05-26 17:06:15 +03:00
committed by GitHub
parent b3373f3428
commit 7aa37064a2

View File

@ -10,103 +10,105 @@ return {
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",
}, },
---@class PluginLspOpts ---@class PluginLspOpts
opts = { opts = function()
-- options for vim.diagnostic.config() return {
---@type vim.diagnostic.Opts -- options for vim.diagnostic.config()
diagnostics = { ---@type vim.diagnostic.Opts
underline = true, diagnostics = {
update_in_insert = false, underline = true,
virtual_text = { update_in_insert = false,
spacing = 4, virtual_text = {
source = "if_many", spacing = 4,
prefix = "", source = "if_many",
-- this will set set the prefix to a function that returns the diagnostics icon based on the severity prefix = "",
-- this only works on a recent 0.10.0 build. Will be set to "●" when not supported -- this will set set the prefix to a function that returns the diagnostics icon based on the severity
-- prefix = "icons", -- this only works on a recent 0.10.0 build. Will be set to "●" when not supported
}, -- prefix = "icons",
severity_sort = true, },
signs = { severity_sort = true,
text = { signs = {
[vim.diagnostic.severity.ERROR] = LazyVim.config.icons.diagnostics.Error, text = {
[vim.diagnostic.severity.WARN] = LazyVim.config.icons.diagnostics.Warn, [vim.diagnostic.severity.ERROR] = LazyVim.config.icons.diagnostics.Error,
[vim.diagnostic.severity.HINT] = LazyVim.config.icons.diagnostics.Hint, [vim.diagnostic.severity.WARN] = LazyVim.config.icons.diagnostics.Warn,
[vim.diagnostic.severity.INFO] = LazyVim.config.icons.diagnostics.Info, [vim.diagnostic.severity.HINT] = LazyVim.config.icons.diagnostics.Hint,
[vim.diagnostic.severity.INFO] = LazyVim.config.icons.diagnostics.Info,
},
}, },
}, },
}, -- Enable this to enable the builtin LSP inlay hints on Neovim >= 0.10.0
-- Enable this to enable the builtin LSP inlay hints on Neovim >= 0.10.0 -- Be aware that you also will need to properly configure your LSP server to
-- Be aware that you also will need to properly configure your LSP server to -- provide the inlay hints.
-- provide the inlay hints. inlay_hints = {
inlay_hints = { enabled = true,
enabled = true, },
}, -- Enable this to enable the builtin LSP code lenses on Neovim >= 0.10.0
-- Enable this to enable the builtin LSP code lenses on Neovim >= 0.10.0 -- Be aware that you also will need to properly configure your LSP server to
-- Be aware that you also will need to properly configure your LSP server to -- provide the code lenses.
-- provide the code lenses. codelens = {
codelens = { enabled = false,
enabled = false, },
}, -- Enable lsp cursor word highlighting
-- Enable lsp cursor word highlighting document_highlight = {
document_highlight = { enabled = true,
enabled = true, },
}, -- add any global capabilities here
-- add any global capabilities here capabilities = {},
capabilities = {}, -- options for vim.lsp.buf.format
-- options for vim.lsp.buf.format -- `bufnr` and `filter` is handled by the LazyVim formatter,
-- `bufnr` and `filter` is handled by the LazyVim formatter, -- but can be also overridden when specified
-- but can be also overridden when specified format = {
format = { formatting_options = nil,
formatting_options = nil, timeout_ms = nil,
timeout_ms = nil, },
}, -- LSP Server Settings
-- LSP Server Settings ---@type lspconfig.options
---@type lspconfig.options servers = {
servers = { lua_ls = {
lua_ls = { -- mason = false, -- set to false if you don't want this server to be installed with mason
-- mason = false, -- set to false if you don't want this server to be installed with mason -- Use this to add any additional keymaps
-- Use this to add any additional keymaps -- for specific lsp servers
-- for specific lsp servers ---@type LazyKeysSpec[]
---@type LazyKeysSpec[] -- keys = {},
-- keys = {}, settings = {
settings = { Lua = {
Lua = { workspace = {
workspace = { checkThirdParty = false,
checkThirdParty = false, },
}, codeLens = {
codeLens = { enable = true,
enable = true, },
}, completion = {
completion = { callSnippet = "Replace",
callSnippet = "Replace", },
}, doc = {
doc = { privateName = { "^_" },
privateName = { "^_" }, },
}, hint = {
hint = { enable = true,
enable = true, setType = false,
setType = false, paramType = true,
paramType = true, paramName = "Disable",
paramName = "Disable", semicolon = "Disable",
semicolon = "Disable", arrayIndex = "Disable",
arrayIndex = "Disable", },
}, },
}, },
}, },
}, },
}, -- you can do any additional lsp server setup here
-- you can do any additional lsp server setup here -- return true if you don't want this server to be setup with lspconfig
-- return true if you don't want this server to be setup with lspconfig ---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?>
---@type table<string, fun(server:string, opts:_.lspconfig.options):boolean?> setup = {
setup = { -- example to setup with typescript.nvim
-- example to setup with typescript.nvim -- tsserver = function(_, opts)
-- tsserver = function(_, opts) -- require("typescript").setup({ server = opts })
-- require("typescript").setup({ server = opts }) -- return true
-- return true -- end,
-- end, -- Specify * to use this function as a fallback for any server
-- Specify * to use this function as a fallback for any server -- ["*"] = function(server, opts) end,
-- ["*"] = function(server, opts) end, },
}, }
}, end,
---@param opts PluginLspOpts ---@param opts PluginLspOpts
config = function(_, opts) config = function(_, opts)
if LazyVim.has("neoconf.nvim") then if LazyVim.has("neoconf.nvim") then