sublimelsp / LSP

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

Implement textDocument.codeAction.isPreferredSupport #1458

Open rwols opened 3 years ago

rwols commented 3 years ago

Is your feature request related to a problem? Please describe. If there's a code action that is the "most obvious fix", then LSP should have a special keybinding, or maybe a boolean setting, to auto-apply that "most obvious fix".

Describe the solution you'd like Advertise textDocument.codeAction.isPreferredSupport. If a code action with an isPreferred property is among the resulting code actions, add a ⭐ emoji (or something) to the "code actions" annotation to signal that there exists a preferred code action among the possible code actions.

The user can then press an alternative keybinding to immediately apply that preferred action, without opening a dialog panel to select one of the code actions.

The same kind of visual indicator should also be present in the hover popup. I'm not sure what we can signal in the gutter.

Describe alternatives you've considered It could also be a boolean setting in the user preferences, like "auto_apply_preferred_code_action" or something, that when set to true, will auto-apply the preferred code action instead of opening a dialog.

predragnikolic commented 3 years ago

I would not add any visual emojis to represent that one code action is more preferred that the other one.

Instead I would suggest sorting the code actions by the isPreferred property.

So that the preferred code actions are always at the top.

predragnikolic commented 3 years ago

related https://code.visualstudio.com/updates/v1_31#_auto-fix-and-codeactionispreferred

predragnikolic commented 2 years ago

While https://github.com/sublimelsp/LSP/pull/2040 is merged - a code action that is preferred will be pre selected in the quick panel.

I would still keep this issue open until an auto quickfix command is introduced:

The user can then press an alternative keybinding to immediately apply that preferred action, without opening a dialog panel to select one of the code actions.

jwortmann commented 2 years ago

I agree, and I already had in mind to add another argument named "preferred" or "only_preferred" for the lsp_code_actions command. Then an "Auto Fix" key binding could set that to true and also use "only_kinds": "quickfix". But at a first glance it seems to need code adjustments in several places and probably some more refactoring, so I postponed it for later (feel free to take over if anyone wants to implement it).

If the key binding is used without any preferred quickfix action available, it should probably show a short message "No auto fix available" in the status bar to provide some feedback to the user.

For the gutter icon I could imagine to show a slightly modified version of the lightbulb icon, like VSCode does.