-
Notifications
You must be signed in to change notification settings - Fork 645
Add go tool directory to PATH when invoking tools #2514
Comments
Is this an issue just with staticcheck, or tools in general? |
This is going to be an issue with any tool based on Using In practice, one should prefer setting PATH so that the right |
Agreed on the circular reference issue if the suggestion was the tools use How about the tools using the value set in the environment variable GOROOT? Shouldn't that work? If yes, then you can use the
There are a couple of ways one could do this
|
In general, almost no one should be setting the GOROOT env var anymore. The go tool knows the path at which it was built, and uses that as the default GOROOT. That’s why you need to invoke the tool to learn it.
Thinking about it, the right way to solve this issue is to discourage use of “go.goroot” or even remove it. Instead there should be a way of setting PATH for both the extension and tools, as they should always be in sync anyway.
Does toolsEnvVars apply to the go tool, by the way?
|
I was digging around the code and found that we were already appending the value of GOROOT (as defined by env variable or the go.goroot setting) + I have updated this to instead use whatever is the path the extension uses to run the Go binary. This way, we respect the alternate tools value. Can you try the latest beta version (0.10.3-beta.3) and see if it works as expected for you? |
This bug fix is now available in the latest update (0.11.0) to the Go extension. |
With go/packages, tools need to shell out to the go tool to do their job. It's important that this go tool is the same go tool used by the rest of the editor (which might be based on alternateTools, GOROOT, or PATH, see #1760).
When invoking any tool, the extension should prepend the directory containing the go binary to the PATH environment variable, so the tool will use that go binary.
(I initially reported this as a staticcheck issue when it broke in the standard library: dominikh/go-tools#460.)
The text was updated successfully, but these errors were encountered: