Skip to content

feat: a rename, a code action or workspace/applyEdit asks to confirm the changes whose change annotation needs confirmation - #2400

Open
lagergren wants to merge 1 commit into
redhat-developer:mainfrom
lagergren:feat/change-annotations
Open

lagergren wants to merge 1 commit into
redhat-developer:mainfrom
lagergren:feat/change-annotations

Conversation

@lagergren

Copy link
Copy Markdown
Collaborator

Fixes #2246.

Since LSP 3.16, a workspace edit can annotate its changes (ChangeAnnotation): a text edit (AnnotatedTextEdit) or a file operation refers to an annotation by its annotationId, and an annotation with needsConfirmation asks the client to let the user confirm those changes first. rust-analyzer annotates a change outside the workspace this way, such as a rename that would edit a dependency's sources, but only for a client that announces changeAnnotationSupport. LSP4IJ didn't, and it dropped the annotation ID of a text edit when it read one, so such changes were applied without asking.

What changes

  • Reading the annotation ID: LSP4J reads the text edits of a TextDocumentEdit as TextEdits, which lose the annotationId. The new AnnotatedTextEditTypeAdapterFactory, among LSP4IJ's Gson adapters, reads an edit with one as an AnnotatedTextEdit, and writes it with it. A SnippetTextEdit and a file operation already keep theirs.

  • ChangeAnnotations finds the changes whose annotation needs confirmation, groups them by label (groupsOnLabel), and returns the edit without the changes of the labels that the user doesn't check.

  • The dialog, ChangeAnnotationsDialog, shows:

    • a check box per label, checked;
    • under it, the number of its changes and their files;
    • the annotation's description as the tooltip.

    Apply applies the checked labels and every change that doesn't need confirmation. Cancel applies nothing.

  • Where it's asked:

    • Rename: the dialog covers the edits of all the language servers; Cancel renames nothing.
    • Code action: a code action that has its edit is applied in the intention's write action, where no dialog can open. When its edit needs confirmation, it's applied later instead, in a command of its own, as a resolved code action is. Cancel doesn't execute its command either, as in VS Code.
    • workspace/applyEdit: the label of the request is the dialog's title. Cancel answers applied: false with a failure reason, and unchecked labels still answer applied: true, as in VS Code.
  • Edits that need no confirmation go the way they went before, on the same threads.

  • File operations: the edit of workspace/willCreateFiles, willRenameFiles or willDeleteFiles is applied during the VFS event, where the user can't be asked. Its changes that need confirmation are left out, and a warning is logged. VS Code asks there, but IntelliJ gives no point before the file operation where a dialog could open; tell me if you'd rather apply them.

  • Fallback: ChangeAnnotations.confirm called in a write action leaves out the changes to confirm instead of opening a dialog.

  • Capabilities: LSP4IJ now announces workspace.workspaceEdit.changeAnnotationSupport (groupsOnLabel: true), and honorsChangeAnnotations for rename and code actions.

  • Tests: the mock language server now writes an AnnotatedTextEdit with its annotation ID, as a language server sends it.

  • Docs: a Change annotations section in docs/LSPSupport.md.

Behaviour changes

Before After
A change whose annotation needs confirmation was applied without asking A rename, a code action or workspace/applyEdit asks to confirm it, by label, and leaves out the unchecked labels; Cancel applies nothing
— A willCreateFiles/willRenameFiles/willDeleteFiles edit leaves out its changes that need confirmation
LSP4IJ announced no change annotation support It announces changeAnnotationSupport (groupsOnLabel) and honorsChangeAnnotations for rename and code actions, so rust-analyzer now annotates

Tests

  • ChangeAnnotationsTest, 7 tests:
    • the capabilities;
    • a text edit with an annotation ID is read as an AnnotatedTextEdit and written back with it, which LSP4J alone doesn't do;
    • which changes need confirmation;
    • grouping by label, with the description and the decoded file names;
    • leaving out an unchecked label, including a file operation, an emptied text document edit and the changes map;
    • Apply, unchecking and Cancel;
    • no dialog in a write action.
  • RenameChangeAnnotationsTest: a rename which edits the current file and, with an annotation that needs confirmation, lib.rs: confirmed, unchecked, cancelled, and without an annotation to confirm, which doesn't ask.
  • ChangeAnnotationsCodeActionTest: a code action with its edit, and a resolved one: confirmed, unchecked and cancelled.
  • ChangeAnnotationsWorkspaceEditTest:
    • workspace/applyEdit confirmed, with the dialog titled by the request's label; unchecked, answering applied: true; and cancelled, answering applied: false with the reason;
    • a willRenameFiles edit applied without the change to confirm, and without a dialog.
  • Without the client adapter, 12 of the 13 end-to-end tests fail: the change is applied without asking.
  • Whole suite: 2,887 tests, 0 failures, 7 skipped.
  • 2026.3: the new tests, the snippet code action tests and the workspace edit version tests pass, 55 tests.

