@@ -178,24 +178,38 @@ func (s *Manager) startServer(ctx context.Context, name, filepath string, server
181− // check again in case another goroutine started it in the meantime
181+ // Check again in case another goroutine started it in the meantime.
183− client := s.clients.GetOrSet(name, func() *Client {
182+ if client, ok := s.clients.Get(name); ok {
184− var cli *Client
183+ switch client.GetServerState() {
184+ case StateReady, StateStarting, StateDisabled:
185+ s.callback(name, client)
185− cli, err = New(
190+ client, err := New(
189− s.cfg.Resolver(),
194+ s.cfg.Resolver(),
190− s.cfg.WorkingDir(),
195+ s.cfg.WorkingDir(),
191− s.cfg.Options.DebugLSP,
196+ s.cfg.Options.DebugLSP,
195 if err != nil {
198 if err != nil {
196 slog.Error("Failed to create LSP client", "name", name, "error", err)
199 slog.Error("Failed to create LSP client", "name", name, "error", err)
202+ // Only store non-nil clients. If another goroutine raced us,
203+ // prefer the already-stored client.
204+ if existing, ok := s.clients.Get(name); ok {
205+ switch existing.GetServerState() {
206+ case StateReady, StateStarting, StateDisabled:
208+ s.callback(name, existing)
212+ s.clients.Set(name, client)
199 defer func() {
213 defer func() {
200 s.callback(name, client)
214 s.callback(name, client)