Skip to content

fix(lsp): retain diagnostics across code actions - #315

Merged
fcoury-oai merged 1 commit into
mainfrom
fcoury/retain-diagnostics-code-actions
Aug 22, 2026
Merged

fcoury-oai merged 1 commit into
mainfrom
fcoury/retain-diagnostics-code-actions

Conversation

@fcoury-oai

Copy link
Copy Markdown
Collaborator

Applying an LSP code action currently replays the prepared workspace edit as a full-buffer replacement. The diagnostic rebase logic therefore treats every range as edited and removes all diagnostics immediately, even when the action only inserts an import and the buffer has not been saved.

Preserve the validated text-edit batches produced during workspace-edit preparation and replay their precise Unicode scalar ranges in protocol order. Each batch is applied from the end inside the existing LSP undo transaction, so unaffected push and pull diagnostics remain attached to their source lines until their respective server channel publishes a fresh report. Atomic validation, resource-operation ordering, and the final-content invariant remain unchanged.

The regression test covers an unsaved import code action, verifies that push and pull diagnostics move with the inserted line, and confirms that each channel clears only when that channel refreshes.

How to Test

  1. Run cargo test --lib workspace_edit_rebases_diagnostics_until_each_channel_refreshes. Expect the unsaved import edit to retain and rebase both diagnostic channels, then clear each only on its own refresh.
  2. Run cargo test --lib lsp::workspace_edit::tests. Expect all workspace-edit ordering, rename, validation, and rollback tests to pass.
  3. Open a Rust file with several diagnostics and accept an import quick fix. Before saving, expect the other diagnostics to remain visible on their shifted lines until rust-analyzer publishes updated diagnostics.
  4. Run cargo clippy --all-targets --all-features -- -D warnings and expect no warnings.

@fcoury-oai
fcoury-oai merged commit 3ab0632 into main Aug 22, 2026
10 checks passed
@fcoury-oai
fcoury-oai deleted the fcoury/retain-diagnostics-code-actions branch August 22, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant