Repository navigation
Conversation
… the document Hover, inlay hints, semantic tokens and code actions ran on the tokio workers and held the read lock of the documents for the whole walk, so the next edit waited for them. The documents are now shared as Arc snapshots: requests clone one and release the lock, and an edit clones the document if a request still uses it. The LSP runs these requests on the blocking pool. A walk checks every 64 statements whether the document changed and stops if it did; the LSP then answers with ContentModified so that the client asks again.
This was referenced Oct 24, 2026
This branch has not been deployed
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.
Stacked on #930.
The handlers for hover, inlay hints, semantic tokens and code actions ran synchronously inside their
async fns on the tokio workers, and the workspace held the read lock of all documents for the whole request.change_fileneeds the write lock, so a request that took seconds on a long file delayed applying the next keystroke by as much, and$/cancelRequestcouldn't stop anything.What changed
Arc<Document>.on_hover,pull_inlay_hints,pull_semantic_tokensandpull_code_actionsclone theArcand release the lock right away.change_fileusesArc::make_mut, so it clones the document if a request still works on the previous version. Cloning is cheap: the statement caches (PgQueryStore,TreeSitterStore,AnnotationStore) are behind anArcand shared, which is correct because they're keyed by the statement text.LSPServer::run_document_requestruns these handlers withspawn_blocking, like the custom workspace methods already are. If the document version changed while the request ran, it answers withContentModified(-32801), which tells the client to ask again instead of showing outdated results.Timings
From
server.perf_tests.rs(release build): an edit while a cold full semantic-token request runs on the same document.change_fileduring the requestBefore,
change_filewaited for the read lock until the request finished: up to the full request time from #930's table (2.5 s for a cold full request on 20,000 statements).Tests
test_editor_requests_use_document_snapshots: a snapshot taken before an edit keeps its content, a walk of it is abandoned, and a walk of the current document isn't. The LSP and workspace suites pass.Not covered
$/cancelRequestwithout an edit still lets the request finish on the blocking pool.Document's fields).Follow-ups: Cancellation without an edit, and diagnostics, completions and formatting without the documents lock, are in #954.