From 2b3615352c9e31cba00ba8eb98c610fc66f6bc3c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 16 Mar 2026 04:12:31 +0200 Subject: Make deferShowDocument respect serverCtx for graceful shutdown Co-Authored-By: Claude Opus 4.6 --- internal/lsp/handlers_document.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/internal/lsp/handlers_document.go b/internal/lsp/handlers_document.go index af52b09..0e6d8e1 100644 --- a/internal/lsp/handlers_document.go +++ b/internal/lsp/handlers_document.go @@ -429,9 +429,19 @@ func (s *Server) clientShowDocument(uri string, sel *Range) { // deferShowDocument schedules a showDocument after a short delay to allow the client // time to apply any pending edits (e.g., create the file before focusing it). +// The goroutine respects s.serverCtx so it won't write after shutdown. func (s *Server) deferShowDocument(uri string, sel Range) { + ctx := s.serverCtx go func() { - time.Sleep(120 * time.Millisecond) - s.clientShowDocument(uri, &sel) + if ctx == nil { + time.Sleep(120 * time.Millisecond) + s.clientShowDocument(uri, &sel) + return + } + select { + case <-time.After(120 * time.Millisecond): + s.clientShowDocument(uri, &sel) + case <-ctx.Done(): + } }() } -- cgit v1.2.3