diff options
| author | Paul Buetow <paul@buetow.org> | 2026-03-16 04:12:31 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-03-16 04:12:31 +0200 |
| commit | 2b3615352c9e31cba00ba8eb98c610fc66f6bc3c (patch) | |
| tree | 4a95901fa025335dbaddbacb642f87a808a86860 | |
| parent | c54fb8bceee0341deb973cc06a73c199786832bf (diff) | |
Make deferShowDocument respect serverCtx for graceful shutdown
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| -rw-r--r-- | internal/lsp/handlers_document.go | 14 |
1 files 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(): + } }() } |
