sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.63k stars 181 forks source link

Allow the user to invoke code actions manually #1356

Open ayoub-benali opened 3 years ago

ayoub-benali commented 3 years ago

Is your feature request related to a problem? Please describe. Some LSP servers like Metals expects source.organizeImports to be invoked manually, after the document is saved and compiled https://github.com/scalameta/metals/pull/2104#discussion_r496601113. So adding source.organizeImports to lsp_code_actions_on_save setting wouldn't work and triggering the LSP code action in the import area yields "No action available".

Describe the solution you'd like LSP could provide a sublime command that takes the name of the code action as an argument so that the user can setup a key binding, or better LSP-* packages would provide these known code actions out of the box.

Describe alternatives you've considered vscode seems to put the feature under a "source actions" menu: https://github.com/scalameta/metals/pull/1971#issuecomment-687085846 gif

While Vim client seems to list all the codeActionLiteralSupport content: https://github.com/scalameta/metals/pull/1971#issuecomment-687139180 gif

rchl commented 3 years ago

Here are literal code actions reported by some servers:

LSP: LSP-eslint: supported code action kinds: ['quickfix', 'source.fixAll.eslint']
LSP: LSP-stylelint: supported code action kinds: ['quickfix', 'source.fixAll.stylelint']
LSP: LSP-pyright: supported code action kinds: ['quickfix', 'source.organizeImports']

In those cases it would only make sense to expose the source.* ones as quickfix wouldn't do anything. What are the code actions supported by metals?

As for supporting that feature we could:

LSP could provide a sublime command that takes the name of the code action as an argument so that the user can setup a key binding

Not sure how would that know on which server (session) the command should run... Maybe on all of them? Or allow specifying config_name also?

or better LSP-* packages would provide these known code actions out of the box.

In what form? Just extend the command palette? In that case, every source action would have a separate entry.

ayoub-benali commented 3 years ago

What are the code actions supported by metals?

'codeActionKinds': ['quickfix', 'refactor', 'source.organizeImports']}

expose "LSP: Source actions..." in the quick panel that would list those for active servers

I think this would be fine but can the user also set keyboard shortcut with this form ? I want to avoid going through the quick panel each time since I will trigger the same code action.

Maybe on all of them? Or allow specifying config_name also?

Yeah passing the session name as well wouldn't hurt I guess.

In what form? Just extend the command palette? In that case, every source action would have a separate entry.

Yes, in the case of Metals I would add it here: https://github.com/scalameta/metals-sublime/blob/master/LSP-metals.sublime-commands