Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
suzuki-shunsuke opened this issue Dec 4, 2024 · 2 comments
Closed

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

suzuki-shunsuke opened this issue Dec 4, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@suzuki-shunsuke
Copy link
Contributor

suzuki-shunsuke commented Dec 4, 2024

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

  • Go version: [e.g. 1.21 ] 1.23
  • go-yaml's Version: [e.g. v1.11.1 ] 1.15.6

Additional context
Add any other context about the problem here.

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

go-yaml/ast/ast.go

Lines 1473 to 1478 in 5d22eed

// Merge merge sequence value.
func (n *SequenceNode) Merge(target *SequenceNode) {
column := n.Start.Position.Column - target.Start.Position.Column
target.AddColumn(column)
n.Values = append(n.Values, target.Values...)
}

✅ I'll create a pull request to resolve this issue. #570

@suzuki-shunsuke
Copy link
Contributor Author

@goccy
Copy link
Owner

goccy commented Dec 5, 2024

This problem has already been fixed with v1.15.7.

@goccy goccy closed this as completed Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants