diff --git a/zcl/json/structure.go b/zcl/json/structure.go index 2e1002b..25b3734 100644 --- a/zcl/json/structure.go +++ b/zcl/json/structure.go @@ -52,6 +52,12 @@ func (b *body) Content(schema *zcl.BodySchema) (*zcl.BodyContent, zcl.Diagnostic } for k, attr := range b.obj.Attrs { + if k == "//" { + // Ignore "//" keys in objects representing bodies, to allow + // their use as comments. + continue + } + if _, ok := hiddenAttrs[k]; !ok { var fixItHint string suggestion := nameSuggestion(k, nameSuggestions) @@ -140,6 +146,12 @@ func (b *body) PartialContent(schema *zcl.BodySchema) (*zcl.BodyContent, zcl.Bod func (b *body) JustAttributes() (zcl.Attributes, zcl.Diagnostics) { attrs := make(map[string]*zcl.Attribute) for name, jsonAttr := range b.obj.Attrs { + if name == "//" { + // Ignore "//" keys in objects representing bodies, to allow + // their use as comments. + continue + } + if _, hidden := b.hiddenAttrs[name]; hidden { continue } diff --git a/zcl/json/structure_test.go b/zcl/json/structure_test.go index a78a0f3..72031d2 100644 --- a/zcl/json/structure_test.go +++ b/zcl/json/structure_test.go @@ -29,6 +29,19 @@ func TestBodyPartialContent(t *testing.T) { }, 0, }, + { + `{"//": "comment that should be ignored"}`, + &zcl.BodySchema{}, + &zcl.BodyContent{ + Attributes: map[string]*zcl.Attribute{}, + MissingItemRange: zcl.Range{ + Filename: "test.json", + Start: zcl.Pos{Line: 1, Column: 40, Byte: 39}, + End: zcl.Pos{Line: 1, Column: 41, Byte: 40}, + }, + }, + 0, + }, { `{"name":"Ermintrude"}`, &zcl.BodySchema{ @@ -618,6 +631,11 @@ func TestBodyContent(t *testing.T) { &zcl.BodySchema{}, 1, }, + { + `{"//": "comment that should be ignored"}`, + &zcl.BodySchema{}, + 0, + }, { `{"unknow": true}`, &zcl.BodySchema{ @@ -698,6 +716,10 @@ func TestJustAttributes(t *testing.T) { }, }, }, + { + `{"//": "comment that should be ignored"}`, + map[string]*zcl.Attribute{}, + }, } for i, test := range tests {