Mason's ruby-lsp is a gem bound to whichever Ruby installed it. In a project that pins a different Ruby, loading the project bundle fails with Bundler::RubyVersionMismatch and the server exits, which is what kept producing the client-quit warning. ruby-lsp's editor docs advise against Mason for this reason and recommend the version manager's shim. Turn Mason off for ruby_lsp and launch ~/.rbenv/shims/ruby-lsp from the project root, since rbenv resolves .ruby-version from the working directory and Neovim otherwise starts servers in its own cwd. Machines without rbenv fall back to ruby-lsp on PATH.
23 lines
769 B
Lua
23 lines
769 B
Lua
return {
|
|
{
|
|
"neovim/nvim-lspconfig",
|
|
opts = {
|
|
servers = {
|
|
ruby_lsp = {
|
|
-- ruby-lsp must run on the project's Ruby to load its bundle, so use
|
|
-- the rbenv shim rather than Mason's copy, which is tied to whichever
|
|
-- Ruby installed it.
|
|
mason = false,
|
|
cmd = function(dispatchers, config)
|
|
local shim = vim.fn.expand("~/.rbenv/shims/ruby-lsp")
|
|
local exe = vim.fn.executable(shim) == 1 and shim or "ruby-lsp"
|
|
-- rbenv reads .ruby-version from the working directory, and nvim
|
|
-- otherwise starts servers in its own cwd.
|
|
return vim.lsp.rpc.start({ exe }, dispatchers, { cwd = config.root_dir })
|
|
end,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|