From a5af84e3f3e3a6f2652789eeba70253d6ea8cb4c Mon Sep 17 00:00:00 2001 From: Rob Findley Date: Fri, 9 Feb 2024 14:56:01 +0000 Subject: [PATCH] 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 LUCI-TryBot-Result: Go LUCI --- gopls/internal/cache/session.go | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/gopls/internal/cache/session.go b/gopls/internal/cache/session.go index 102a2261d25..a6802336dc9 100644 --- a/gopls/internal/cache/session.go +++ b/gopls/internal/cache/session.go @@ -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: @@ -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 }