Skip to content

Commit fb289fb

Browse files
ridersofrohanstamblerre
authored andcommitted
internal/lsp: fix concurrent map read/write for missingmodules
This change fixes an issue with concurrent map reads and writes that occurred when determining if an import is missing the corresponding dependency in the go.mod file. Change-Id: Ic5cf3a620b4fd84eb4a377d0e4c22edbc8f37540 Reviewed-on: https://go-review.googlesource.com/c/tools/+/221897 Run-TryBot: Rohan Challa <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]> (cherry picked from commit 115860e) Reviewed-on: https://go-review.googlesource.com/c/tools/+/222980 Reviewed-by: Heschi Kreinick <[email protected]>
1 parent c7e21b3 commit fb289fb

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

internal/lsp/source/diagnostics.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ func Diagnostics(ctx context.Context, snapshot Snapshot, ph PackageHandle, missi
6161
warn = true
6262
}
6363

64-
isMissingModule := false
64+
missing := make(map[string]*modfile.Require)
6565
for _, imp := range pkg.Imports() {
66-
if _, ok := missingModules[imp.PkgPath()]; ok {
67-
isMissingModule = true
66+
if req, ok := missingModules[imp.PkgPath()]; ok {
67+
missing[imp.PkgPath()] = req
6868
continue
6969
}
7070
for dep, req := range missingModules {
@@ -77,8 +77,7 @@ func Diagnostics(ctx context.Context, snapshot Snapshot, ph PackageHandle, missi
7777
// )
7878
// They both are related to the same module: "golang.org/x/tools"
7979
if req != nil && strings.HasPrefix(imp.PkgPath(), dep) {
80-
missingModules[imp.PkgPath()] = req
81-
isMissingModule = true
80+
missing[imp.PkgPath()] = req
8281
break
8382
}
8483
}
@@ -90,8 +89,8 @@ func Diagnostics(ctx context.Context, snapshot Snapshot, ph PackageHandle, missi
9089
if err := clearReports(snapshot, reports, fh.File().Identity().URI); err != nil {
9190
return nil, warn, err
9291
}
93-
if isMissingModule {
94-
if err := missingModulesDiagnostics(ctx, snapshot, reports, missingModules, fh.File().Identity().URI); err != nil {
92+
if len(missing) > 0 {
93+
if err := missingModulesDiagnostics(ctx, snapshot, reports, missing, fh.File().Identity().URI); err != nil {
9594
return nil, warn, err
9695
}
9796
}

0 commit comments

Comments
 (0)