LSP icon indicating copy to clipboard operation
LSP copied to clipboard

Allow the user to invoke code actions manually

Open ayoub-benali opened this issue 5 years ago • 2 comments

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

ayoub-benali avatar Oct 01 '20 07:10 ayoub-benali

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:

  • expose "LSP: Source actions..." in the quick panel that would list those for active servers
  • add context menu item LSP -> Source actions.... That would probably be a bit confusing next to code actions though...

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.

rchl avatar Oct 01 '20 08:10 rchl

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

ayoub-benali avatar Oct 01 '20 09:10 ayoub-benali