@@ -15,6 +15,7 @@ import (
15
15
"path/filepath"
16
16
"sort"
17
17
"strings"
18
+ "sync/atomic"
18
19
"time"
19
20
20
21
"golang.org/x/tools/go/packages"
@@ -28,12 +29,17 @@ import (
28
29
"golang.org/x/tools/internal/span"
29
30
)
30
31
32
+ var loadID uint64 // atomic identifier for loads
33
+
31
34
// load calls packages.Load for the given scopes, updating package metadata,
32
35
// import graph, and mapped files with the result.
33
36
//
34
37
// The resulting error may wrap the moduleErrorMap error type, representing
35
38
// errors associated with specific modules.
36
39
func (s * snapshot ) load (ctx context.Context , allowNetwork bool , scopes ... interface {}) (err error ) {
40
+ id := atomic .AddUint64 (& loadID , 1 )
41
+ eventName := fmt .Sprintf ("go/packages.Load #%d" , id ) // unique name for logging
42
+
37
43
var query []string
38
44
var containsDir bool // for logging
39
45
@@ -138,9 +144,9 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
138
144
return ctx .Err ()
139
145
}
140
146
if err != nil {
141
- event .Error (ctx , "go/packages.Load" , err , tag .Snapshot .Of (s .ID ()), tag .Directory .Of (cfg .Dir ), tag .Query .Of (query ), tag .PackageCount .Of (len (pkgs )))
147
+ event .Error (ctx , eventName , err , tag .Snapshot .Of (s .ID ()), tag .Directory .Of (cfg .Dir ), tag .Query .Of (query ), tag .PackageCount .Of (len (pkgs )))
142
148
} else {
143
- event .Log (ctx , "go/packages.Load" , tag .Snapshot .Of (s .ID ()), tag .Directory .Of (cfg .Dir ), tag .Query .Of (query ), tag .PackageCount .Of (len (pkgs )))
149
+ event .Log (ctx , eventName , tag .Snapshot .Of (s .ID ()), tag .Directory .Of (cfg .Dir ), tag .Query .Of (query ), tag .PackageCount .Of (len (pkgs )))
144
150
}
145
151
if len (pkgs ) == 0 {
146
152
if err == nil {
@@ -168,7 +174,7 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
168
174
}
169
175
170
176
if ! containsDir || s .view .Options ().VerboseOutput {
171
- event .Log (ctx , "go/packages.Load" ,
177
+ event .Log (ctx , eventName ,
172
178
tag .Snapshot .Of (s .ID ()),
173
179
tag .Package .Of (pkg .ID ),
174
180
tag .Files .Of (pkg .CompiledGoFiles ))
@@ -209,6 +215,8 @@ func (s *snapshot) load(ctx context.Context, allowNetwork bool, scopes ...interf
209
215
loadedIDs = append (loadedIDs , id )
210
216
}
211
217
218
+ event .Log (ctx , fmt .Sprintf ("%s: updating metadata for %d packages" , eventName , len (updates )))
219
+
212
220
s .mu .Lock ()
213
221
214
222
// invalidate the reverse transitive closure of packages that have changed.
0 commit comments