mirror of
https://github.com/golang/go
synced 2024-11-18 19:34:41 -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:
parent
9558fe4a78
commit
faf83c64e9
@ -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 {
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user