I'm looking into making the rust-analyzer LSP work as much as possible with Coc.
Everything _mostly_ works out of the box, except that the server does not support workspace/executeCommand, and so code actions don't work.
Instead, the response of a textDocument/codeAction request returns a set of actions, each having their command set to rust-analyzer.applySourceChange, and arguments containing the data needed to manipulate the code locally to apply the source change.
I've implemented something similar before for LanguageClient-neovim.
Given that this doesn't fit into an "extension" (as far as I know), I suspect support for something like this will have to be hard-coded into coc.nvim itself?
Are you open to such a change, or do you have any pointers for me to make this work as expected?
Actually, looking at the code, it seems like this can be handled by registering the rust-analyzer.applySourceChange command to the CommandManager.
The only question is if there's already shared code that supports easy local text manipulation based on span information and text.
I'll have to dig into this some more sometime this weekend, but if you have any other pointers, feel free to let me know.
Okay, that was fairly easy to implement. I'll see about making this into a proper extension, but for starters, this will make sure local edits are applied as expected:
const { commands, workspace } = require('coc.nvim')
exports.activate = context => {
context.subscriptions.push(commands.registerCommand('rust-analyzer.applySourceChange', async({ _cursorPosition, _label, workspaceEdit }) => {
await workspace.applyEdit(workspaceEdit)
}, null, true))
}
For anyone finding this issue: add this to a rust-analyzer.js file in $VIMCONFIG/coc-extensions, and things should work as expected.
I'm porting rust-analyzer-vscode to a coc extension, https://www.npmjs.com/package/coc-rust-analyzer, give it a try.
rust-analyzer.applySourceChange is available now.
@fannheyward great! Are you going to host the code somewhere so others can contribute?
@JeanMertz yes, I'll open it on GitHub later.
These commands are works!
@fannheyward after you have a repo, I'll add a note in Avi-D-coder/coc-rust-analyzer pointing to it, since I never got around to finishing it.
@fannheyward great work so far. Two things I've noticed, but I'm not sure if it's a limitation of the plugin, coc itself, or my configuration:
@Avi-D-coder @JeanMertz I make it open: https://github.com/fannheyward/coc-rust-analyzer
This issue can be closed, any issue/feature/feedback can be post in coc-rust-analyzer repo, thanks.
Most helpful comment
These commands are works!