-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
v3: preserve comments lines and indents after unmarshal -> marshal #709
Comments
Removed the function that was adding the comments to the last key from the map and replaced that with the separate comments queue. Unfold that comment queue each time we get the end of a flow, a document and a block. Append comments to the end token if their indents are >= than the first comment indent (this is safe as we only add comments to that queue if we detect that their indent is < than the last key indent). Additionally fixed the bug in the emitter, related to skipping foot_comments for the mapping end events. Fixes: go-yaml#709 Signed-off-by: Artem Chernyshev <[email protected]>
Removed the function that was adding the comments to the last key from the map and replaced that with the separate comments queue. Unfold that comment queue each time we get the end of a flow, a document and a block. Append comments to the end token if their indents are >= than the first comment indent (this is safe as we only add comments to that queue if we detect that their indent is < than the last key indent). Additionally fixed the bug in the emitter, related to skipping foot_comments for the mapping end events. Fixes: go-yaml#709 Signed-off-by: Artem Chernyshev <[email protected]>
Removed the function that was adding the comments to the last key from the map and replaced that with the separate comments queue. Unfold that comment queue each time we get the end of a flow, a document and a block. Append comments to the end token if their indents are >= than the first comment indent (this is safe as we only add comments to that queue if we detect that their indent is < than the last key indent). Additionally fixed the bug in the emitter, related to skipping foot_comments for the mapping end events. Fixes: go-yaml#709 Signed-off-by: Artem Chernyshev <[email protected]>
Removed the function that was adding the comments to the last key from the map and replaced that with the separate comments queue. Unfold that comment queue each time we get the end of a flow, a document and a block. Append comments to the end token if their indents are >= than the first comment indent (this is safe as we only add comments to that queue if we detect that their indent is < than the last key indent). Additionally fixed the bug in the emitter, related to skipping foot_comments for the mapping end events. Fixes: go-yaml#709 Signed-off-by: Artem Chernyshev <[email protected]>
Removed the function that was adding the comments to the last key from the map and replaced that with the separate comments queue. Unfold that comment queue each time we get the end of a flow, a document and a block. Append comments to the end token if their indents are >= than the first comment indent (this is safe as we only add comments to that queue if we detect that their indent is < than the last key indent). Additionally fixed the bug in the emitter, related to skipping foot_comments for the mapping end events. Fixes: go-yaml#709 Signed-off-by: Artem Chernyshev <[email protected]>
On a first sight this seems to be a bug. It should remain as a foot comment of the key, otherwise it'll keep walking down the hierarchy on future encode/decode cycles. I'll have a look at this on the next update. Thanks for the report. |
@niemeyer how big of a lift is it to fix this bug? I also have seen this issue. |
Is there any update about this issue? I am facing a similar problem. Original file content:
After after unmarshal -> marshal:
|
I wonder if it is possible to preserve the same positions for all decoded comments, when you unmarshal into
yaml.Node
and then marshal thatyaml.Node
back to yaml.So for example:
Turns into:
Where foot comment changes it's indent and becomes foot comment of key2 (?).
Here's the code snippet:
https://play.golang.org/p/BtzerXV8ofI
It looks like the comment is attached to the last element in the map, instead of attaching it to the map.
Do you think it's a bug in the library? Or that's intended behavior? Is there any workaround for that?
The text was updated successfully, but these errors were encountered: