Skip to content

Commit 19db92e

Browse files
committed
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 <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]> gopls-CI: kokoro <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Rebecca Stambler <[email protected]>
1 parent 0cef57b commit 19db92e

File tree

4 files changed

+2
-147
lines changed

4 files changed

+2
-147
lines changed

internal/lsp/cache/mod.go

Lines changed: 0 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ package cache
66

77
import (
88
"context"
9-
"encoding/json"
109
"fmt"
11-
"io"
12-
"os"
1310
"path/filepath"
1411
"regexp"
1512
"strings"
@@ -220,123 +217,6 @@ func (s *snapshot) ModWhy(ctx context.Context, fh source.FileHandle) (map[string
220217
return mwh.why(ctx, s)
221218
}
222219

223-
type modUpgradeHandle struct {
224-
handle *memoize.Handle
225-
}
226-
227-
type modUpgradeData struct {
228-
// upgrades maps modules to their latest versions.
229-
upgrades map[string]string
230-
231-
err error
232-
}
233-
234-
func (muh *modUpgradeHandle) upgrades(ctx context.Context, snapshot *snapshot) (map[string]string, error) {
235-
v, err := muh.handle.Get(ctx, snapshot.generation, snapshot)
236-
if v == nil {
237-
return nil, err
238-
}
239-
data := v.(*modUpgradeData)
240-
return data.upgrades, data.err
241-
}
242-
243-
// moduleUpgrade describes a module that can be upgraded to a particular
244-
// version.
245-
type moduleUpgrade struct {
246-
Path string
247-
Update struct {
248-
Version string
249-
}
250-
}
251-
252-
func (s *snapshot) ModUpgrade(ctx context.Context, fh source.FileHandle) (map[string]string, error) {
253-
if fh.Kind() != source.Mod {
254-
return nil, fmt.Errorf("%s is not a go.mod file", fh.URI())
255-
}
256-
if handle := s.getModUpgradeHandle(fh.URI()); handle != nil {
257-
return handle.upgrades(ctx, s)
258-
}
259-
key := modKey{
260-
sessionID: s.view.session.id,
261-
env: hashEnv(s),
262-
mod: fh.FileIdentity(),
263-
view: s.view.rootURI.Filename(),
264-
verb: upgrade,
265-
}
266-
h := s.generation.Bind(key, func(ctx context.Context, arg memoize.Arg) interface{} {
267-
ctx, done := event.Start(ctx, "cache.ModUpgradeHandle", tag.URI.Of(fh.URI()))
268-
defer done()
269-
270-
snapshot := arg.(*snapshot)
271-
272-
pm, err := snapshot.ParseMod(ctx, fh)
273-
if err != nil {
274-
return &modUpgradeData{err: err}
275-
}
276-
277-
// No requires to upgrade.
278-
if len(pm.File.Require) == 0 {
279-
return &modUpgradeData{}
280-
}
281-
// Run "go list -mod readonly -u -m all" to be able to see which deps can be
282-
// upgraded without modifying mod file.
283-
inv := &gocommand.Invocation{
284-
Verb: "list",
285-
Args: []string{"-u", "-m", "-json", "all"},
286-
WorkingDir: filepath.Dir(fh.URI().Filename()),
287-
}
288-
if s.workspaceMode()&tempModfile == 0 || containsVendor(fh.URI()) {
289-
// Use -mod=readonly if the module contains a vendor directory
290-
// (see golang/go#38711).
291-
inv.ModFlag = "readonly"
292-
}
293-
stdout, err := snapshot.RunGoCommandDirect(ctx, source.Normal|source.AllowNetwork, inv)
294-
if err != nil {
295-
return &modUpgradeData{err: err}
296-
}
297-
var upgradeList []moduleUpgrade
298-
dec := json.NewDecoder(stdout)
299-
for {
300-
var m moduleUpgrade
301-
if err := dec.Decode(&m); err == io.EOF {
302-
break
303-
} else if err != nil {
304-
return &modUpgradeData{err: err}
305-
}
306-
upgradeList = append(upgradeList, m)
307-
}
308-
if len(upgradeList) <= 1 {
309-
return &modUpgradeData{}
310-
}
311-
upgrades := make(map[string]string)
312-
for _, upgrade := range upgradeList[1:] {
313-
if upgrade.Update.Version == "" {
314-
continue
315-
}
316-
upgrades[upgrade.Path] = upgrade.Update.Version
317-
}
318-
return &modUpgradeData{
319-
upgrades: upgrades,
320-
}
321-
}, nil)
322-
muh := &modUpgradeHandle{handle: h}
323-
s.mu.Lock()
324-
s.modUpgradeHandles[fh.URI()] = muh
325-
s.mu.Unlock()
326-
327-
return muh.upgrades(ctx, s)
328-
}
329-
330-
// containsVendor reports whether the module has a vendor folder.
331-
func containsVendor(modURI span.URI) bool {
332-
dir := filepath.Dir(modURI.Filename())
333-
f, err := os.Stat(filepath.Join(dir, "vendor"))
334-
if err != nil {
335-
return false
336-
}
337-
return f.IsDir()
338-
}
339-
340220
var moduleAtVersionRe = regexp.MustCompile(`^(?P<module>.*)@(?P<version>.*)$`)
341221

342222
// extractGoCommandError tries to parse errors that come from the go command

internal/lsp/cache/session.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ func (s *Session) createView(ctx context.Context, name string, folder, tempWorks
230230
unloadableFiles: make(map[span.URI]struct{}),
231231
parseModHandles: make(map[span.URI]*parseModHandle),
232232
modTidyHandles: make(map[span.URI]*modTidyHandle),
233-
modUpgradeHandles: make(map[span.URI]*modUpgradeHandle),
234233
modWhyHandles: make(map[span.URI]*modWhyHandle),
235234
workspace: workspace,
236235
}

internal/lsp/cache/snapshot.go

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,8 @@ type snapshot struct {
103103
// Preserve go.mod-related handles to avoid garbage-collecting the results
104104
// of various calls to the go command. The handles need not refer to only
105105
// the view's go.mod file.
106-
modTidyHandles map[span.URI]*modTidyHandle
107-
modUpgradeHandles map[span.URI]*modUpgradeHandle
108-
modWhyHandles map[span.URI]*modWhyHandle
106+
modTidyHandles map[span.URI]*modTidyHandle
107+
modWhyHandles map[span.URI]*modWhyHandle
109108

110109
workspace *workspace
111110
workspaceDirHandle *memoize.Handle
@@ -574,12 +573,6 @@ func (s *snapshot) getModWhyHandle(uri span.URI) *modWhyHandle {
574573
return s.modWhyHandles[uri]
575574
}
576575

577-
func (s *snapshot) getModUpgradeHandle(uri span.URI) *modUpgradeHandle {
578-
s.mu.Lock()
579-
defer s.mu.Unlock()
580-
return s.modUpgradeHandles[uri]
581-
}
582-
583576
func (s *snapshot) getModTidyHandle(uri span.URI) *modTidyHandle {
584577
s.mu.Lock()
585578
defer s.mu.Unlock()
@@ -1296,7 +1289,6 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
12961289
unloadableFiles: make(map[span.URI]struct{}),
12971290
parseModHandles: make(map[span.URI]*parseModHandle),
12981291
modTidyHandles: make(map[span.URI]*modTidyHandle),
1299-
modUpgradeHandles: make(map[span.URI]*modUpgradeHandle),
13001292
modWhyHandles: make(map[span.URI]*modWhyHandle),
13011293
workspace: newWorkspace,
13021294
}
@@ -1341,12 +1333,6 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
13411333
}
13421334
result.modTidyHandles[k] = v
13431335
}
1344-
for k, v := range s.modUpgradeHandles {
1345-
if _, ok := changes[k]; ok {
1346-
continue
1347-
}
1348-
result.modUpgradeHandles[k] = v
1349-
}
13501336
for k, v := range s.modWhyHandles {
13511337
if _, ok := changes[k]; ok {
13521338
continue
@@ -1400,9 +1386,6 @@ func (s *snapshot) clone(ctx, bgCtx context.Context, changes map[span.URI]*fileC
14001386
for k := range s.modTidyHandles {
14011387
delete(result.modTidyHandles, k)
14021388
}
1403-
for k := range s.modUpgradeHandles {
1404-
delete(result.modUpgradeHandles, k)
1405-
}
14061389
for k := range s.modWhyHandles {
14071390
delete(result.modWhyHandles, k)
14081391
}
@@ -1531,9 +1514,6 @@ copyIDs:
15311514
for _, v := range result.modTidyHandles {
15321515
newGen.Inherit(v.handle)
15331516
}
1534-
for _, v := range result.modUpgradeHandles {
1535-
newGen.Inherit(v.handle)
1536-
}
15371517
for _, v := range result.modWhyHandles {
15381518
newGen.Inherit(v.handle)
15391519
}

internal/lsp/source/view.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,6 @@ type Snapshot interface {
109109
// the given go.mod file.
110110
ModWhy(ctx context.Context, fh FileHandle) (map[string]string, error)
111111

112-
// ModUpgrade returns the possible updates for the module specified by the
113-
// given go.mod file.
114-
ModUpgrade(ctx context.Context, fh FileHandle) (map[string]string, error)
115-
116112
// ModTidy returns the results of `go mod tidy` for the module specified by
117113
// the given go.mod file.
118114
ModTidy(ctx context.Context, pm *ParsedModule) (*TidiedModule, error)

0 commit comments

Comments
 (0)