Skip to content

Commit a5af84e

Browse files
committed
gopls/internal/cache: check views on any on-disk change to go.mod files
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 <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
1 parent a7407fa commit a5af84e

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

gopls/internal/cache/session.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ func bestView[V viewDefiner](ctx context.Context, fs file.Source, fh file.Handle
590590
pushView(&workViews, view)
591591
}
592592
case GoModView:
593-
if modURI == def.gomod {
593+
if _, ok := def.workspaceModFiles[modURI]; ok {
594594
modViews = append(modViews, view)
595595
}
596596
case GOPATHView:
@@ -746,18 +746,12 @@ func (s *Session) DidModifyFiles(ctx context.Context, modifications []file.Modif
746746
checkViews = true
747747
}
748748

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

0 commit comments

Comments
 (0)