From 5009109513f6e6e9976e47ab5527250962b3db21 Mon Sep 17 00:00:00 2001 From: Raphael Amorim Date: Thu, 21 Aug 2025 01:10:22 +0200 Subject: [PATCH] feat: add healtchcheck for lsp --- internal/lsp/client.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/internal/lsp/client.go b/internal/lsp/client.go index 4db28c43ac74e4fa1a083b919bcd240ec9d6d04f..28c9e843efc071f2d034da7c28826101b9fd89c9 100644 --- a/internal/lsp/client.go +++ b/internal/lsp/client.go @@ -44,6 +44,10 @@ type Client struct { handlers map[int32]chan *Message handlersMu sync.RWMutex + // Request tracking for cleanup + pendingRequests map[int32]time.Time + pendingRequestsMu sync.RWMutex + // Server request handlers serverRequestHandlers map[string]ServerRequestHandler serverHandlersMu sync.RWMutex @@ -68,6 +72,7 @@ type Client struct { shutdownChan chan struct{} stderrDone chan struct{} messageHandlerDone chan struct{} + healthCheckDone chan struct{} } // NewClient creates a new LSP client. @@ -100,6 +105,7 @@ func NewClient(ctx context.Context, name string, config config.LSPConfig) (*Clie stdout: bufio.NewReader(stdout), stderr: stderr, handlers: make(map[int32]chan *Message), + pendingRequests: make(map[int32]time.Time), notificationHandlers: make(map[string]NotificationHandler), serverRequestHandlers: make(map[string]ServerRequestHandler), diagnostics: make(map[protocol.DocumentURI][]protocol.Diagnostic), @@ -107,6 +113,7 @@ func NewClient(ctx context.Context, name string, config config.LSPConfig) (*Clie shutdownChan: make(chan struct{}), stderrDone: make(chan struct{}), messageHandlerDone: make(chan struct{}), + healthCheckDone: make(chan struct{}), } // Initialize server state @@ -143,6 +150,12 @@ func NewClient(ctx context.Context, name string, config config.LSPConfig) (*Clie client.handleMessages() }() + // Start health check and cleanup goroutine + go func() { + defer close(client.healthCheckDone) + client.startHealthCheckAndCleanup(ctx) + }() + return client, nil }