emacs-lsp / lsp-ui

UI integrations for lsp-mode
https://emacs-lsp.github.io/lsp-ui
GNU General Public License v3.0
1.04k stars 139 forks source link

code actions not shown in sideline for rust-analyzer #443

Open tspiteri opened 4 years ago

tspiteri commented 4 years ago

I don't know if this is a problem in lsp-mode, lsp-ui, or rust-analyzer.

Code actions that should be shown in the sideline are not. I traced the issue to lsp-ui-sideline--code-actions which first thing matches the actions against lsp-ui-sideline-actions-kind-regex. All actions however have their kind set to "". Now if kind were nil the action would be accepted, but "" is not, so the code actions are not shown. I couldn't follow where the "" was coming from, and I have no idea whether "" should be accepted and ignored like nil or whether kind shouldn't be "".

As a workaround, adding \|^$ (a choice to accept empty strings) to lsp-ui-sideline-actions-kind-regex works.

yyoncho commented 4 years ago

Kind = "" comes from the server - I think that someone has to validate if vscode show those as quick fixes as well(most likely it does).

Generally, we should separate the actions into 3 groups:

  1. Quick fixes (what lsp-ui is showing)
  2. Refactor actions (we should have lsp-refactor and right-click menu)
  3. Source actions e. g. organize imports - again right-click and a command lsp-source-actions.

ATM we have 1(?) and a method which asks you to select from all actions.

cc @flodiebold

flodiebold commented 4 years ago

I don't know much about this. We will presumably start setting kind properly in the not too distant future. Personally, I don't use the sidebar, I just have lsp-execute-code-action bound to a key. We have a lot of code actions, so showing them all in the sidebar could get annoying fast. (And we do set kind to null for diagnostic quick fixes, I think.)

tspiteri commented 4 years ago

@flodiebold The issue I see there is discoverability, where when you're new to rust-analyzer and haven't studied the assist docs you cannot know which actions are available, or even if there are actions available. When I tried to discover actions by simply invoking lsp-execute-code-action at some points, there is a chance that there is only one code action and it will be immediately applied, and then I had to undo/redo a couple times to figure out what just happened.

yyoncho commented 4 years ago

Related: https://github.com/emacs-lsp/lsp-mode/issues/1237

there is only one code action and it will be immediately applied

See lsp-auto-execute-action

matklad commented 4 years ago

I think "" is what protocl requires for "no specific kind":

export namespace CodeActionKind {

    /**
     * Empty kind.
     */
    export const Empty: CodeActionKind = '';

https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction