-
Notifications
You must be signed in to change notification settings - Fork 69
Respect vim.lsp.commands, client.commands, and server capabilities when executing CompletionItem.command
#73
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: main
Are you sure you want to change the base?
Conversation
|
I just noticed that cmp behaves weird in certain situations with this change applied. I'll keep this PR as a draft until I figure out why. |
|
Turns out that I actually had to copy and paste the logic inside the |
|
I think it's also worth talking about how I got here for the future googlers. The first symptom of this bug that this PR fixes was rust-analyzer flooding the LSP log file with this error message: (and the manually formatted version for legibility:) I found out that the Also, after this PR is applied, you'll probably see this warning when accepting a completion item from rust-analyzer (assuming you don't have the config discussed below), which I'm guessing will be googled in the future. This is because the commands from completion items are now being handled properly and by default there's no handlers on the client (neovim) side for the vim.lsp.commands["rust-analyzer.triggerParameterHints"] = function()
vim.lsp.buf.signature_help()
endAlternatively, you can just do nothing and only get rid of the warning if you find the parameter hints annoying. vim.lsp.commands["rust-analyzer.triggerParameterHints"] = function() endIf you don't want to modify the global command handlers, you can also put the handler in |
|
I understand your PR, but I'm not sure if the language server is returning If the language server sends a supported command without returning |
|
IMO, we should check |
|
It seems like I have this issue in See this and linked issue for more details: neovim/neovim#32445 What about for example potentially just check if |
|
I'm sorry that it took me this long to reply... To @hrsh7th
Do you mean rust analyzer may not be returning
Yes it does cause an error in that case, but I'd say that's the language server's fault and there's not much we can do about this.
I'm not sure what exactly is your problem with my changes? My code checks if either To @seblyng
Sure, and it looks like that's how blink.cmp implements this part of their plugins, but that actually doesn't work at least in cmp-nvim-lsp. (or maybe also in blink.cmp and it's an overlooked bug? I've never used blink so don't count on me though) We can probably request a change to the upstream like making |
Currently, when cmp-nvim-lsp receives a
CompletionItemwith aCommand, it executes the command by directly making aworkspace/executeCommandrequest.This behavior fails to respect the user-defined command handlers in
vim.lsp.commandsandclient.commands, as well as whether the language server is capable of handling the command.This PR addresses this issue by using the
client:_exec_cmd()method, which does respectvim.lsp.commands,client.commands, and server capabilities.I am aware that
client:_exec_cmd()is probably meant to be a private method and that relying on it might become a problem in the future.However, I'm not sure if copying the whole method over to this plugin would be any better, and a quick search reveals that there are some plugins that do rely on
client:_exec_cmd().Please let me know if you have a better idea.