-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
fix(lsp): use the same lsp server for filetype if it exists #2287
Conversation
I don't know if there is a spec or something to follow, this is just guessing what vscode does. |
Helix handles this, so I got curious whats the trick, turns out there is no trick, they never spawn an lsp server in response to a goToDefinition request, which now I think about actually make sense. Why do we have that code in the first place, are there actual use cases ? |
If we take a step back, theoretically in response to a gotodefiniton, the lsp server that sent us there should be the one to continue to work |
It might be only really solvable at neovim level though |
Nvm, helix does the exact same thing https://github.com/helix-editor/helix/blob/bcdb475b71b0fbabce57344ac8d2575c23b1bbe0/helix-view/src/editor.rs#L944 |
but helix has a sanity check to compare the original lsp that sent us This can only be done inside nvim itself |
lua/lspconfig/configs.lua
Outdated
-- Check if there is an active server already for this same file type | ||
local active_clients_list = util.get_active_clients_list_by_ft(vim.bo[bufnr].filetype) | ||
if #active_clients_list ~= 0 then | ||
id = active_clients_list[1].id |
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.
I don't think there can use index 1 if there has multiple clients for this filetype . like efm tsserver for ts file the 1 can be efm or tsserver .
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.
We don't have the original lsp client id at this point, so we can't tell which client to choose
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.
I am trying to remove root_dir in lsp start client in core. maybe can solve this. there is no root_dir definition in lsp doc. use wrokspace folder would be better?
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.
I'm not sure if this is a correct approach , helix also have this concept , (emacs as well?)
I'm not sure what vscode does
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.
I asked a bit , seems like vscode sets the root workspace as root but it have more logic to add more workspaces (vscode can handle multiple workspaces at the time)
Honestly I can't answer here as I'm not familiar that much with lsp protocol
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.
I think that works I updated the pr with your code
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.
do we need add the new root dir into the workspaceFolder ?
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.
I'm not sure when I tested with jonhoo original rust problem your snippet fixes it
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.
maybe them belong to one workspace.
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.
maybe them belong to one workspace.
NO, they belong different workspace when you try to open another project file
fix #2285