Skip to content

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

In review

Description

@lagergren

What

Since 3.16, a WorkspaceEdit can carry changeAnnotations: a map from an ID to a ChangeAnnotation with { label, needsConfirmation, description }.

  • Text edits (AnnotatedTextEdit) and file operations (create, rename, delete) refer to an annotation by its annotationId.
  • An annotation with needsConfirmation: true asks the client to let the user confirm those changes before they are applied.
  • The client announces it with:
    • workspace.workspaceEdit.changeAnnotationSupport (groupsOnLabel optional);
    • textDocument.rename.honorsChangeAnnotations;
    • textDocument.codeAction.honorsChangeAnnotations.

Why

  • rust-analyzer: marks edits and file renames outside the workspace, for example in a dependency's sources, with an annotation "Edit outside of the workspace" (outside_workspace_annotation_id(), crates/rust-analyzer/src/lsp/to_proto.rs). It does this only when the client announces changeAnnotationSupport.

I found no other mainstream server that uses annotations without looking further. VS Code shows a refactor preview whenever an annotation needs confirmation.

What users miss:

  • Renaming a symbol that is also used in a library's source edits that library without asking.
  • No grouping or labels for the parts of a large edit.

Today

How it could be done

  • In the paths that apply a server's WorkspaceEdit:
    • LSPIJUtils.applyWorkspaceEdit, called for rename, code actions and workspace/applyEdit;
    • collect the changes whose annotation has needsConfirmation: true.
  • If there are any, show one dialog before applying anything:
    • the changes grouped by annotation label (and description as a tooltip);
    • a checkbox per group, as VS Code's preview does;
    • OK applies the checked groups and the unannotated changes, and Cancel applies nothing.
  • A plain DialogWrapper with a CheckboxTree is enough. IntelliJ's own UsageView preview may be too heavy for this.
  • For workspace/applyEdit, unchecked changes still count as applied. The spec leaves it to the client; VS Code answers applied: true too. Cancel answers applied: false with a failureReason.
  • Then announce changeAnnotationSupport: { groupsOnLabel: true } and both honorsChangeAnnotations.

Test

A rename fixture test with one annotated edit with needsConfirmation and one plain edit: accept, uncheck, and cancel.

Activity

  1. modified the milestones: Backlog, 0.30.3 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

No one assigned

    Labels

    enhancementrefactoringrename

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions