internal/lsp/source: allow opt-out from -mod=readonly, GOPROXY=off

The changes to require more explicit dependency management and network
access are very user-facing, and we may not fully understand their
implications. Allow users to roll them back with options for the moment.
Ideally we'll be able to remove them in a few months after things
stabilize.

Change-Id: I5a5ff7c9f3afa490b9945604109c4e3bd9bd7844
Reviewed-on: https://go-review.googlesource.com/c/tools/+/274532
Trust: Heschi Kreinick <heschi@google.com>
Run-TryBot: Heschi Kreinick <heschi@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Rebecca Stambler <rstambler@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Heschi Kreinick 2020-12-01 12:40:58 -05:00
parent bd5d160bec
commit fa6651ede5
4 changed files with 27 additions and 3 deletions

View File

@ -240,6 +240,19 @@ comprehensively test.
Default: `true`.
### **allowModfileModifications** *bool*
allowModfileModifications disables -mod=readonly, allowing imports from
out-of-scope modules. This option will eventually be removed.
Default: `false`.
### **allowImplicitNetworkAccess** *bool*
allowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module
downloads rather than requiring user action. This option will eventually
be removed.
Default: `false`.
<!-- END Experimental: DO NOT MANUALLY EDIT THIS SECTION -->
## Debugging

View File

@ -249,6 +249,8 @@ func (s *snapshot) RunGoCommandPiped(ctx context.Context, mode source.Invocation
func (s *snapshot) goCommandInvocation(ctx context.Context, flags source.InvocationFlags, inv *gocommand.Invocation) (tmpURI span.URI, updatedInv *gocommand.Invocation, cleanup func(), err error) {
s.view.optionsMu.Lock()
allowModfileModificationOption := s.view.options.AllowModfileModifications
allowNetworkOption := s.view.options.AllowImplicitNetworkAccess
inv.Env = append(append(append(os.Environ(), s.view.options.EnvSlice()...), inv.Env...), "GO111MODULE="+s.view.go111module)
inv.BuildFlags = append([]string{}, s.view.options.BuildFlags...)
s.view.optionsMu.Unlock()
@ -260,7 +262,7 @@ func (s *snapshot) goCommandInvocation(ctx context.Context, flags source.Invocat
}
mode, allowNetwork := flags.Mode(), flags.AllowNetwork()
if !allowNetwork {
if !allowNetwork && !allowNetworkOption {
inv.Env = append(inv.Env, "GOPROXY=off")
}
@ -314,7 +316,7 @@ func (s *snapshot) goCommandInvocation(ctx context.Context, flags source.Invocat
case source.LoadWorkspace, source.Normal:
if vendorEnabled {
inv.ModFlag = "vendor"
} else if s.workspaceMode()&usesWorkspaceModule == 0 {
} else if s.workspaceMode()&usesWorkspaceModule == 0 && !allowModfileModificationOption {
inv.ModFlag = "readonly"
} else {
// Temporarily allow updates for multi-module workspace mode:

File diff suppressed because one or more lines are too long

View File

@ -350,6 +350,15 @@ type ExperimentalOptions struct {
// by an experiment because caching behavior is subtle and difficult to
// comprehensively test.
ExperimentalPackageCacheKey bool
// AllowModfileModifications disables -mod=readonly, allowing imports from
// out-of-scope modules. This option will eventually be removed.
AllowModfileModifications bool
// AllowImplicitNetworkAccess disables GOPROXY=off, allowing implicit module
// downloads rather than requiring user action. This option will eventually
// be removed.
AllowImplicitNetworkAccess bool
}
// DebuggingOptions should not affect the logical execution of Gopls, but may