Skip to content
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

workspace/executeCommand not supported #1232

Closed
JeanMertz opened this issue May 4, 2019 · 12 comments
Closed

workspace/executeCommand not supported #1232

JeanMertz opened this issue May 4, 2019 · 12 comments

Comments

@JeanMertz
Copy link
Contributor

The lsp-features.md file mentions that workspace/executeCommand is supported (specifically, apply_code_action):

https://github.com/rust-analyzer/rust-analyzer/blob/a71d0ecd774008bbfe8cb2215ffa6dedd5024877/docs/dev/lsp-features.md#L19-L20

I want to make rust-analyzer code actions work in Vim by updating LanguageClient-neovim, but from what I can tell, workspace/executeCommand is not actually supported anymore?

I can see the handle_execute_command handler being removed in 8abf536#diff-43d4f175343e385858e9f5a752c17d57L370.

Instead, from what I understand, I have to do a textDocument/codeAction request, pick one of the actions to perform, match on the rust-analyzer.applySourceChange command, and then parse the arguments data to apply the changes locally on the client:

https://github.com/rust-analyzer/rust-analyzer/blob/a71d0ecd774008bbfe8cb2215ffa6dedd5024877/crates/ra_lsp_server/src/main_loop/handlers.rs#L630-L633

Are my assumptions correct? If so, then I'll start adding this feature to Vim, and I guess it would make sense to uncheck the box in the supported features list, right?

@matklad
Copy link
Member

matklad commented May 4, 2019

Yeah, right, rust-analyzer.applySourceChange should be supported by the client.

We need microsoft/language-server-protocol#724 to switch to build-in facilities for our code actions

JeanMertz added a commit to rustic-games/LanguageClient-neovim that referenced this issue May 5, 2019
The "rust-analyzer"[0] language server requires the clients to implement
a custom source change operation.

This is similar to the already existing "java.apply.workspaceEdit"
functionality in this language client.

This feature can be removed once rust-analyzer supports server-side file
manipulation[1].

[0]: https://github.com/rust-analyzer/rust-analyzer
[1]: rust-lang/rust-analyzer#1232
@kjeremy
Copy link
Contributor

kjeremy commented May 9, 2019

Would it be better to move applySourceChange into the server and implement workspace/executeCommand and workspace/applyEdit?

@matklad
Copy link
Member

matklad commented May 9, 2019

@kjeremy we can't do that because, because:

  • we can't tell the client to open specific file (needed for unresolved modle fix)
  • we can't tell the client about cursor position (needed for many intentions like add derive)

Ideally, we extend LSP with support for those use-cases, yeah.

@JeanMertz
Copy link
Contributor Author

When adding support for this in Vim, I noticed that the client already had something similar implemented for the/a Java language server.

So apparently it's not unprecedented to leave it up to the clients to handle this (probably for the same reasons you mentioned, @matklad, the LSP spec does not provide the flexibility needed in this case).

autozimu pushed a commit to autozimu/LanguageClient-neovim that referenced this issue Jul 17, 2019
The "rust-analyzer"[0] language server requires the clients to implement
a custom source change operation.

This is similar to the already existing "java.apply.workspaceEdit"
functionality in this language client.

This feature can be removed once rust-analyzer supports server-side file
manipulation[1].

[0]: https://github.com/rust-analyzer/rust-analyzer
[1]: rust-lang/rust-analyzer#1232
@lnicola
Copy link
Member

lnicola commented Jul 15, 2020

This can be closed, I think?

@matklad
Copy link
Member

matklad commented Jul 15, 2020

right, we don't intend to have server-side commands.

@jan-xyz
Copy link

jan-xyz commented Jul 24, 2021

Do I understand this right, that this is a custom implementation needed in every client? I'm coming from Neovim and basically can't use any of the code lenses (Run Test, Debug...) because it's considered a "custom extension/handler" (neovim/neovim#14874 (comment)) and it needs custom implementation. If that's true then it's quite sad and we are again at a point pre-LSP where each editor needs to provide custom code to fully support some features (albeit much less then before).

@matklad
Copy link
Member

matklad commented Jul 24, 2021

@jan-xyz you need https://github.com/simrat39/rust-tools.nvim to gain access to rust-analyzer specific extensions in neovim. If you want to see our extensions upstreamed into the protocol, show your support for corresponding issues on the lsp repo: https://github.com/microsoft/language-server-protocol/issues/created_by/matklad

@jan-xyz
Copy link

jan-xyz commented Jul 25, 2021

Thanks for your reply, I played around with rust-tools and it covers at least some aspect ( I can run individual tests 🤗 ) but the code lenses aren't implemented, I guess I vote and hope that Microsoft will hear our plea...

@matklad
Copy link
Member

matklad commented Jul 25, 2021

( I can run individual tests hugs ) but the code lenses aren't implemented,

If this is about this functionality:

image

then the situation here is even more confusing. What we do here is entirely standard LSP, but still requires custom support from the client. Basically, in the LSP code lens contains a string name of the command to be executed by the client (like "rust-analyzer.runSingle"), and that command needs to be implemented by the client. That is, the way LSP is specced here is "invoke this custom command on the client side".

This particular feature really should have first-class support in the protocol, upstream issue is microsoft/language-server-protocol#944

@jan-xyz
Copy link

jan-xyz commented Jul 25, 2021

Yes! That's the functionality, did I comment on the wrong issue? Since Neovim invokes workspace/executeCommand when I run those code lenses, I thought this is related to this issue.

So what a plugin like rust-tools needs to do is implement rust-analyser.runSingle on the built-in client?

@matklad
Copy link
Member

matklad commented Jul 25, 2021

Aha, my understanding is that shouldn't be happening, opened neovim/neovim#15183 for that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants