fix(lsp): properly remove clients from map on stop/kill

Andrey Nering created

- Delete clients from the map in StopAll and KillAll so they can be
  recreated on restart
- Add StateDisabled to the state check to prevent re-initializing
  disabled clients
- Remove duplicate callback invocation in startServer

💘 Generated with Crush

Assisted-by: Kimi K2.5 via Crush <crush@charm.land>

Change summary

internal/lsp/manager.go | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

Detailed changes

internal/lsp/manager.go 🔗

@@ -201,13 +201,12 @@ func (s *Manager) startServer(ctx context.Context, name, filepath string, server
 	}()
 
 	switch client.GetServerState() {
-	case StateReady, StateStarting:
+	case StateReady, StateStarting, StateDisabled:
 		// already done, return
 		return
 	}
 
 	client.serverState.Store(StateStarting)
-	s.callback(name, client)
 
 	initCtx, cancel := context.WithTimeout(ctx, time.Duration(cmp.Or(cfg.Timeout, 30))*time.Second)
 	defer cancel()
@@ -315,6 +314,7 @@ func (s *Manager) KillAll(context.Context) {
 			defer func() { s.callback(name, client) }()
 			client.client.Kill()
 			client.SetServerState(StateStopped)
+			s.clients.Del(name)
 			slog.Debug("Killed LSP client", "name", name)
 		})
 	}
@@ -335,6 +335,7 @@ func (s *Manager) StopAll(ctx context.Context) {
 				slog.Warn("Failed to stop LSP client", "name", name, "error", err)
 			}
 			client.SetServerState(StateStopped)
+			s.clients.Del(name)
 			slog.Debug("Stopped LSP client", "name", name)
 		})
 	}