internal/lsp/cache: check the user's configuration for GOPACKAGESDRIVER

A user need not necessarily set GOPACKAGESDRIVER in their environment,
but they may still provide it through their configuration.

Change-Id: Ic48328e6a1596ff653a048b24256b8dc44c45b8e
Reviewed-on: https://go-review.googlesource.com/c/tools/+/247817
Run-TryBot: Rebecca Stambler <rstambler@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Rebecca Stambler 2020-08-10 19:19:30 -04:00
parent 2d15c7a537
commit 64be3c5c02
1 changed files with 15 additions and 8 deletions

View File

@ -126,9 +126,10 @@ type View struct {
// Only possible with Go versions 1.14 and above.
tmpMod bool
// goCommand indicates if the user is using the go command or some other
// build system.
goCommand bool
// noGopackagesDriver is true if the user has no value set for the
// GOPACKAGESDRIVER environment variable and no gopackagesdriver binary on
// their machine.
noGopackagesDriver bool
// `go env` variables that need to be tracked by gopls.
gocache, gomodcache, gopath, goprivate string
@ -793,9 +794,9 @@ func (v *View) setBuildConfiguration() (isValid bool) {
defer func() {
v.hasValidBuildConfiguration = isValid
}()
// Since we only really understand the `go` command, if the user is not
// using the go command, assume that their configuration is valid.
if !v.goCommand {
// Since we only really understand the `go` command, if the user has a
// different GOPACKAGESDRIVER, assume that their configuration is valid.
if !v.noGopackagesDriver {
return true
}
// Check if the user is working within a module.
@ -860,11 +861,17 @@ func (v *View) setGoEnv(ctx context.Context, configEnv []string) (string, error)
}
// The value of GOPACKAGESDRIVER is not returned through the go command.
gopackagesdriver := os.Getenv("GOPACKAGESDRIVER")
for _, s := range configEnv {
split := strings.SplitN(s, "=", 2)
if split[0] == "GOPACKAGESDRIVER" {
gopackagesdriver = split[1]
}
}
// A user may also have a gopackagesdriver binary on their machine, which
// works the same way as setting GOPACKAGESDRIVER.
gopackagesdriver := os.Getenv("GOPACKAGESDRIVER")
tool, _ := exec.LookPath("gopackagesdriver")
v.goCommand = gopackagesdriver == "off" || (gopackagesdriver == "" && tool == "")
v.noGopackagesDriver = gopackagesdriver == "off" || (gopackagesdriver == "" && tool == "")
return gomod, nil
}