I have setup neovim some month ago to see how coding in it is like. Today I updated the LSPs in Mason and after that I got the error below.
The error message occurs at every start now and I don't know how to fix it. I'm not really familiar with lua, but I managed to paste a setup together which worked fine before today. I'll attach the lsp config under the error message.
I tried to delete the neovim cache, because it did help before with faulty updates, but not this time. I also tried to uninstall all LSPs with MasonUninstall and the error was gone. But when I installed one LSP again it came back.
The packages in neovim are managed with Lazy and are up to date. Neovim is in version: 0.10
Thank you.
Failed to run `config` for lsp-zero.nvim
...g.nvim/lua/mason-lspconfig/features/automatic_enable.lua:47: attempt to call field 'enable' (a nil value)
# stacktrace:
- /mason-lspconfig.nvim/lua/mason-lspconfig/features/automatic_enable.lua:47 _in_ **fn**
- /mason.nvim/lua/mason-core/functional/list.lua:116 _in_ **each**
- /mason-lspconfig.nvim/lua/mason-lspconfig/features/automatic_enable.lua:56 _in_ **init**
- /mason-lspconfig.nvim/lua/mason-lspconfig/init.lua:41 _in_ **setup**
- lsp.lua:36 _in_ **config**
- ~/.config/nvim/lua/config/lazy.lua:19
- ~/.config/nvim/lua/config/init.lua:3
- ~/.config/nvim/init.lua:1
return {
'VonHeikemen/lsp-zero.nvim',
dependencies = {
{'williamboman/mason.nvim'},
{'williamboman/mason-lspconfig.nvim'},
{'neovim/nvim-lspconfig'},
{'hrsh7th/cmp-nvim-lsp'},
{'hrsh7th/cmp-buffer'},
{'hrsh7th/nvim-cmp'},
},
config = function()
local lsp_zero = require('lsp-zero')
local lsp_attach = function(client, bufnr)
local opts = {buffer = bufnr}
vim.keymap.set('n', 'K', '<cmd>lua vim.lsp.buf.hover()<cr>', opts)
vim.keymap.set('n', 'gd', '<cmd>lua vim.lsp.buf.definition()<cr>', opts)
vim.keymap.set('n', 'gD', '<cmd>lua vim.lsp.buf.declaration()<cr>', opts)
vim.keymap.set('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<cr>', opts)
vim.keymap.set('n', 'go', '<cmd>lua vim.lsp.buf.type_definition()<cr>', opts)
vim.keymap.set('n', 'gr', '<cmd>lua vim.lsp.buf.references()<cr>', opts)
vim.keymap.set('n', 'gs', '<cmd>lua vim.lsp.buf.signature_help()<cr>', opts)
vim.keymap.set('n', '<F2>', '<cmd>lua vim.lsp.buf.rename()<cr>', opts)
vim.keymap.set({'n', 'x'}, '<F3>', '<cmd>lua vim.lsp.buf.format({async = true})<cr>', opts)
vim.keymap.set('n', '<F4>', '<cmd>lua vim.lsp.buf.code_action()<cr>', opts)
end
lsp_zero.extend_lspconfig({
sign_text = true,
lsp_attach = lsp_attach,
capabilities = require('cmp_nvim_lsp').default_capabilities()
})
require('mason').setup({})
require('mason-lspconfig').setup({
handlers = {
function(server_name)
require('lspconfig')[server_name].setup({})
end,
}
})
local cmp = require('cmp')
local cmp_format = lsp_zero.cmp_format({details = true})
cmp.setup({
window = {
completion = cmp.config.window.bordered(),
documentation = cmp.config.window.bordered(),
},
sources = {
{name = 'nvim_lsp'},
{name = 'buffer'},
},
snippet = {
expand = function(args)
-- You need Neovim v0.10 to use vim.snippet
vim.snippet.expand(args.body)
end,
},
mapping = cmp.mapping.preset.insert({
['<CR>'] = cmp.mapping.confirm({select = false}),
}),
formatting = cmp_format,
})
end
}
It seems that installing neovim 0.11.1 solved the problem.