internal/lsp: signal diagnostic completion if modification failed

If didModifyFiles fails we were never closing the diagnoseDone channel.
This was potentially leaking goroutines in the regtests.

Noticed in
https://storage.googleapis.com/go-build-log/ab4085ce/freebsd-amd64-12_2_149b05c3.log

Change-Id: I906b643d415c915d7be1951e5d8d21bf9016acee
Reviewed-on: https://go-review.googlesource.com/c/tools/+/334250
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/text_synchronization.go b/internal/lsp/text_synchronization.go
index f54ca37..d9a6961 100644
--- a/internal/lsp/text_synchronization.go
+++ b/internal/lsp/text_synchronization.go
@@ -282,6 +282,7 @@
 		// produce a better error message. The actual race to the cache should be
 		// guarded by Session.viewMu.
 		s.stateMu.Unlock()
+		close(diagnoseDone)
 		return errors.New("server is shut down")
 	}
 	s.stateMu.Unlock()
@@ -291,6 +292,7 @@
 
 	snapshots, releases, err := s.session.DidModifyFiles(ctx, modifications)
 	if err != nil {
+		close(diagnoseDone)
 		return err
 	}