internal/lsp: add additional debug logging for diagnostics

This change adds detailed debug logging for lsp.Diagnostics. This is
necessary for further investigation of cases where diagnostics aren't
propagated after a "didChange" request.

Updates golang/go#30786

Change-Id: I30eabf5a1cb17d4538a8860310b450494626b76f
Reviewed-on: https://go-review.googlesource.com/c/tools/+/172971
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go
index ef14a13..f587cbb 100644
--- a/internal/lsp/diagnostics.go
+++ b/internal/lsp/diagnostics.go
@@ -14,16 +14,24 @@
 )
 
 func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content string) error {
+	s.log.Debugf(ctx, "cacheAndDiagnose: %s", uri)
+
 	view := s.findView(ctx, uri)
 	if err := view.SetContent(ctx, uri, []byte(content)); err != nil {
 		return err
 	}
+
+	s.log.Debugf(ctx, "cacheAndDiagnose: set content for %s", uri)
+
 	go func() {
 		ctx := view.BackgroundContext()
 		if ctx.Err() != nil {
 			s.log.Errorf(ctx, "canceling diagnostics for %s: %v", uri, ctx.Err())
 			return
 		}
+
+		s.log.Debugf(ctx, "cacheAndDiagnose: going to get diagnostics for %s", uri)
+
 		reports, err := source.Diagnostics(ctx, view, uri)
 		if err != nil {
 			s.log.Errorf(ctx, "failed to compute diagnostics for %s: %v", uri, err)
@@ -33,6 +41,8 @@
 		s.undeliveredMu.Lock()
 		defer s.undeliveredMu.Unlock()
 
+		s.log.Debugf(ctx, "cacheAndDiagnose: publishing diagnostics")
+
 		for uri, diagnostics := range reports {
 			if err := s.publishDiagnostics(ctx, view, uri, diagnostics); err != nil {
 				if s.undelivered == nil {
@@ -44,6 +54,9 @@
 			// In case we had old, undelivered diagnostics.
 			delete(s.undelivered, uri)
 		}
+
+		s.log.Debugf(ctx, "cacheAndDiagnose: publishing undelivered diagnostics")
+
 		// Anytime we compute diagnostics, make sure to also send along any
 		// undelivered ones (only for remaining URIs).
 		for uri, diagnostics := range s.undelivered {
@@ -53,6 +66,9 @@
 			delete(s.undelivered, uri)
 		}
 	}()
+
+	s.log.Debugf(ctx, "cacheAndDiagnose: done computing diagnostics for %s", uri)
+
 	return nil
 }
 
diff --git a/internal/lsp/text_synchronization.go b/internal/lsp/text_synchronization.go
index f7f6074..9f20749 100644
--- a/internal/lsp/text_synchronization.go
+++ b/internal/lsp/text_synchronization.go
@@ -34,6 +34,7 @@
 		}
 		text = change.Text
 	}
+	s.log.Debugf(ctx, "didChange: %s", params.TextDocument.URI)
 	return s.cacheAndDiagnose(ctx, span.NewURI(params.TextDocument.URI), text)
 }