Skip to content

fix: resolve a code action that has a command but no edit, so that its lazily computed edit is applied before the command - #2193

Merged
lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/resolve-a-code-action-with-a-command
Nov 24, 2026
Merged

lagergren merged 1 commit into
redhat-developer:mainfrom
lagergren:fix/resolve-a-code-action-with-a-command

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2191

What

LSPLazyCodeActionIntentionAction.invoke resolved a code action only when it had neither an edit nor a command. LSP4IJ announces codeAction.resolveSupport.properties: ["edit"], so a language server may compute a code action's edit lazily and still give the action a command to execute after the edit. The Ecstasy language server's safe delete does this. LSP4IJ then never sent codeAction/resolve: it executed the command alone, and nothing was edited.

Change

A code action without an edit is now resolved whenever the language server supports codeAction/resolve, whether or not it has a command. VS Code does the same: it resolves any action without an edit when its provider can resolve. The resolved action is then applied as before:

  • its edit first, in a command of its own that Undo reverts, and only to the text it was made for;
  • then its command.

LSP says "If a code action provides an edit and a command, first the edit is executed and then the command."

A code action that has an edit, or a language server without resolveProvider, is applied as before.

Tests

  • New ResolvedCodeActionTest.testACodeActionWithACommandIsResolvedForItsEditWhichIsAppliedBeforeTheCommand: a code action with data and a command, and no edit, is resolved to an edit. Invoking it applies the edit and then executes the command through workspace/executeCommand.
    • Without the fix it fails: the text stays world instead of hello world, as no codeAction/resolve is sent.
    • With the fix it passes, also headless.
  • The features.codeAction.* and commands.* tests pass on IC 2024.2, 2025.3 and IU 2026.3: 43 each, with 0 failures or skipped.

Behaviour change

Before After
A code action with a command and no edit, from a language server that resolves code actions, executes its command alone, and its lazily computed edit is never asked for It is resolved, and its edit is applied, then its command executed

…s lazily computed edit is applied before the command

LSPLazyCodeActionIntentionAction resolved a code action only when it had
neither an edit nor a command. A language server that computes a code
action's edit lazily, as LSP4IJ's resolveSupport for "edit" allows, may
still give the action a command to execute after the edit, as the
Ecstasy language server's safe delete does. LSP4IJ then never sent
codeAction/resolve: it executed the command alone, and nothing was
edited.

A code action without an edit is now resolved whenever the language
server supports codeAction/resolve, whatever else it has, as VS Code
does. The resolved action is applied as before: its edit first, in a
command of its own that Undo reverts, then its command, as LSP says.

Fixes redhat-developer#2191
@lagergren lagergren added this to the 0.30.2 milestone Nov 24, 2026
@lagergren lagergren added the bug Something isn't working label Nov 24, 2026
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Code actions that include both a deferred edit and a command now apply the edit before running the command, helping ensure both parts of the action take effect in the correct order.

When a code action has no edit and the language server supports resolution, LSP4IJ now resolves it even if it has a command. The test verifies that the resolved edit is applied before the command runs.

Changes: Lazy code action resolution

Layer / File(s) Summary
Resolve and apply code actions
src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java, src/test/java/com/redhat/devtools/lsp4ij/features/codeAction/ResolvedCodeActionTest.java
The invocation path resolves actions that have no edit when resolution is supported, including actions with commands. The test checks that the resolved edit is applied before the command executes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: angelozerr

Merge Risk: Minimal · up to 37620

Code actions that carry a command but no edit are now resolved first. Their edit is applied before the command runs, which matches the behavior requested in the linked issue. Other actions behave as before. No concrete merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title states the main change: a code action with a command but no edit is now resolved so its lazily computed edit is applied before the command. The title matches the raw summary, PR objectives, …
Description check Passed The description is closely related to the changeset. It explains the root cause in LSPLazyCodeActionIntentionAction.invoke, the new resolve condition, the apply order (edit, then command), the added R…
Linked Issues check Passed Issue #2191 requires that a code action without an edit be resolved when the client supports resolving edits, even if it has a command, and that the resolved edit then be applied before the command. A…
Out of Scope Changes check Passed The reviewed changes touch LSPLazyCodeActionIntentionAction.java and ResolvedCodeActionTest.java only. The main-file change is limited to the resolve condition and comments that document the edit-then…
Full details: Title check

Explanation

The title states the main change: a code action with a command but no edit is now resolved so its lazily computed edit is applied before the command. The title matches the raw summary, PR objectives, and linked issue #2191. It uses the conventional 'fix:' prefix. The length (121 characters) is long but still one clear sentence.

Full details: Description check

Explanation

The description is closely related to the changeset. It explains the root cause in LSPLazyCodeActionIntentionAction.invoke, the new resolve condition, the apply order (edit, then command), the added ResolvedCodeActionTest, and the before/after behaviour. It references issue #2191.

Full details: Linked Issues check

Explanation

Issue #2191 requires that a code action without an edit be resolved when the client supports resolving edits, even if it has a command, and that the resolved edit then be applied before the command. At the reviewed head, LSPLazyCodeActionIntentionAction.invoke checks codeAction.getEdit() == null and isResolveCodeActionSupported(file), without checking for a command. It then calls codeAction/resolve through resolveCodeAction, in both the unit-test (synchronous) path and the runtime (asynchronous) path. The resolved action goes to applyResolved, which calls apply. apply applies the edit first, through LSPIJUtils.applyWorkspaceEdit, and then runs the command. Actions with an edit, or from servers without resolve support, still go to apply directly, as before. The added test ResolvedCodeActionTest.testACodeActionWithACommandIsResolvedForItsEditWhichIsAppliedBeforeTheCommand covers the new behavior. The test file was not read directly in this assessment; its result is taken from the PR description and the supplied summary.

Full details: Out of Scope Changes check

Explanation

The reviewed changes touch LSPLazyCodeActionIntentionAction.java and ResolvedCodeActionTest.java only. The main-file change is limited to the resolve condition and comments that document the edit-then-command order. The test change adds coverage for the same behavior. Both changes connect directly to #2191. The extra handling in applyResolved, which validates the edit against a WorkspaceEditSnapshot and runs it in its own write command, supports the issue's requirement that the edit apply to the text it was made for. No unrelated change was found in the supplied summary or the inspected code.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c372673d-a6fd-4fa7-bf9a-6c6b5aadebb2
Commits

Reviewing files that changed from the base of the PR and between 084bf75 and 37620b0.

Files selected for processing: 2

  • src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/codeAction/ResolvedCodeActionTest.java

Included review availability: This review used your included allowance. Your plan provides up to 2 included reviews per hour; 0 remain after this review.

@codecov

codecov Bot commented Nov 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 54.29%. Comparing base (084bf75) to head (37620b0).

Files with missing lines Patch % Lines
...s/codeAction/LSPLazyCodeActionIntentionAction.java 0.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2193      +/-   ##
==========================================
+ Coverage   54.23%   54.29%   +0.06%     
==========================================
  Files         832      832              
  Lines       35334    35334              
  Branches     7286     5535    -1751     
==========================================
+ Hits        19163    19186      +23     
+ Misses      13348    13327      -21     
+ Partials     2823     2821       -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@lagergren
lagergren merged commit d592c89 into redhat-developer:main Nov 24, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A code action that has a command is never resolved, so its lazily computed edit is not applied

1 participant