solargraph icon indicating copy to clipboard operation
solargraph copied to clipboard

Add in Refactoring Support Using Code Actions from LSP Spec

Open gwillcox-r7 opened this issue 2 years ago • 3 comments

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.

gwillcox-r7 avatar Nov 28 '22 17:11 gwillcox-r7

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.

castwide avatar Jan 08 '23 01:01 castwide

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.

mkaito avatar Jul 15 '23 13:07 mkaito

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

ipatch avatar Aug 17 '23 03:08 ipatch