extension/src/goInstallTools: strengthing minimum go version requirement #3371
+123
−33
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change addresses problems in tools installation surfaced by the recent changes in go and gopls.
The automated Go toolchain switch change added in go1.21 changed the meaning of 'go version' output different. Previously, it was meant exactly the version of the toolchain on the system. After go1.21, this is a go version for chosen for the workspace, computed based on the local toolchain version and the required go version dictated by go.mod or go.work.
The extension has a facility to detect the go version used to compile tools, and ask users to rebuild them if they were built with older go standard libraries. When a local toolchain is older (for example,
go1.21.0
) than the workspace's required go version (go1.22.0
), the 'go version' reportsgo1.22.0
. The extension will detect tools that need recompiling to supportgo1.22.0
project. That works as expected.However, when recompiling those tools with
go install
, the workspace's go version requirement doesn't come into play at all, but only the local toolchain's go version and the target tool's minimum required go version will be used in the toolchain switch decision making. As of today, none of the tools set their minimum required go version to go1.22.x, so if the local toolchain is still go1.21.0,go install
will use go1.21.0 for build.We need to explicitly specify the minimum required version using the
GOTOOLCHAIN
environment variable. In this example, go install withGOTOOLCHAIN=go1.22.0+auto
will address the issue.In this CL,
getGoVersion
to allow the local toolchain version by specifying the optional GOTOOLCHAIN parameter.getGoForInstall
to produce the correct GoVersion object that carries the true version of the local toolchain. (computed withgetGoVersion(..., 'local')
).installTools
to append theGOTOOLCHAIN
env var if the go version to be used for install is older than the project's minimum required go version.Gopls is supposed to prompt when it detects it needs to be recompiled to process the modules that require newer go versions. The extension has relied this as the second, and more reliable defense mechanism. Unfortunately, bugs in the recent gopls stopped gopls from reliably detecting this case or, even made the gopls crash before showing the notification.
Similar crashes can occur in other tools (#3168) when the version is mismatched. Previously,
installTools
warned users only if the go version for install was very old (e.g. go1.15).In this CL,
installTools
's installation tool version check further. So, if the project requires a newer version of go and the go configured for tools installation (maybe due to outdated 'go.toolsManagement.go' setting) is older and is a version that cannot handle automated version switch (<go1.21), it prompts users.Testing involving two versions of go is complex. Changed the runTest helper for 'Installation Tests' test suite to accept extra parameters and stubs, so we can make the installation function under test believe the local go chosen for installation is an older version.
This CL also adjusted the logging of gopls restart activities. When gopls installed (automatically, or from the activation), the extension may attempt to restart the gopls. That may help investigate spurious gopls restarts obeserved during https://github.com/golang/vscode-go/issues/3307.
This CL stops clearing of the Go outputChannel before tool installation or goplay run. This channel is now a log output channel, so it's better not to clear.
Fixes #3168
Change-Id: Id9a4c0fe98c85efb17eb3351cfba5665a83b094d
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/577095
Reviewed-by: Peter Weinberger pjw@google.com
Commit-Queue: Hyang-Ah Hana Kim hyangah@gmail.com
Reviewed-by: Suzy Mueller suzmue@golang.org
kokoro-CI: kokoro noreply+kokoro@google.com
This PR will be imported into Gerrit with the title and first
comment (this text) used to generate the subject and body of
the Gerrit change.
Please ensure you adhere to every item in this list.
More info can be found at https://github.com/golang/go/wiki/CommitMessage
frob the quux before blarfing
"This change modifies Go to ___________"
really needed (ASCII art, table, or long link)
Fixes golang/vscode-go#1234
orUpdates golang/vscode-go#1234
(the latter if this is not a complete fix) to this comment
owner/repo#issue_number
syntax:Fixes golang/tools#1234
Our Gerrit server & GitHub bots enforce CLA compliance instead.