diff options
Diffstat (limited to 'internal')
| -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(): + } }() } |
