-
Notifications
You must be signed in to change notification settings - Fork 2.3k
fix(ruby_lsp): prevent duplicate clients on second buffer #4132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
lsp/ruby_lsp.lua
Outdated
return client.config.cmd_cwd == config.cmd_cwd | ||
local client_cwd = client.config.cmd_cwd or client.root_dir | ||
local config_cwd = config.cmd_cwd or config.root_dir | ||
return client_cwd == config_cwd |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this thing forcing root_dir to always be equal to CWD?
i would think this whole reuse_client
can be dropped, assuming the other comment is addressed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The custom reuse_client
was added in commit 903045b for monorepo support, but I don't fully understand why cmd_cwd comparison is necessary.
I don't have any monorepos that use ruby. This worked for me and i think it doesn't break the original monorepo support.
324d022
to
dc8e56d
Compare
Updated the fix based on feedback:
This approach:
The commit has been squashed and the message updated. |
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. Solution: Use before_init to ensure cmd_cwd is set for every client. Remove the custom reuse_client function to use Neovim's default reuse logic (compare name + root_dir). Testing: Tested with Neovim 0.11.4 by opening 3 Ruby files. All buffers now correctly reuse the first client.
dc8e56d
to
52b3eea
Compare
}, | ||
reuse_client = function(client, config) | ||
before_init = function(_, config) | ||
config.cmd_cwd = config.root_dir |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sadly, before_init
happens after the cmd
is invoked, which means setting the cmd_cwd
won't have the effect that was intended here.
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 setscmd_cwd
as a side effect during reuse checks. This means the first client is created withoutcmd_cwd
set, causing the reuse check to fail for the second buffer.Solution: Use
before_init
to ensurecmd_cwd
is set for every client before initialization. Remove the customreuse_client
function to use Neovim's default reuse logic (compare name + root_dir).Testing: Tested with Neovim 0.11.4 by opening 3 Ruby files. All buffers now correctly reuse the first client.
Note:
lsp/ast_grep.lua
has the identical pattern and likely has the same issue.