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>
diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go
index 7110e28..e78d04b 100644
--- a/internal/lsp/cache/view.go
+++ b/internal/lsp/cache/view.go
@@ -126,9 +126,10 @@
// 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 @@
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 @@
}
// 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
}