Skip to content

Commit fb2b4b1

Browse files
madelinekalilh9jiang
authored andcommitted
extension/tools/goplssetting: handle integer types
The upcoming release of gopls v0.22.0 contains a new setting, maxFileCacheBytes, which is an int64. Previously, the generation script for the gopls settings did not handle settings with integer types, which is causing the gopls pre-release workflow to fail on the final step (update gopls settings in vscode). This CL adds support for all builtin integer types in the gopls settings generation script. Change-Id: I281a34d562183c2dbe9885cf6d84669f04e54e7d Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/772240 TryBot-Bypass: Hongxiang Jiang <hxjiang@golang.org> Reviewed-by: Hongxiang Jiang <hxjiang@golang.org>
1 parent 60c3930 commit fb2b4b1

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

extension/tools/goplssetting/goplssetting.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ func toObject(opt *Option) (*Object, error) {
335335
return obj, nil
336336
}
337337

338-
func formatOptionDefault(opt *Option) interface{} {
338+
func formatOptionDefault(opt *Option) any {
339339
// Each key will have its own default value, instead of one large global
340340
// one. (Alternatively, we can build the default from the keys.)
341341
if len(opt.EnumKeys.Keys) > 0 {
@@ -348,7 +348,7 @@ func formatOptionDefault(opt *Option) interface{} {
348348
// formatDefault converts a string-based default value to an actual value that
349349
// can be marshaled to JSON. Right now, gopls generates default values as
350350
// strings, but perhaps that will change.
351-
func formatDefault(def, typ string) interface{} {
351+
func formatDefault(def, typ string) any {
352352
switch typ {
353353
case "enum", "string", "time.Duration":
354354
unquote, err := strconv.Unquote(def)
@@ -360,6 +360,14 @@ func formatDefault(def, typ string) interface{} {
360360
if err := json.Unmarshal([]byte(def), &x); err == nil {
361361
return x
362362
}
363+
case "int", "int8", "int16", "int32", "int64":
364+
if i, err := strconv.ParseInt(def, 10, 64); err == nil {
365+
return i
366+
}
367+
case "uint", "uint8", "uint16", "uint32", "uint64":
368+
if u, err := strconv.ParseUint(def, 10, 64); err == nil {
369+
return u
370+
}
363371
}
364372
switch def {
365373
case "{}", "[]":
@@ -406,6 +414,9 @@ func mapType(t string) string {
406414
return "object"
407415
case "any":
408416
return "boolean"
417+
case "int", "int8", "int16", "int32", "int64",
418+
"uint", "uint8", "uint16", "uint32", "uint64":
419+
return "number"
409420
}
410421
log.Fatalf("unknown type %q", t)
411422
return ""
@@ -418,7 +429,7 @@ type Object struct {
418429
AdditionalProperties bool `json:"additionalProperties,omitempty"`
419430
Enum []any `json:"enum,omitempty"`
420431
MarkdownEnumDescriptions []string `json:"markdownEnumDescriptions,omitempty"`
421-
Default interface{} `json:"default,omitempty"`
432+
Default any `json:"default,omitempty"`
422433
Scope string `json:"scope,omitempty"`
423434
Properties map[string]*Object `json:"properties,omitempty"`
424435
DeprecationMessage string `json:"deprecationMessage,omitempty"`

extension/tools/goplssetting/goplssetting_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ func TestWriteAsVSCodeSettings(t *testing.T) {
159159
},
160160
},
161161
},
162+
{
163+
name: "int64",
164+
in: &Option{
165+
Name: "maxFileCacheBytes",
166+
Type: "int64",
167+
Default: "0",
168+
},
169+
want: map[string]*Object{
170+
"maxFileCacheBytes": {
171+
Type: "number",
172+
Default: int64(0),
173+
Scope: "resource",
174+
},
175+
},
176+
},
162177
}
163178

164179
for _, tc := range testCases {

0 commit comments

Comments
 (0)