kickstart.nvim
kickstart.nvim copied to clipboard
Cannot set lsp servers root_dir with root_pattern
Describe the bug I am trying to override the root_dir of one of my LSP servers by using root_pattern but get the following error:
Error executing vim.schedule lua callback: /usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:289: Cannot serialise function: type not supported
stack traceback:
[C]: in function 'encode'
/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:289: in function 'notify'
/usr/share/nvim/runtime/lua/vim/lsp.lua:1326: in function ''
vim/_editor.lua: in function <vim/_editor.lua:0>
To Reproduce
local servers = {
tsserver = {
root_dir = require("lspconfig").util.root_pattern("package.json")
},
sumneko_lua = {
Lua = {
workspace = { checkThirdParty = false },
telemetry = { enable = false },
},
},
}
Desktop:
- OS: Ubuntu 22.04
- Terminal: Alacritty
Neovim Version
NVIM v0.8.1
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by runner@fv-az178-366
Features: +acl +iconv +tui
Nevermind I figured it out. root_dir needs to be given to the lspconfig setup method as a parameter and not in the settings table.
To keep my servers table as it is, I modified the setup_handlers part like so:
mason_lspconfig.setup_handlers {
function(server_name)
local root_dir = servers[server_name]['root_dir'] -- get root_dir from servers table
servers[server_name]['root_dir'] = nil -- remove root_dir from table
require('lspconfig')[server_name].setup {
capabilities = capabilities,
on_attach = on_attach,
settings = servers[server_name], -- settings will not contain root_dir
root_dir = root_dir, -- use root_dir on its own
}
end,
}