feat(lsp): non-blocking initialization + configurable diagnostics timeout#13332
Open
ojh102 wants to merge 3 commits intoanomalyco:devfrom
Open
feat(lsp): non-blocking initialization + configurable diagnostics timeout#13332ojh102 wants to merge 3 commits intoanomalyco:devfrom
ojh102 wants to merge 3 commits intoanomalyco:devfrom
Conversation
…imeouts LSP initialization blocks for 45+ seconds on large projects (e.g., kotlin-lsp with Android monorepos), causing timeout errors before any language features become available. Make getClients() synchronous by returning immediately with [] when state is not yet cached, then spawning LSP servers in the background via fire-and-forget promises. Once a server is ready, Bus.publish(Event.Updated) triggers a UI refresh so the editor picks up the new client. Key changes: - Add cachedState module-level variable populated by init() - Convert getClients() from async to sync with early return pattern - Move server.root() resolution and schedule() into fire-and-forget promises - Bus.publish fires on successful client creation, not synchronously - Add 6 tests covering non-blocking behavior, event firing, broken set, and deduplication via spawning map Closes anomalyco#7477
- Add OPENCODE_EXPERIMENTAL_LSP_DIAGNOSTICS_TIMEOUT_MS flag with dynamic getter - Integrate timeout into getDiagnostics() call (defaults to 10_000ms) - Add comprehensive test suite (5 tests) covering default, custom, and invalid values - All tests passing (937 pass, 5 skip, 0 fail) - Typecheck clean (12 successful)
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.
What does this PR do?
On large projects (Android monorepo with
kotlin-lsp),getClients()blocks 45+ seconds waiting for LSP init, which causes timeouts and makes the editor unusable during startup. The 3s diagnostics timeout is also too short for heavy language servers like ESLint.This PR does two things:
Makes
getClients()non-blocking — changes the return type fromPromise<LSPClient.Info[]>toLSPClient.Info[]. Returns immediately with whatever clients are ready (or[]during init), spawns servers in the background, and notifies viaBus.publish(Event.Updated)when new clients come online. The editor stays responsive from the first keystroke.Makes diagnostics timeout configurable — adds
OPENCODE_EXPERIMENTAL_LSP_DIAGNOSTICS_TIMEOUT_MSflag (default bumped from 3s to 10s). Uses the existingnumber()helper and follows the same pattern asOPENCODE_EXPERIMENTAL_BASH_DEFAULT_TIMEOUT_MS.Fixes #13328
Related: #7477, #13272, #13154
Files changed:
packages/opencode/src/lsp/index.ts— non-blockinggetClients()packages/opencode/src/lsp/index.test.ts— 6 tests for non-blocking behaviorpackages/opencode/src/flag/flag.ts— newOPENCODE_EXPERIMENTAL_LSP_DIAGNOSTICS_TIMEOUT_MSflagpackages/opencode/src/lsp/client.ts— uses configurable timeout instead of hardcoded 3spackages/opencode/src/lsp/client.test.ts— 3 tests for timeout configurationHow did you verify your code works?
kotlin-lspon an Android monorepo — editor loads instantly, LSP features appear as servers become ready