Repository navigation
lsp: compile tree-sitter before first completion - #314
Merged
Merged
Conversation
Completion classifies the cursor with tree-sitter, whose WebAssembly module was compiled on first use: by the first completion request. That takes ~60ms idle (vs ~0.2ms for later classifications) and roughly ten times that on a loaded CI runner, where TestNeovimCompletion's first completion (`hel` → `hello`) then missed its 1s window. The compile also ran inside the parse's 1s timeout, so a slow enough compile could cut the parse short and drop completions (or parse error messages) entirely. The server now starts compiling the module on initialize, alongside the first file's analysis, and an update finishes only once it's compiled, so requests waiting on the file never wait on the compile. Tree-sitter parses compile the module, if nothing has yet, before starting their timeout. Signed-off-by: Alex Suraci <[email protected]>
Deploying dang with
|
| Latest commit: |
0987304
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://edd4c538.dang-3kk.pages.dev |
| Branch Preview URL: | https://lsp-warm-tree-sitter.dang-3kk.pages.dev |
This was referenced Nov 13, 2026
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.
Fixes the
TestLSP/TestNeovimCompletionflake that failed #313's CI twice (tracec728d6607bc56ea4ce96cf9e2bf7a8a1). TheL006 ^ea<C-x><C-o>step senttextDocument/completion, but no response came back within its 1s window.The cause was already on main. Since #307, completion classifies the cursor with tree-sitter compiled to WebAssembly. Its module is compiled on first use, which means the first completion request pays for it. Measured in-process on
testdata/complete.dang:In the failing CI run, analysis of the same file took ~650ms. #313 touches
pkg/dang, so every package's tests reran at once and the runner was loaded. At that rate the cold compile is roughly 600ms, which together with Neovim's round trip ran past the 1s window. One more problem: the compile ran inside the parse's 1streeSitterTimeout, so a slow enough compile could cancel the parse and silently drop completions or parse-error messages.Changes:
tswasm.Loadanddang.LoadTreeSittercompile the module ahead of first use.LoadTreeSitterdoes nothing in no-wasm builds.initialize, in the background, so it runs alongside the first file's analysis.updateFilereleases waiting readers only once the compile is done. Requests that wait on a file, and the test's hover readiness probe, therefore never wait on the compile. After the first time, this costs nothing.inspectEditedTreeandparseSyntaxTreecompile the module before starting their timeout, so the timeout covers only the parse.Tested:
pkg/lsp(includingTestLSP),pkg/dang,pkg/dang/analysis,pkg/dang/tswasm,cmd/dangandtest/nocgoall pass.