diff --git a/internal/lsp/diagnostics.go b/internal/lsp/diagnostics.go index 7ec6b965..0602bbd2 100644 --- a/internal/lsp/diagnostics.go +++ b/internal/lsp/diagnostics.go @@ -32,6 +32,9 @@ func (s *Server) cacheAndDiagnose(ctx context.Context, uri span.URI, content str for uri, diagnostics := range reports { if err := s.publishDiagnostics(ctx, uri, diagnostics); err != nil { + if s.undelivered == nil { + s.undelivered = make(map[span.URI][]source.Diagnostic) + } s.undelivered[uri] = diagnostics continue } diff --git a/internal/lsp/lsp_test.go b/internal/lsp/lsp_test.go index a21b86ca..26da588b 100644 --- a/internal/lsp/lsp_test.go +++ b/internal/lsp/lsp_test.go @@ -74,7 +74,8 @@ func testLSP(t *testing.T, exporter packagestest.Exporter) { log := xlog.New(xlog.StdSink{}) s := &Server{ - view: cache.NewView(ctx, log, "lsp_test", span.FileURI(cfg.Dir), &cfg), + view: cache.NewView(ctx, log, "lsp_test", span.FileURI(cfg.Dir), &cfg), + undelivered: make(map[span.URI][]source.Diagnostic), } // Do a first pass to collect special markers for completion. if err := exported.Expect(map[string]interface{}{