internal/lsp/cache: remove mod upgrade code At this point I'm fairly sure we don't want it. Change-Id: Ib0657e8954463df751ab740aa5f582e496ee035b Reviewed-on: https://go-review.googlesource.com/c/tools/+/286475 Trust: Heschi Kreinick <heschi@google.com> Run-TryBot: Heschi Kreinick <heschi@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
diff --git a/internal/lsp/cache/mod.go b/internal/lsp/cache/mod.go index cfd3fd1..28bf692 100644 --- a/internal/lsp/cache/mod.go +++ b/internal/lsp/cache/mod.go
@@ -6,10 +6,7 @@ import ( "context" - "encoding/json" "fmt" - "io" - "os" "path/filepath" "regexp" "strings" @@ -220,123 +217,6 @@ return mwh.why(ctx, s) } -type modUpgradeHandle struct { - handle *memoize.Handle -} - -type modUpgradeData struct { - // upgrades maps modules to their latest versions. - upgrades map[string]string - - err error -} - -func (muh *modUpgradeHandle) upgrades(ctx context.Context, snapshot *snapshot) (map[string]string, error) { - v, err := muh.handle.Get(ctx, snapshot.generation, snapshot) - if v == nil { - return nil, err - } - data := v.(*modUpgradeData) - return data.upgrades, data.err -} - -// moduleUpgrade describes a module that can be upgraded to a particular -// version. -type moduleUpgrade struct { - Path string - Update struct { - Version string - } -} - -func (s *snapshot) ModUpgrade(ctx context.Context, fh source.FileHandle) (map[string]string, error) { - if fh.Kind() != source.Mod { - return nil, fmt.Errorf("%s is not a go.mod file", fh.URI()) - } - if handle := s.getModUpgradeHandle(fh.URI()); handle != nil { - return handle.upgrades(ctx, s) - } - key := modKey{ - sessionID: s.view.session.id, - env: hashEnv(s), - mod: fh.FileIdentity(), - view: s.view.rootURI.Filename(), - verb: upgrade, - } - h := s.generation.Bind(key, func(ctx context.Context, arg memoize.Arg) interface{} { - ctx, done := event.Start(ctx, "cache.ModUpgradeHandle", tag.URI.Of(fh.URI())) - defer done() - - snapshot := arg.(*snapshot) - - pm, err := snapshot.ParseMod(ctx, fh) - if err != nil { - return &modUpgradeData{err: err} - } - - // No requires to upgrade. - if len(pm.File.Require) == 0 { - return &modUpgradeData{} - } - // Run "go list -mod readonly -u -m all" to be able to see which deps can be - // upgraded without modifying mod file. - inv := &gocommand.Invocation{ - Verb: "list", - Args: []string{"-u", "-m", "-json", "all"}, - WorkingDir: filepath.Dir(fh.URI().Filename()), - } - if s.workspaceMode()&tempModfile == 0 || containsVendor(fh.URI()) { - // Use -mod=readonly if the module contains a vendor directory - // (see golang/go#38711). - inv.ModFlag = "readonly" - } - stdout, err := snapshot.RunGoCommandDirect(ctx, source.Normal|source.AllowNetwork, inv) - if err != nil { - return &modUpgradeData{err: err} - } - var upgradeList []moduleUpgrade - dec := json.NewDecoder(stdout) - for { - var m moduleUpgrade - if err := dec.Decode(&m); err == io.EOF { - break - } else if err != nil { - return &modUpgradeData{err: err} - } - upgradeList = append(upgradeList, m) - } - if len(upgradeList) <= 1 { - return &modUpgradeData{} - } - upgrades := make(map[string]string) - for _, upgrade := range upgradeList[1:] { - if upgrade.Update.Version == "" { - continue - } - upgrades[upgrade.Path] = upgrade.Update.Version - } - return &modUpgradeData{ - upgrades: upgrades, - } - }, nil) - muh := &modUpgradeHandle{handle: h} - s.mu.Lock() - s.modUpgradeHandles[fh.URI()] = muh - s.mu.Unlock() - - return muh.upgrades(ctx, s) -} - -// containsVendor reports whether the module has a vendor folder. -func containsVendor(modURI span.URI) bool { - dir := filepath.Dir(modURI.Filename()) - f, err := os.Stat(filepath.Join(dir, "vendor")) - if err != nil { - return false - } - return f.IsDir() -} - var moduleAtVersionRe = regexp.MustCompile(`^(?P<module>.*)@(?P<version>.*)$`) // extractGoCommandError tries to parse errors that come from the go command
diff --git a/internal/lsp/cache/session.go b/internal/lsp/cache/session.go index 552d1c5..fb1790c 100644 --- a/internal/lsp/cache/session.go +++ b/internal/lsp/cache/session.go
@@ -230,7 +230,6 @@ unloadableFiles: make(map[span.URI]struct{}), parseModHandles: make(map[span.URI]*parseModHandle), modTidyHandles: make(map[span.URI]*modTidyHandle), - modUpgradeHandles: make(map[span.URI]*modUpgradeHandle), modWhyHandles: make(map[span.URI]*modWhyHandle), workspace: workspace, }
diff --git a/internal/lsp/cache/snapshot.go b/internal/lsp/cache/snapshot.go index 7ede4e4..55bb910 100644 --- a/internal/lsp/cache/snapshot.go +++ b/internal/lsp/cache/snapshot.go
@@ -103,9 +103,8 @@ // Preserve go.mod-related handles to avoid garbage-collecting the results // of various calls to the go command. The handles need not refer to only // the view's go.mod file. - modTidyHandles map[span.URI]*modTidyHandle - modUpgradeHandles map[span.URI]*modUpgradeHandle - modWhyHandles map[span.URI]*modWhyHandle + modTidyHandles map[span.URI]*modTidyHandle + modWhyHandles map[span.URI]*modWhyHandle workspace *workspace workspaceDirHandle *memoize.Handle @@ -574,12 +573,6 @@ return s.modWhyHandles[uri] } -func (s *snapshot) getModUpgradeHandle(uri span.URI) *modUpgradeHandle { - s.mu.Lock() - defer s.mu.Unlock() - return s.modUpgradeHandles[uri] -} - func (s *snapshot) getModTidyHandle(uri span.URI) *modTidyHandle { s.mu.Lock() defer s.mu.Unlock() @@ -1296,7 +1289,6 @@ unloadableFiles: make(map[span.URI]struct{}), parseModHandles: make(map[span.URI]*parseModHandle), modTidyHandles: make(map[span.URI]*modTidyHandle), - modUpgradeHandles: make(map[span.URI]*modUpgradeHandle), modWhyHandles: make(map[span.URI]*modWhyHandle), workspace: newWorkspace, } @@ -1341,12 +1333,6 @@ } result.modTidyHandles[k] = v } - for k, v := range s.modUpgradeHandles { - if _, ok := changes[k]; ok { - continue - } - result.modUpgradeHandles[k] = v - } for k, v := range s.modWhyHandles { if _, ok := changes[k]; ok { continue @@ -1400,9 +1386,6 @@ for k := range s.modTidyHandles { delete(result.modTidyHandles, k) } - for k := range s.modUpgradeHandles { - delete(result.modUpgradeHandles, k) - } for k := range s.modWhyHandles { delete(result.modWhyHandles, k) } @@ -1531,9 +1514,6 @@ for _, v := range result.modTidyHandles { newGen.Inherit(v.handle) } - for _, v := range result.modUpgradeHandles { - newGen.Inherit(v.handle) - } for _, v := range result.modWhyHandles { newGen.Inherit(v.handle) }
diff --git a/internal/lsp/source/view.go b/internal/lsp/source/view.go index 329c89a..62ca995 100644 --- a/internal/lsp/source/view.go +++ b/internal/lsp/source/view.go
@@ -109,10 +109,6 @@ // the given go.mod file. ModWhy(ctx context.Context, fh FileHandle) (map[string]string, error) - // ModUpgrade returns the possible updates for the module specified by the - // given go.mod file. - ModUpgrade(ctx context.Context, fh FileHandle) (map[string]string, error) - // ModTidy returns the results of `go mod tidy` for the module specified by // the given go.mod file. ModTidy(ctx context.Context, pm *ParsedModule) (*TidiedModule, error)