…the changes whose change annotation needs confirmation (redhat-developer#2246)

A text edit with an annotationId is read as an AnnotatedTextEdit, which
LSP4J would read as a TextEdit without it. The changes whose annotation
needs confirmation are shown by label in a dialog, each checked: Apply
applies the checked labels and the other changes, and Cancel applies
nothing. The edit of workspace/will*Files, applied during a VFS event,
leaves them out. LSP4IJ announces changeAnnotationSupport (groupsOnLabel)
and honorsChangeAnnotations for rename and code actions.
@lagergren lagergren added this to the 0.30.3 milestone Dec 1, 2026
@lagergren lagergren added enhancement New feature or request rename refactoring labels Dec 1, 2026
@coderabbitai

coderabbitai Bot commented Dec 1, 2026

Copy link
Copy Markdown

Warning

Review limit reached

This review ran on the open-source allowance, not this organization's plan, because the pull request author doesn't have an assigned seat. Waiting won't change this — ask an organization admin to assign them a seat, or add seats in Billing if every seat is already assigned, then retry.

Next included review available in 31 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available.

Learn how review limits work.

Review configuration:

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: 96a16cd0-ba1d-4de7-858c-258dae15ea9e
Commits

Reviewing files that changed from the base of the PR and between 40c9391 and c72094d.

Files selected for processing: 16

  • docs/LSPSupport.md
  • src/main/java/com/redhat/devtools/lsp4ij/ChangeAnnotations.java
  • src/main/java/com/redhat/devtools/lsp4ij/JSONUtils.java
  • src/main/java/com/redhat/devtools/lsp4ij/client/LanguageClientImpl.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/codeAction/LSPLazyCodeActionIntentionAction.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/files/AbstractLSPFileListener.java
  • src/main/java/com/redhat/devtools/lsp4ij/features/rename/LSPRenameRefactoringDialog.java
  • src/main/java/com/redhat/devtools/lsp4ij/internal/adapters/AnnotatedTextEditTypeAdapterFactory.java
  • src/main/java/com/redhat/devtools/lsp4ij/internal/capabilities/ClientCapabilitiesFactory.java
  • src/main/java/com/redhat/devtools/lsp4ij/ui/ChangeAnnotationsDialog.java
  • src/main/resources/messages/LanguageServerBundle.properties
  • src/test/java/com/redhat/devtools/lsp4ij/ChangeAnnotationsTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/ChangeAnnotationsWorkspaceEditTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/codeAction/ChangeAnnotationsCodeActionTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/features/rename/RenameChangeAnnotationsTest.java
  • src/test/java/com/redhat/devtools/lsp4ij/mock/MockConnectionProvider.java

@codecov

codecov Bot commented Dec 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.11111% with 74 lines in your changes missing coverage. Please review.
✅ Project coverage is 60.06%. Comparing base (40c9391) to head (c72094d).

Files with missing lines Patch % Lines
...at/devtools/lsp4ij/ui/ChangeAnnotationsDialog.java 0.00% 33 Missing ⚠️
.../com/redhat/devtools/lsp4ij/ChangeAnnotations.java 79.82% 14 Missing and 9 partials ⚠️
...ij/features/rename/LSPRenameRefactoringDialog.java 65.51% 10 Missing ⚠️
...s/codeAction/LSPLazyCodeActionIntentionAction.java 75.00% 1 Missing and 3 partials ⚠️
...hat/devtools/lsp4ij/client/LanguageClientImpl.java 75.00% 1 Missing and 1 partial ⚠️
.../adapters/AnnotatedTextEditTypeAdapterFactory.java 86.66% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2400      +/-   ##
==========================================
+ Coverage   60.01%   60.06%   +0.05%     
==========================================
  Files         860      863       +3     
  Lines       37725    37930     +205     
  Branches     5923     7866    +1943     
==========================================
+ Hits        22641    22783     +142     
- Misses      11980    12035      +55     
- Partials     3104     3112       +8     

☔ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LSP: support change annotations in workspace edits (changeAnnotationSupport, needsConfirmation)

1 participant