Skip to content

LSP: support preferred and disabled code actions (isPreferred, disabled) #2237

Todo

Description

@lagergren

What

  • CodeAction.isPreferred (3.15) marks the action that is most likely the right fix, for example the only fix of a diagnostic. VS Code puts it first and uses it for "Auto Fix". The client announces textDocument.codeAction.isPreferredSupport.
  • CodeAction.disabled (3.16) is { reason }: an action that can't be applied here, together with the reason. The client announces disabledSupport. VS Code shows disabled refactorings greyed out, or their reason when the user asks for that kind explicitly.

Why

isPreferred:

  • clangd: sets it on the fix of a diagnostic that has only one (ClangdLSPServer.cpp, OnlyFix->isPreferred = true).
  • ESLint server: sets it on the fix action (server/src/eslintServer.ts).

disabled:

  • typescript-language-server: reads disabledSupport (src/lsp-server.ts, codeActionDisabledSupport). When it is set, it also returns the refactorings that don't apply, as disabled: { reason: notApplicableReason }, with tsserver's reason. Otherwise it leaves them out (src/refactor.ts).

What users miss:

  • Without isPreferred, the right quick fix can be anywhere in the Alt+Enter list.
  • Without disabled, "Extract function" on a selection that can't be extracted silently isn't there, instead of saying why.

Today

How it could be done

isPreferred:

  • Announce isPreferredSupport: true.
  • Let LSPLazyCodeActionIntentionAction implement PriorityAction (both versions). getPriority() returns Priority.TOP, or HIGH, for a preferred quick fix and NORMAL otherwise.
  • The action is lazy: its slot resolves the code action list when the popup asks. getPriority() must not block, so it answers from what is already loaded and otherwise returns NORMAL.

disabled:

  • Announce disabledSupport: true.
  • A disabled action stays in the list, so that the reason can be seen. Selecting it shows the reason with HintManager.showErrorHint instead of applying anything, and it never runs its edit or command.
  • Alternative: hide disabled actions, which is what LSP4IJ effectively does today because servers don't send them. That is less useful. To decide.
  • The "Show CodeAction in the Refactoring menu" idea (Show CodeAction (no quickfix) in the Refactoring menu #196) would make disabled more useful. VS Code shows disabled actions mainly in its Refactor menu.

Test

Code action fixture tests:

  • a preferred quick fix sorts first among several;
  • a disabled refactoring shows its reason and doesn't apply.

Activity

  1. added
    enhancement
    on Nov 25, 2026
  2. cordeirops commented on Nov 28, 2026

    @cordeirops
    Contributor

    Hello @lagergren, I would like to work on this. Could you assign this to me?

    /assign

  3. added this to the Backlog milestone on Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

codeActionenhancement

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions