From a23aa4d884bfab4c2f27ea6448bdac98d0ffd9cb Mon Sep 17 00:00:00 2001 From: Jason Ross Date: Sun, 27 Sep 2026 16:21:08 -0500 Subject: [PATCH] fix(ruby): run ruby-lsp on the project's Ruby via rbenv 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. --- lua/plugins/ruby.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 lua/plugins/ruby.lua diff --git a/lua/plugins/ruby.lua b/lua/plugins/ruby.lua new file mode 100644 index 0000000..5de22d9 --- /dev/null +++ b/lua/plugins/ruby.lua @@ -0,0 +1,22 @@ +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, + }, + }, + }, + }, +}