1
0
mirror of https://github.com/golang/go synced 2024-11-18 19:14:40 -07:00

internal/lsp: fix race in delivering diagnostics to the command line client

Fixes golang/go#32091

Change-Id: I1399a596169384f48d9f2409988226708dcd3473
Reviewed-on: https://go-review.googlesource.com/c/tools/+/177937
Run-TryBot: Ian Cottrell <iancottrell@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
This commit is contained in:
Ian Cottrell 2019-05-17 15:18:39 -04:00
parent 9558fe4a78
commit faf83c64e9
2 changed files with 5 additions and 0 deletions

View File

@ -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 {

View File

@ -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 {