autozimu / LanguageClient-neovim

Language Server Protocol (LSP) support for vim and neovim.
MIT License
3.55k stars 273 forks source link

Running code action automatically when there is only one #1158

Closed roddyyaga closed 3 years ago

roddyyaga commented 3 years ago

When I run code action I get an FZF window of choices. In the case where there is only one, is there a way to execute it immediately? Adding an extra <CR> in the binding doesn't work.

martskins commented 3 years ago

There's nothing there yet, but I commented on this a few days ago here https://github.com/autozimu/LanguageClient-neovim/issues/854#issuecomment-732363961.

I'll try and see if I can find a nice way to enable this, although it's likely going to be a new function or a modification to one existing function instead of it just selecting it when there's only one. I oppose to the idea of calling the action when there's only one for two reasons: the first reason is that as a user I would like to know what exactly was ran, the second reason is that adding a function that you can call from mappings enables you the call specific actions even without explicitly making the initial code actions call, and I guess that's desirable.

roddyyaga commented 3 years ago

Sure, being able to explicitly call a specific code action would also work and be better.

martskins commented 3 years ago

@roddyyaga Just opened #1160 that would probably address this. Note that that PR only works for code actions, not commands, as they can't be filtered by kind alone, and commands can already be executed via LanguageClient#workspace_executeCommand

martskins commented 3 years ago

Closing via #1160

roddyyaga commented 3 years ago

@martskins

Thanks for coming up with a fix so quickly! For some reason it's not working for me though: hen using executeCodeAction I'm getting [LC] Error: Failure { jsonrpc: Some(V2), error: Error { code: InternalError, message: "Unknown method", data: Some(Object({"method": String("languageClient/executeCodeAction")})) }, id: Num(1) } for some reason (with id incrementing each time). I'm doing :call LanguageClient#executeCodeAction('destruct') where destruct: Destruct is the only language action available at that point. Am I doing something wrong?

martskins commented 3 years ago

Have you compiled the client? The dev branch doesn't produce a binary that you can just use, you need to compile from source to be able to use it. (I'm assuming you are using the dev branch cause I would expect another error otherwise)

roddyyaga commented 3 years ago

Thanks again, that was it!