Skip to content

Commit 736ef26

Browse files
committed
fix(ruby_lsp): prevent duplicate clients on second buffer
Problem: When opening multiple Ruby buffers, a second LSP client is spawned instead of reusing the first client, even though they share the same root directory. Root cause: The reuse_client function sets cmd_cwd as a side effect during reuse checks. This means the first client is created without cmd_cwd set, causing the reuse check to fail for the second buffer (nil != root_dir). The second client gets cmd_cwd set (due to the side effect), so subsequent buffers correctly reuse it. Solution: Use on_new_config to ensure cmd_cwd is always set before client creation. Update reuse_client to compare without mutation, with fallback to root_dir for backward compatibility.
1 parent ac98db2 commit 736ef26

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lsp/ruby_lsp.lua

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,12 @@ return {
2020
init_options = {
2121
formatter = 'auto',
2222
},
23+
on_new_config = function(config, root_dir)
24+
config.cmd_cwd = root_dir
25+
end,
2326
reuse_client = function(client, config)
24-
config.cmd_cwd = config.root_dir
25-
return client.config.cmd_cwd == config.cmd_cwd
27+
local client_cwd = client.config.cmd_cwd or client.root_dir
28+
local config_cwd = config.cmd_cwd or config.root_dir
29+
return client_cwd == config_cwd
2630
end,
2731
}

0 commit comments

Comments
 (0)