From 64be3c5c027333f4eee9126cf3fddecb5478ee7b Mon Sep 17 00:00:00 2001 From: Rebecca Stambler Date: Mon, 10 Aug 2020 19:19:30 -0400 Subject: [PATCH] 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 TryBot-Result: Gobot Gobot Reviewed-by: Robert Findley --- internal/lsp/cache/view.go | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/internal/lsp/cache/view.go b/internal/lsp/cache/view.go index 7110e28a9c..e78d04bb45 100644 --- a/internal/lsp/cache/view.go +++ b/internal/lsp/cache/view.go @@ -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 }