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>
This commit is contained in:
parent
61c0d37527
commit
1e2181f3f4
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue