-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
gopls/internal/cache: simplify usage of snapshot.GoCommandInvocation
The Snapshot.GoCommandInvocation API is a source of confusion, because it passes in a gocommand.Invocation, performs arbitrary mutation, and then passes it back to the caller (which may perform mutation on top). Aside from the readability problems of this indirectness, this API can lead to real bugs, for example if one of the mutations is incompatible with another. Furthermore, the fact that the GoCommandInvocation is the golden source of information about the Go command environment leads to awkwardness and redundant work. For example, to get the packages.Config we called Snapshot.GoCommandInvocation, just to read env, working dir, and build flags (and the now irrelevant ModFile and ModFlag). But GoCommandInvocation wrote overlays, so we'd end up writing overlays twice: once within the gopls layer, and then again in the go/packages go list driver. Simplify as follows: - Pass in dir, verb, args, and env to GoCommandInvocation, to avoid passing around and mutating an Invocation. - Extract the View.Env, which is a useful concept, and apply invocation env on top. Surveying existing use cases that this was correct, as all call sites expected their env not to be overwritten. - Move Snapshot.config to load.go, where it belongs, and simplify not to depend on GoCommandInvocation. Also add an additional test case for BenchmarkReload. Change-Id: I8ae7a13a033360e0e7b0b24ff718b5a22123e99c Reviewed-on: https://go-review.googlesource.com/c/tools/+/626715 Reviewed-by: Alan Donovan <adonovan@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Robert Findley <rfindley@google.com>
- Loading branch information
Showing
9 changed files
with
167 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.