castwide / solargraph

A Ruby language server.
https://solargraph.org
MIT License
1.89k stars 158 forks source link

Add in Refactoring Support Using Code Actions from LSP Spec #614

Open gwillcox-r7 opened 1 year ago

gwillcox-r7 commented 1 year ago

According to https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_codeAction there should be the option using Code Actions to support prompts for fixing code. This also explicitly calls out that these Code Actions can then be used to either fix things automatically or be used as prompts for instructing the user on what might be possible to allow for refactoring or fixing the code.

Sorbet already has some support for this as noted at https://github.com/search?q=repo%3Asorbet%2Fsorbet+RefactorExtract&type=code, and there is an example of how to generate "Move method" code actions at https://github.com/sorbet/sorbet/blob/cd9e60b894bd7de78c100ea91ad8dd20f4109ee2/main/lsp/requests/code_action.cc#L166.

This would allow tools that support it to utilize Solargraph's understanding of the code to suggest refactoring possibilities or fixes for common coding mistakes.

castwide commented 1 year ago

This has been on the roadmap for a while. There's some stubbed functionality for Code Actions in place, but there aren't any actions in production. I'm open to suggestions for actions to implement.

mkaito commented 1 year ago

The one kind of action I keep wishing for is being able to add a rubocop:disable stanza for whatever active complaint my cursor is on.

ipatch commented 1 year ago

i to would appreciate this feature. i have been removing the dust from an old rails project and got solargraph setup and working with neovim native lsp today and noticed it would be super handy to navigate to a warning in a ruby file and apply such fix. as solargraph is showing me same warnings in neovim that i get with running rubocop from a cli