Repository navigation
fix(lsp): retain diagnostics across code actions - #315
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
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.cargo test --lib lsp::workspace_edit::tests. Expect all workspace-edit ordering, rename, validation, and rollback tests to pass.cargo clippy --all-targets --all-features -- -D warningsand expect no warnings.