diff --git a/internal/lsp/cmd/check.go b/internal/lsp/cmd/check.go index 59f0599a..c5d9960b 100644 --- a/internal/lsp/cmd/check.go +++ b/internal/lsp/cmd/check.go @@ -62,6 +62,8 @@ func (c *check) Run(ctx context.Context, args ...string) error { case <-time.Tick(30 * time.Second): return fmt.Errorf("timed out waiting for results from %v", file.uri) } + file.diagnosticsMu.Lock() + defer file.diagnosticsMu.Unlock() for _, d := range file.diagnostics { spn, err := file.mapper.RangeSpan(d.Range) if err != nil { diff --git a/internal/lsp/cmd/cmd.go b/internal/lsp/cmd/cmd.go index 9b676c9e..6c9ab2d8 100644 --- a/internal/lsp/cmd/cmd.go +++ b/internal/lsp/cmd/cmd.go @@ -220,6 +220,7 @@ type cmdFile struct { err error added bool hasDiagnostics chan struct{} + diagnosticsMu sync.Mutex diagnostics []protocol.Diagnostic } @@ -306,6 +307,8 @@ func (c *cmdClient) PublishDiagnostics(ctx context.Context, p *protocol.PublishD defer c.filesMu.Unlock() uri := span.URI(p.URI) file := c.getFile(ctx, uri) + file.diagnosticsMu.Lock() + defer file.diagnosticsMu.Unlock() hadDiagnostics := file.diagnostics != nil file.diagnostics = p.Diagnostics if file.diagnostics == nil {