Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/govim: add ExperimentalAllowModfileModifications #1027

Merged
merged 1 commit into from
Feb 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/govim/config.vim
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ function! s:validExperimentalProgressPopups(v)
return s:validBool(a:v)
endfunction

function! s:validExperimentalAllowModfileModifications(v)
return s:validBool(a:v)
endfunction

let s:validators = {
\ "FormatOnSave": function("s:validFormatOnSave"),
\ "QuickfixAutoDiagnostics": function("s:validQuickfixAutoDiagnostics"),
Expand All @@ -211,4 +215,5 @@ let s:validators = {
\ "ExperimentalCursorTriggeredHoverPopupOptions": function("s:validExperimentalCursorTriggeredHoverPopupOptions"),
\ "ExperimentalWorkaroundCompleteoptLongest": function("s:validExperimentalWorkaroundCompleteoptLongest"),
\ "ExperimentalProgressPopups": function("s:validExperimentalProgressPopups"),
\ "ExperimentalAllowModfileModifications": function("s:validExperimentalProgressPopups"),
\ }
16 changes: 16 additions & 0 deletions cmd/govim/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,22 @@ type Config struct {
//
// Default: false
ExperimentalProgressPopups *bool `json:",omitempty"`

// ExperimentalAllowModfileModifications controls whether gopls should
// automatically modify go.{mod,sum} as a side effect of its use of cmd/go
// or not. Setting this option to true can be considered a gopls equivalent
// to setting GOFLAGS=-mod=mod when using cmd/go. Leaving it unset or
// setting it to false is equivalent to -mod=readonly. Indeed setting
// GOFLAGS=-mod=XYZ is now considered deprecated as a means of controlling
// this behaviour in gopls.
//
// For reference: in Go 1.16 cmd/go build commands default to -mod=readonly
// (equivalent to leaving this option unset, or setting it to false),
// whereas prior to Go 1.16 the default was -mod=mod (equivalent to setting
// this option to true).
//
// Default: true
ExperimentalAllowModfileModifications *bool `json:",omitempty"`
}

type Command string
Expand Down
3 changes: 3 additions & 0 deletions cmd/govim/config/gen_applygen.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,7 @@ func (r *Config) Apply(v *Config) {
if v.ExperimentalProgressPopups != nil {
r.ExperimentalProgressPopups = v.ExperimentalProgressPopups
}
if v.ExperimentalAllowModfileModifications != nil {
r.ExperimentalAllowModfileModifications = v.ExperimentalAllowModfileModifications
}
}
8 changes: 5 additions & 3 deletions cmd/govim/gopls.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,13 @@ func (g *govimplugin) startGopls() error {
goplsConfig[goplsSymbolStyle] = *conf.SymbolStyle
}

// TODO: This option was introduced as a way to opt-out from the changes introduced in CL 268597.
// This option was introduced as a way to opt-out from the changes introduced in CL 268597.
// According to CL 274532 (that added this opt-out), it is intended to be removed - "Ideally
// we'll be able to remove them in a few months after things stabilize.". We need to handle that
// case before it is removed.
goplsConfig["allowModfileModifications"] = true
// case before it is removed. Following up on that point is tracked in golang.org/issue/44008
if conf.ExperimentalAllowModfileModifications != nil {
goplsConfig["allowModfileModifications"] = *conf.ExperimentalAllowModfileModifications
}

initParams.InitializationOptions = goplsConfig

Expand Down
2 changes: 2 additions & 0 deletions cmd/govim/internal/vimconfig/vimconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type VimConfig struct {
ExperimentalCursorTriggeredHoverPopupOptions *map[string]interface{}
ExperimentalWorkaroundCompleteoptLongest *int
ExperimentalProgressPopups *int
ExperimentalAllowModfileModifications *int
}

func (c *VimConfig) ToConfig(d config.Config) config.Config {
Expand Down Expand Up @@ -59,6 +60,7 @@ func (c *VimConfig) ToConfig(d config.Config) config.Config {
ExperimentalCursorTriggeredHoverPopupOptions: copyMap(c.ExperimentalCursorTriggeredHoverPopupOptions, d.ExperimentalCursorTriggeredHoverPopupOptions),
ExperimentalWorkaroundCompleteoptLongest: boolVal(c.ExperimentalWorkaroundCompleteoptLongest, d.ExperimentalWorkaroundCompleteoptLongest),
ExperimentalProgressPopups: boolVal(c.ExperimentalProgressPopups, d.ExperimentalProgressPopups),
ExperimentalAllowModfileModifications: boolVal(c.ExperimentalAllowModfileModifications, d.ExperimentalAllowModfileModifications),
}
if v.FormatOnSave == nil {
v.FormatOnSave = d.FormatOnSave
Expand Down
25 changes: 13 additions & 12 deletions cmd/govim/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,19 @@ func newplugin(goplspath string, goplsEnv []string, defaults, user *config.Confi
}
if defaults == nil {
defaults = &config.Config{
FormatOnSave: vimconfig.FormatOnSaveVal(config.FormatOnSaveGoImportsGoFmt),
QuickfixAutoDiagnostics: vimconfig.BoolVal(true),
QuickfixSigns: vimconfig.BoolVal(true),
Staticcheck: vimconfig.BoolVal(false),
HighlightDiagnostics: vimconfig.BoolVal(true),
HighlightReferences: vimconfig.BoolVal(true),
HoverDiagnostics: vimconfig.BoolVal(true),
TempModfile: vimconfig.BoolVal(false),
ExperimentalAutoreadLoadedBuffers: vimconfig.BoolVal(false),
SymbolMatcher: vimconfig.SymbolMatcherVal(config.SymbolMatcherFuzzy),
SymbolStyle: vimconfig.SymbolStyleVal(config.SymbolStyleFull),
OpenLastProgressWith: vimconfig.StringVal("below 10split"),
FormatOnSave: vimconfig.FormatOnSaveVal(config.FormatOnSaveGoImportsGoFmt),
QuickfixAutoDiagnostics: vimconfig.BoolVal(true),
QuickfixSigns: vimconfig.BoolVal(true),
Staticcheck: vimconfig.BoolVal(false),
HighlightDiagnostics: vimconfig.BoolVal(true),
HighlightReferences: vimconfig.BoolVal(true),
HoverDiagnostics: vimconfig.BoolVal(true),
TempModfile: vimconfig.BoolVal(false),
ExperimentalAutoreadLoadedBuffers: vimconfig.BoolVal(false),
SymbolMatcher: vimconfig.SymbolMatcherVal(config.SymbolMatcherFuzzy),
SymbolStyle: vimconfig.SymbolStyleVal(config.SymbolStyleFull),
OpenLastProgressWith: vimconfig.StringVal("below 10split"),
ExperimentalAllowModfileModifications: vimconfig.BoolVal(true),
}
}
// Overlay the initial user values on the defaults
Expand Down
2 changes: 1 addition & 1 deletion cmd/govim/testdata/scenario_modreadonly/user_config.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"GoplsEnv": {"GOFLAGS": "-mod=readonly"}
"ExperimentalAllowModfileModifications": false
}