fix: debounce did_change diagnostics to prevent stale analysis backlog#761
Merged
psteinroe merged 1 commit intoJun 22, 2026
Conversation
Add a per-URL debounce in Session that cancels any pending diagnostic task when a new textDocument/didChange notification arrives, then spawns a fresh 300 ms sleep before calling update_diagnostics. Only the final change in a rapid-fire burst triggers a full analysis run. The existing is_stale_diagnostics guard is retained as a second safety net for any concurrent races. did_close now cancels a pending debounce task for the URL before clearing the document, preventing stale diagnostics from being published after the file is closed. Fixes supabase-community#744
psteinroe
approved these changes
Jun 22, 2026
psteinroe
left a comment
Collaborator
There was a problem hiding this comment.
thanks for fixing this! also thanks for the comments :)
Contributor
Author
|
Thanks @psteinroe, follow-up landed - debouncing did_change diagnostics is a nice complement to the stale-version discard from the other PR. |
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
Arc<Mutex<FxHashMap<Url, AbortHandle>>>) toSessionthat tracks one pending diagnostic task per open document.session.update_diagnostics(url).awaitcall indid_changewithsession.schedule_diagnostics(url), which cancels any in-flight task for that URL and spawns a new one that sleeps 300 ms before running analysis.cancel_pending_diagnosticscalled fromdid_closeso no stale diagnostics fire after a document is closed.is_stale_diagnosticsversion guard is retained as a second safety net for concurrent races.Why this matters
Fixes #744. When editing large SQL files, every keystroke sends a
textDocument/didChangenotification and the server was callingupdate_diagnosticssynchronously for each one. This queued dozens to hundreds of back-to-back analysis requests (some involving DB-backed typechecking), wasting resources on both server and database. With this change, only the final change in a burst triggers an analysis run - matching editor conventions and preventing the stale-analysis backlog described in the issue.Testing
did_changenotifications for the same URL: only oneupdate_diagnosticscall fires after the burst, not one per change (the abort path resets the timer each time).did_changewith no follow-up: diagnostics still publish after the 300 ms delay.did_closewhile a debounce task is pending:cancel_pending_diagnosticsaborts the task before the document is removed.cargo build -p pgls_lspandcargo clippy -p pgls_lsp --all-targetspass with no new errors or warnings.