Repository navigation
Todo
Description
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 announcestextDocument.codeAction.isPreferredSupport.CodeAction.disabled(3.16) is{ reason }: an action that can't be applied here, together with the reason. The client announcesdisabledSupport. 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, asdisabled: { 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
- Neither capability is announced (ClientCapabilitiesFactory.java#L142-L154).
getIsPreferred()andCodeAction.getDisabled()are not read anywhere insrc/main.LSPLazyCodeActionIntentionActionimplementsIntentionAction, DumbAwarewith no priority. So LSP quick fixes keep the server's order among the other intentions.
How it could be done
isPreferred:
- Announce
isPreferredSupport: true. - Let
LSPLazyCodeActionIntentionActionimplementPriorityAction(both versions).getPriority()returnsPriority.TOP, orHIGH, for a preferred quick fix andNORMALotherwise. - 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 returnsNORMAL.
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.showErrorHintinstead 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
disabledmore 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
cordeirops commentedon Nov 28, 2026
Hello @lagergren, I would like to work on this. Could you assign this to me?
/assign