aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/cache/mod.go
diff options
context:
space:
mode:
authorHeschi Kreinick <heschi@google.com>2020-02-24 16:46:08 -0500
committerHeschi Kreinick <heschi@google.com>2020-02-25 21:33:46 +0000
commitc5cec6710e927457c3c29d6c156415e8539a5111 (patch)
tree80d1b01d6ab96784ed9b822f54ae2d024e9e04ba /internal/lsp/cache/mod.go
parentee3f11463c6a5531f311052d575e57978fb9bfcf (diff)
downloadgolang-x-tools-c5cec6710e927457c3c29d6c156415e8539a5111.tar.gz
all: consolidate invokeGo implementations
Over time we have accumulated a disturbing number of ways to run the Go command, each of which supported slightly different features and workarounds. Combine all of them. This unavoidably introduces some changes in debug logging behavior; I think we should try to fix them incrementally and consistently. Updates golang/go#37368. Change-Id: I664ca8685bf247a226be3cb807789c2fcddf233d Reviewed-on: https://go-review.googlesource.com/c/tools/+/220737 Run-TryBot: Heschi Kreinick <heschi@google.com> Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Diffstat (limited to 'internal/lsp/cache/mod.go')
-rw-r--r--internal/lsp/cache/mod.go23
1 files changed, 17 insertions, 6 deletions
diff --git a/internal/lsp/cache/mod.go b/internal/lsp/cache/mod.go
index 1241c8b68..54a0749b2 100644
--- a/internal/lsp/cache/mod.go
+++ b/internal/lsp/cache/mod.go
@@ -15,6 +15,7 @@ import (
"golang.org/x/mod/modfile"
"golang.org/x/tools/go/packages"
+ "golang.org/x/tools/internal/gocommand"
"golang.org/x/tools/internal/lsp/protocol"
"golang.org/x/tools/internal/lsp/source"
"golang.org/x/tools/internal/lsp/telemetry"
@@ -169,10 +170,14 @@ func dependencyUpgrades(ctx context.Context, cfg *packages.Config, folder string
return nil, nil
}
// Run "go list -u -m all" to be able to see which deps can be upgraded.
- args := []string{"list"}
- args = append(args, cfg.BuildFlags...)
- args = append(args, []string{"-u", "-m", "all"}...)
- stdout, err := source.InvokeGo(ctx, folder, cfg.Env, args...)
+ inv := gocommand.Invocation{
+ Verb: "list",
+ Args: []string{"-u", "-m", "all"},
+ BuildFlags: cfg.BuildFlags,
+ Env: cfg.Env,
+ WorkingDir: folder,
+ }
+ stdout, err := inv.Run(ctx)
if err != nil {
return nil, err
}
@@ -273,8 +278,14 @@ func (s *snapshot) ModTidyHandle(ctx context.Context, realfh source.FileHandle)
}
// We want to run "go mod tidy" to be able to diff between the real and the temp files.
- args := append([]string{"mod", "tidy"}, cfg.BuildFlags...)
- if _, err := source.InvokeGo(ctx, folder, cfg.Env, args...); err != nil {
+ inv := gocommand.Invocation{
+ Verb: "mod",
+ Args: []string{"tidy"},
+ BuildFlags: cfg.BuildFlags,
+ Env: cfg.Env,
+ WorkingDir: folder,
+ }
+ if _, err := inv.Run(ctx); err != nil {
// Ignore concurrency errors here.
if !modConcurrencyError.MatchString(err.Error()) {
data.err = err