Repository navigation
perf(lsp): stop cancelled requests, and run diagnostics, completions and formatting off the runtime - #954
Open
psteinroe wants to merge 2 commits into
Open
perf(lsp): stop cancelled requests, and run diagnostics, completions and formatting off the runtime#954psteinroe wants to merge 2 commits into
psteinroe wants to merge 2 commits into
Conversation
…and formatting off the runtime When the client cancels a request, the language server now tells the handler to stop through a cancellation flag that the editor walk checks with the document version. Diagnostics, completions, formatting, fixes and statement execution no longer hold the documents lock while they run, and diagnostics, completions and formatting run on the blocking thread pool like hover and the other editor requests.
Diagnostics and completions now run on the blocking thread pool, so the runtime is free while they run and the timeout of the test server fires after one second of wall time, which diagnostics against the database exceed while the other tests run. Allow 30 seconds; a hang still fails.
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 #953.
Two gaps that #931 left.
$/cancelRequestWhen a client cancels a request, tower-lsp drops its future, but the handler kept running on the blocking pool until it finished. On a long file that is seconds of wasted work per cancelled hover, inlay hint or semantic token request, often while the next request for the same document waits for the walk cache.
pgls_workspace::cancellation:with_cancellation(flag, f)sets a flag for the thread that runsf.run_document_requestin the LSP sets the flag when its future is dropped, whether it finished or was cancelled.The documents lock
pull_file_diagnostics,pull_file_formatting,get_completions,fix_fileandexecute_statementheld the read lock of all documents while they ran, so an edit to any document waited for them. Like hover and inlay hints in #931, they now clone the document'sArcand release the lock. In the LSP, diagnostics run withspawn_blocking, and completions and formatting go throughrun_document_request: blocking pool, cancellation, andContentModifiedif the document changed meanwhile.Tests
cancellationunit test: the flag applies while the request runs, nests, and is restored.test_cancelled_requests_stop_walking: a cancelled semantic-token request returns nothing, and the next one returns all tokens.Not covered
$/cancelRequest. The test client can't cancel a request it awaits; the flag is tested at the workspace level.