Skip to content

Commit df4e862

Browse files
committed
gopls/internal/settings: minor cleanups
This change causes the "env" setting to require that its JSON value is a mapping from strings to strings, or int for legacy compatibility; but other values (float, array, object, null, bool) are now rejected. Also, group all the deprecated settings together with a comment to resist the temptation to delete them. Change-Id: I7eb2f017e9cda4a3821370034b8e95809a3d8e11 Reviewed-on: https://go-review.googlesource.com/c/tools/+/593075 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 4a26477 commit df4e862

File tree

1 file changed

+55
-44
lines changed

1 file changed

+55
-44
lines changed

gopls/internal/settings/settings.go

+55-44
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,13 @@ const (
723723
// Set updates *options based on the provided JSON value:
724724
// null, bool, string, number, array, or object.
725725
// On failure, it returns one or more non-nil errors.
726-
func (options *Options) Set(value any) (errors []error) {
726+
func (o *Options) Set(value any) (errors []error) {
727727
switch value := value.(type) {
728728
case nil:
729729
case map[string]any:
730730
seen := make(map[string]struct{})
731731
for name, value := range value {
732-
if err := options.set(name, value, seen); err != nil {
732+
if err := o.set(name, value, seen); err != nil {
733733
err := fmt.Errorf("setting option %v: %w", name, err)
734734
errors = append(errors, err)
735735
}
@@ -862,7 +862,13 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
862862
o.Env = make(map[string]string)
863863
}
864864
for k, v := range env {
865-
o.Env[k] = fmt.Sprint(v)
865+
// For historic compatibility, we accept int too (e.g. CGO_ENABLED=1).
866+
switch v.(type) {
867+
case string, int:
868+
o.Env[k] = fmt.Sprint(v)
869+
default:
870+
return fmt.Errorf("invalid map value %T (want string)", v)
871+
}
866872
}
867873

868874
case "buildFlags":
@@ -883,8 +889,6 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
883889
}
884890
o.DirectoryFilters = filters
885891

886-
case "memoryMode":
887-
return deprecatedError("")
888892
case "completionDocumentation":
889893
return setBool(&o.CompletionDocumentation, value)
890894
case "usePlaceholders":
@@ -969,8 +973,6 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
969973
o.Codelenses[source] = enabled
970974
}
971975

972-
// codelens is deprecated, but still works for now.
973-
// TODO(rstambler): Remove this for the gopls/v0.7.0 release.
974976
if name == "codelens" {
975977
return deprecatedError("codelenses")
976978
}
@@ -995,9 +997,6 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
995997
case "verboseWorkDoneProgress":
996998
return setBool(&o.VerboseWorkDoneProgress, value)
997999

998-
case "tempModFile":
999-
return deprecatedError("")
1000-
10011000
case "showBugReports":
10021001
return setBool(&o.ShowBugReports, value)
10031002

@@ -1033,12 +1032,6 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
10331032
case "experimentalPostfixCompletions":
10341033
return setBool(&o.ExperimentalPostfixCompletions, value)
10351034

1036-
case "experimentalWorkspaceModule":
1037-
return deprecatedError("")
1038-
1039-
case "experimentalTemplateSupport": // TODO(pjw): remove after June 2022
1040-
return deprecatedError("")
1041-
10421035
case "templateExtensions":
10431036
switch value := value.(type) {
10441037
case []any:
@@ -1049,9 +1042,6 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
10491042
return fmt.Errorf("unexpected type %T (want JSON array of string)", value)
10501043
}
10511044

1052-
case "experimentalDiagnosticsDelay":
1053-
return deprecatedError("diagnosticsDelay")
1054-
10551045
case "diagnosticsDelay":
10561046
return setDuration(&o.DiagnosticsDelay, value)
10571047

@@ -1063,38 +1053,15 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
10631053
case "analysisProgressReporting":
10641054
return setBool(&o.AnalysisProgressReporting, value)
10651055

1066-
case "experimentalWatchedFileDelay":
1067-
return deprecatedError("")
1068-
1069-
case "experimentalPackageCacheKey":
1070-
return deprecatedError("")
1071-
1072-
case "allowModfileModifications":
1073-
return deprecatedError("")
1074-
10751056
case "allowImplicitNetworkAccess":
10761057
if err := setBool(&o.AllowImplicitNetworkAccess, value); err != nil {
10771058
return err
10781059
}
10791060
return softErrorf("gopls setting \"allowImplicitNetworkAccess\" is deprecated.\nPlease comment on https://go.dev/issue/66861 if this impacts your workflow.")
10801061

1081-
case "experimentalUseInvalidMetadata":
1082-
return deprecatedError("")
1083-
10841062
case "standaloneTags":
10851063
return setStringSlice(&o.StandaloneTags, value)
10861064

1087-
case "allExperiments":
1088-
// golang/go#65548: this setting is a no-op, but we fail don't report it as
1089-
// deprecated, since the nightly VS Code injects it.
1090-
//
1091-
// If, in the future, VS Code stops injecting this, we could theoretically
1092-
// report an error here, but it also seems harmless to keep ignoring this
1093-
// setting forever.
1094-
1095-
case "newDiff":
1096-
return deprecatedError("")
1097-
10981065
case "subdirWatchPatterns":
10991066
return setEnum(&o.SubdirWatchPatterns, value,
11001067
SubdirWatchPatternsOn,
@@ -1116,7 +1083,13 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
11161083
case "zeroConfig":
11171084
return setBool(&o.ZeroConfig, value)
11181085

1119-
// Replaced settings.
1086+
// deprecated and renamed settings
1087+
//
1088+
// These should never be deleted: there is essentially no cost
1089+
// to providing a better error message indefinitely; it's not
1090+
// as if we would ever want to recycle the name of a setting.
1091+
1092+
// renamed
11201093
case "experimentalDisabledAnalyses":
11211094
return deprecatedError("analyses")
11221095

@@ -1138,7 +1111,45 @@ func (o *Options) set(name string, value any, seen map[string]struct{}) error {
11381111
case "caseSensitiveCompletion":
11391112
return deprecatedError("matcher")
11401113

1141-
// Deprecated settings.
1114+
case "experimentalDiagnosticsDelay":
1115+
return deprecatedError("diagnosticsDelay")
1116+
1117+
// deprecated
1118+
case "memoryMode":
1119+
return deprecatedError("")
1120+
1121+
case "tempModFile":
1122+
return deprecatedError("")
1123+
1124+
case "experimentalWorkspaceModule":
1125+
return deprecatedError("")
1126+
1127+
case "experimentalTemplateSupport":
1128+
return deprecatedError("")
1129+
1130+
case "experimentalWatchedFileDelay":
1131+
return deprecatedError("")
1132+
1133+
case "experimentalPackageCacheKey":
1134+
return deprecatedError("")
1135+
1136+
case "allowModfileModifications":
1137+
return deprecatedError("")
1138+
1139+
case "allExperiments":
1140+
// golang/go#65548: this setting is a no-op, but we fail don't report it as
1141+
// deprecated, since the nightly VS Code injects it.
1142+
//
1143+
// If, in the future, VS Code stops injecting this, we could theoretically
1144+
// report an error here, but it also seems harmless to keep ignoring this
1145+
// setting forever.
1146+
1147+
case "experimentalUseInvalidMetadata":
1148+
return deprecatedError("")
1149+
1150+
case "newDiff":
1151+
return deprecatedError("")
1152+
11421153
case "wantSuggestedFixes":
11431154
return deprecatedError("")
11441155

0 commit comments

Comments
 (0)