refactor(lsp): coalesce concurrent server startup in manager#2493
Open
iceymoss wants to merge 1 commit intocharmbracelet:mainfrom
Open
refactor(lsp): coalesce concurrent server startup in manager#2493iceymoss wants to merge 1 commit intocharmbracelet:mainfrom
iceymoss wants to merge 1 commit intocharmbracelet:mainfrom
Conversation
Contributor
|
All contributors have signed the CLA ✍️ ✅ |
Contributor
Author
|
I have read the Contributor License Agreement (CLA) and hereby sign the CLA. |
Contributor
Author
|
recheck |
Use singleflight in LSP manager to deduplicate concurrent startup requests for the same server, keep callback/state semantics intact, and clean up failed initialization paths. Made-with: Cursor
9a265b3 to
0c745ef
Compare
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
Refactor
internal/lsp/manager.goto coalesce concurrent LSP startup requests per server name usingsingleflight.Previously,
startServer()relied on repeated check-then-create paths. Under concurrent calls, multiple goroutines could still race to create duplicate clients, then close losers. This worked functionally but added unnecessary startup churn and complexity.Changes
singleflight.Grouptolsp.Manager:requestGroup singleflight.GroupstartServer()into a clearer flow:unavailable, existing active client),LookPath, skip list,handles),isActiveClient(*Client) boolgetActiveClient(name string) (*Client, bool)StateReady/StateError),s.clients.context.WithoutCancel(ctx)for shared startup work so one waiter cancellation does not abort the shared startup operation.Why
Start()calls.Compatibility
Manager.Startusage remains unchanged.Verification
go test ./internal/lspgo test ./internal/lsp/...Notes
Waiter cancellation now only stops waiting for that caller; the shared startup operation may continue for other callers.