feat(core): add TreeSitterClient.idle() to await pending work#881
Open
edlsh wants to merge 2 commits intoanomalyco:mainfrom
Open
feat(core): add TreeSitterClient.idle() to await pending work#881edlsh wants to merge 2 commits intoanomalyco:mainfrom
edlsh wants to merge 2 commits intoanomalyco:mainfrom
Conversation
Add an idle() method that returns a Promise resolving when all pending tree-sitter operations (buffer creates, updates, resets, parser preloads, etc.) complete. This replaces arbitrary setTimeout/Bun.sleep waits in tests with a deterministic state-based approach. The implementation tracks outstanding work via a pendingWorkCount counter with beginTrackedWork()/finish callbacks, per-buffer response queues, and reset-debounce tracking. All tracked work is cleaned up on destroy(). Also fix the worker to always send HIGHLIGHT_RESPONSE even when highlights are empty, preventing idle() from hanging on blank/comment-only content. Un-skip two previously flaky CI tests that now use idle() instead of timing-dependent sleeps.
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
Add
TreeSitterClient.idle()— a method that returns a Promise resolving when all pending tree-sitter operations complete. This eliminates flaky CI tests that relied on arbitrarysetTimeout/Bun.sleepdelays to wait for async highlighting.Changes
packages/core/src/lib/tree-sitter/client.tsidle()public method with tracked-work counting (beginTrackedWork()/finish()callback pattern)pendingBufferResponses) and reset-debounce work (pendingResetDebounces)destroy()packages/core/src/lib/tree-sitter/parser.worker.tsHIGHLIGHT_RESPONSEeven when highlights array is empty. Previously,HANDLE_EDITSandRESET_BUFFERsent no message when highlights were empty with no warning/error, which would causeidle()to hang indefinitely on blank or comment-only content.packages/core/src/lib/tree-sitter/client.test.tsidle(): resolves immediately when nothing pending, and waits for queued buffer updatespackages/core/src/renderables/Code.test.tssetTimeoutwith deterministicidle()+highlightingDone+renderOnce()packages/core/src/renderables/__tests__/LineNumberRenderable.test.tsBun.sleepwithidle()+highlightingDone+renderOnce()Testing
All 124 affected tests pass locally (42 tree-sitter client + 82 renderable tests).