goccy / go-yaml

YAML support for the Go language
MIT License
1.2k stars 135 forks source link

ast.Merge() removes comments in a SequenceNode #569

Open suzuki-shunsuke opened 9 hours ago

suzuki-shunsuke commented 9 hours ago

Describe the bug A clear and concise description of what the bug is.

When we merge two SequenceNodes by ast.Merge, comments are removed.

To Reproduce

Please provide a minimum yaml content that can be reproduced. We are more than happy to use Go Playground

https://go.dev/play/p/xTKF9ON8bUd

Expected behavior A clear and concise description of what you expected to happen.

ast.Merge keeps comments.

- foo
# hello
- bar
- zoo
- baz

Screenshots If applicable, add screenshots to help explain your problem.

Version Variables

Additional context Add any other context about the problem here.

I reported the similar issue before. ast.Merge doesn't update ValueHeadComments.

https://github.com/goccy/go-yaml/blob/5d22eed00009e4cd6cf5eaf9848f77c0477d23a8/ast/ast.go#L1473-L1478

✅ I'll create a pull request to resolve this issue. https://github.com/goccy/go-yaml/pull/570

suzuki-shunsuke commented 9 hours ago