this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: correctly import comments after a field key

The YAML decoder attached an inline key comment to the label,
rather than to the entire field, which caused the comment to be printed
before the colon character and cause weird formatting.

Then teach cue/format to print an inline comment on a field colon.

Fixes #3214.

Change-Id: I17e669bc6c129dde86478d604a28d07fc63f7b69
Signed-off-by: haoqixu <hq.xu0o0@gmail.com>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1196291
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

authored by

haoqixu and committed by
Daniel Martí
cc7cb90d 859f1f6d

+14 -1
+12
cmd/cue/cmd/testdata/script/import_auto.txtar
··· 1 1 exec cue import -o - ./openapi.yaml 2 2 cmp stdout expect-openapi 3 3 4 + # Issue #3214 5 + exec cue import -o - -f ./import1.yaml 6 + cmp stdout expect-stdout1 7 + 8 + -- import1.yaml -- 9 + a: # inline comment for a 10 + b: "value" # inline comment for b 11 + -- expect-stdout1 -- 12 + a: // inline comment for a 13 + { 14 + b: "value" // inline comment for b 15 + } 4 16 -- expect-openapi -- 5 17 // An OpenAPI file 6 18
+1
cue/format/node.go
··· 314 314 } else { 315 315 f.print(blank, nooverride, n.Token) 316 316 } 317 + f.visitComments(f.current.pos) 317 318 318 319 if mem := f.inlineField(n); mem != nil { 319 320 switch {
+1 -1
internal/encoding/yaml/decode.go
··· 401 401 if err != nil { 402 402 return err 403 403 } 404 - d.addCommentsToNode(label, yk, 1) 404 + d.addCommentsToNode(field, yk, 2) 405 405 field.Label = label 406 406 407 407 if mergeValues {