Skip to content

Commit 1e2181f

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Ian Cottrell <[email protected]>
1 parent 61c0d37 commit 1e2181f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

internal/lsp/diagnostics.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,24 @@ import (
1414
)
1515

1616
func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content string) error {
17+
s.log.Debugf(ctx, "cacheAndDiagnose: %s", uri)
18+
1719
view := s.findView(ctx, uri)
1820
if err := view.SetContent(ctx, uri, []byte(content)); err != nil {
1921
return err
2022
}
23+
24+
s.log.Debugf(ctx, "cacheAndDiagnose: set content for %s", uri)
25+
2126
go func() {
2227
ctx := view.BackgroundContext()
2328
if ctx.Err() != nil {
2429
s.log.Errorf(ctx, "canceling diagnostics for %s: %v", uri, ctx.Err())
2530
return
2631
}
32+
33+
s.log.Debugf(ctx, "cacheAndDiagnose: going to get diagnostics for %s", uri)
34+
2735
reports, err := source.Diagnostics(ctx, view, uri)
2836
if err != nil {
2937
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
3341
s.undeliveredMu.Lock()
3442
defer s.undeliveredMu.Unlock()
3543

44+
s.log.Debugf(ctx, "cacheAndDiagnose: publishing diagnostics")
45+
3646
for uri, diagnostics := range reports {
3747
if err := s.publishDiagnostics(ctx, view, uri, diagnostics); err != nil {
3848
if s.undelivered == nil {
@@ -44,6 +54,9 @@ func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content str
4454
// In case we had old, undelivered diagnostics.
4555
delete(s.undelivered, uri)
4656
}
57+
58+
s.log.Debugf(ctx, "cacheAndDiagnose: publishing undelivered diagnostics")
59+
4760
// Anytime we compute diagnostics, make sure to also send along any
4861
// undelivered ones (only for remaining URIs).
4962
for uri, diagnostics := range s.undelivered {
@@ -53,6 +66,9 @@ func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content str
5366
delete(s.undelivered, uri)
5467
}
5568
}()
69+
70+
s.log.Debugf(ctx, "cacheAndDiagnose: done computing diagnostics for %s", uri)
71+
5672
return nil
5773
}
5874

internal/lsp/text_synchronization.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func (s *Server) didChange(ctx context.Context, params *protocol.DidChangeTextDo
3434
}
3535
text = change.Text
3636
}
37+
s.log.Debugf(ctx, "didChange: %s", params.TextDocument.URI)
3738
return s.cacheAndDiagnose(ctx, span.NewURI(params.TextDocument.URI), text)
3839
}
3940

0 commit comments

Comments
 (0)