Skip to content

Commit

Permalink
gopls/internal/cache: check views on any on-disk change to go.mod files
Browse files Browse the repository at this point in the history
To prepare for the follow up change, where we honor local replaces in
the view selection algorithm, treat go.mod files more like go.work files
in a couple places:

- Re-run the view selection algorithm whenever a go.mod file changes on
  disk.
- Use the workspaceModFiles field in the bestView algorithm, rather than
  checking the gomod field directly.

Apart from perhaps running the view selection algorithm more frequently,
this change should have no observable impact.

For golang/go#64888

Change-Id: I9d9a74b876791a77e284a1a1d5fcc7a691199901
Reviewed-on: https://go-review.googlesource.com/c/tools/+/562679
Reviewed-by: Alan Donovan <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
findleyr committed Feb 9, 2024
1 parent a7407fa commit a5af84e
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions gopls/internal/cache/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ func bestView[V viewDefiner](ctx context.Context, fs file.Source, fh file.Handle
pushView(&workViews, view)
}
case GoModView:
if modURI == def.gomod {
if _, ok := def.workspaceModFiles[modURI]; ok {
modViews = append(modViews, view)
}
case GOPATHView:
Expand Down Expand Up @@ -746,18 +746,12 @@ func (s *Session) DidModifyFiles(ctx context.Context, modifications []file.Modif
checkViews = true
}

// Any on-disk change to a go.work file causes recomputing views.
// Any on-disk change to a go.work or go.mod file causes recomputing views.
//
// TODO(rfindley): go.work files need not be named "go.work" -- we need to
// check each view's source to handle the case of an explicit GOWORK value.
// Write a test that fails, and fix this.
if isGoWork(c.URI) && (c.Action == file.Save || c.OnDisk) {
checkViews = true
}
// Opening/Close/Create/Delete of go.mod files all trigger
// re-evaluation of Views. Changes do not as they can't affect the set of
// Views.
if isGoMod(c.URI) && c.Action != file.Change && c.Action != file.Save {
if (isGoWork(c.URI) || isGoMod(c.URI)) && (c.Action == file.Save || c.OnDisk) {
checkViews = true
}

Expand Down

0 comments on commit a5af84e

Please sign in to comment.