Skip to content

Commit bcd607e

Browse files
committed
gopls/internal/cache: don't log packages when selectively reloading
Previously, gopls would log package contents whenever reloading (but not reinitializing) a workspace--essentially whenever the query did not contain a '...'. But following a big invalidation, gopls may reload hundreds or even thousands of packages. Logging them is tremendously verbose. Change the behavior to simply log packages if and only if verboseOutput is set. This is easier to understand and greatly reduces the noisiness of loading. Also annotate the one test that broke when I experimented with this behavior. We should really have a more robust framework for asserting on loads, but that is a project for another CL. For golang/go#66746 Change-Id: I0eff7fad1b2deb2f170a1c336abf2c2a9e4f56ba Reviewed-on: https://go-review.googlesource.com/c/tools/+/577875 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 6f92c83 commit bcd607e

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

gopls/internal/cache/load.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ func (s *Snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
4747
eventName := fmt.Sprintf("go/packages.Load #%d", id) // unique name for logging
4848

4949
var query []string
50-
var containsDir bool // for logging
51-
var standalone bool // whether this is a load of a standalone file
50+
var standalone bool // whether this is a load of a standalone file
5251

5352
// Keep track of module query -> module path so that we can later correlate query
5453
// errors with errors.
@@ -103,10 +102,6 @@ func (s *Snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
103102
default:
104103
panic(fmt.Sprintf("unknown scope type %T", scope))
105104
}
106-
switch scope.(type) {
107-
case viewLoadScope, moduleLoadScope:
108-
containsDir = true
109-
}
110105
}
111106
if len(query) == 0 {
112107
return nil
@@ -217,7 +212,7 @@ func (s *Snapshot) load(ctx context.Context, allowNetwork bool, scopes ...loadSc
217212
continue
218213
}
219214

220-
if !containsDir || s.Options().VerboseOutput {
215+
if s.Options().VerboseOutput {
221216
event.Log(ctx, eventName, append(
222217
s.Labels(),
223218
tag.Package.Of(pkg.ID),

gopls/internal/test/integration/watch/watch_test.go

+9
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,13 @@ func _() {
363363
// Tests golang/go#38498. Delete a file and then force a reload.
364364
// Assert that we no longer try to load the file.
365365
func TestDeleteFiles(t *testing.T) {
366+
// TODO(rfindley): this test is brittle, because it depends on underspecified
367+
// logging behavior around loads.
368+
//
369+
// We should have a robust way to test loads. It should be possible to assert
370+
// on the specific loads that have occurred, and without the synchronization
371+
// problems associated with logging.
372+
366373
const pkg = `
367374
-- go.mod --
368375
module mod.com
@@ -379,6 +386,8 @@ package a
379386
`
380387
t.Run("close then delete", func(t *testing.T) {
381388
WithOptions(
389+
// verboseOutput causes Snapshot.load to log package files.
390+
// (see the TODO above: this is brittle)
382391
Settings{"verboseOutput": true},
383392
).Run(t, pkg, func(t *testing.T, env *Env) {
384393
env.OpenFile("a/a.go")

0 commit comments

Comments
 (0)