aboutsummaryrefslogtreecommitdiff
path: root/internal/lsp/command.go
diff options
context:
space:
mode:
authorRohan Challa <rohan@golang.org>2020-03-23 08:35:36 -0400
committerRebecca Stambler <rstambler@golang.org>2020-04-08 03:22:09 +0000
commit46bd65c8538fb57593a8365bea5663a3239aee37 (patch)
tree0d5909033cc53f34ced1615b0d22002193bbe4d6 /internal/lsp/command.go
parent4d14fc9c00cedea0631fe7d87ee41b1a25031402 (diff)
downloadgolang-x-tools-46bd65c8538fb57593a8365bea5663a3239aee37.tar.gz
internal/lsp/cache: add concurrency error check for go cmds
This change attempts to fix a concurrency error that would cause textDocument/CodeLens, textDocument/Formatting, textDocument/DocumentLink, and textDocument/Hover from failing on go.mod files. The issue was that the go command would return a potential concurrency error since the ModHandle and the ModTidyHandle are both using the temporary go.mod file. Updates golang/go#37824 Change-Id: I6cd63c1f75817c7308e033aec473966536a2a3bd Reviewed-on: https://go-review.googlesource.com/c/tools/+/224917 Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'internal/lsp/command.go')
-rw-r--r--internal/lsp/command.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/internal/lsp/command.go b/internal/lsp/command.go
index 6c5f51f40..280f47e78 100644
--- a/internal/lsp/command.go
+++ b/internal/lsp/command.go
@@ -11,6 +11,7 @@ import (
"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/packagesinternal"
"golang.org/x/tools/internal/xcontext"
errors "golang.org/x/xerrors"
)
@@ -32,14 +33,16 @@ func (s *Server) executeCommand(ctx context.Context, params *protocol.ExecuteCom
if !ok {
return nil, err
}
+ cfg := snapshot.Config(ctx)
// Run go.mod tidy on the view.
inv := gocommand.Invocation{
Verb: "mod",
Args: []string{"tidy"},
- Env: snapshot.Config(ctx).Env,
+ Env: cfg.Env,
WorkingDir: snapshot.View().Folder().Filename(),
}
- if _, err := inv.Run(ctx); err != nil {
+ gocmdRunner := packagesinternal.GetGoCmdRunner(cfg)
+ if _, err := gocmdRunner.Run(ctx, inv); err != nil {
return nil, err
}
case "upgrade.dependency":
@@ -52,14 +55,16 @@ func (s *Server) executeCommand(ctx context.Context, params *protocol.ExecuteCom
if !ok {
return nil, err
}
+ cfg := snapshot.Config(ctx)
// Run "go get" on the dependency to upgrade it to the latest version.
inv := gocommand.Invocation{
Verb: "get",
Args: strings.Split(deps, " "),
- Env: snapshot.Config(ctx).Env,
+ Env: cfg.Env,
WorkingDir: snapshot.View().Folder().Filename(),
}
- if _, err := inv.Run(ctx); err != nil {
+ gocmdRunner := packagesinternal.GetGoCmdRunner(cfg)
+ if _, err := gocmdRunner.Run(ctx, inv); err != nil {
return nil, err
}
}