From 1e2181f3f4b5c7c23d8605d9c000a2421690c01c Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 22 Apr 2019 15:28:38 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell --- internal/lsp/diagnostics.go | 16 ++++++++++++++++ internal/lsp/text_synchronization.go | 1 + 2 files changed, 17 insertions(+) diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index ef14a137..f587cbb5 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -14,16 +14,24 @@ import ( ) 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 @@ func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content str 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 @@ func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content str // 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 @@ func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content str 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 f7f6074b..9f207497 100644 --- a/internal/lsp/text_synchronization.go +++ b/internal/lsp/text_synchronization.go @@ -34,6 +34,7 @@ func (s *Server) didChange(ctx context.Context, params *protocol.DidChangeTextDo } text = change.Text } + s.log.Debugf(ctx, "didChange: %s", params.TextDocument.URI) return s.cacheAndDiagnose(ctx, span.NewURI(params.TextDocument.URI), text) }