fix(lsp): discard stale diagnostics for outdated document versions#760
Merged
psteinroe merged 1 commit intoJun 18, 2026
Merged
Conversation
When editing large SQL files, rapid didChange notifications each run Session::update_diagnostics, which awaits the DB-backed pull_file_diagnostics. Results for older document versions arrive after newer edits and were still published, causing stale diagnostics to overwrite newer ones. Capture the document version before computing diagnostics and re-read the current version after the await point. If a newer version has arrived, skip publishing so superseded results are discarded. Refs supabase-community#744.
psteinroe
approved these changes
Jun 18, 2026
psteinroe
left a comment
Collaborator
There was a problem hiding this comment.
thanks for taking a look! I like the simplicity of it. I was planning to add a more sophisticated debounce layer but this is might even be sufficient already. Let's try!
Contributor
Author
|
Appreciate you merging this, @psteinroe. Discarding diagnostics computed for an outdated document version should stop the stale results. |
Contributor
Author
|
Thanks @psteinroe - discarding diagnostics computed for an outdated document version should stop stale LSP results from clobbering newer ones. |
Collaborator
thanks for taking care! pushing a new release now :) |
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.
Summary
Discard LSP diagnostics that were computed for an outdated document version, so stale results are never published over a newer (or freshly reopened) document.
Session::update_diagnosticsawaits the DB-backedpull_file_diagnostics. During rapid edits to a large SQL file, eachtextDocument/didChangeruns this synchronously, and responses for older document versions arrive after newer edits have already been applied. Previously those stale results were still published, causing diagnostics computed against superseded snapshots to overwrite newer ones.This change captures the document version before computing diagnostics, re-reads the current version after the await point, and skips publishing when the versions no longer match. Any version mismatch is treated as stale (not just a strictly newer version), which also covers the close/reopen case where a client resets the document version to a lower number.
Why this matters
Refs #744. The issue reports that editing large SQL files triggers a backlog of sequential analysis requests whose stale responses keep getting published after the user stops typing. Discarding results for non-current document versions is one of the fixes the reporter asked for ("Track document version and discard results for non-current versions"), and it removes the visible flicker of stale diagnostics with a minimal, low-risk change. The
Documentstruct already carriesversion, so no schema change is needed.This is a partial fix: debounce, in-flight cancellation tokens, and per-document queue-depth coalescing would reduce the redundant analysis work itself, but they require a dedicated server-side scheduler and are left as a separate, larger change. The version guard is independent and useful on its own.
Testing
session::tests::stale_diagnostics_are_detected_by_version), covering: a newer version arriving (stale), the same version (publish), and a reopened document reset to a lower version (stale). This test has no database dependency.cargo check -p pgls_lsp,cargo fmt -p pgls_lsp --check, andcargo clippy -p pgls_lspall pass.pgls_lspintegration tests are#[sqlx::test]and require a live Postgres test database; they were not run as part of this change (no behavioral change to those paths beyond the version guard).