Skip to content

Conversation

@Tim203
Copy link

@Tim203 Tim203 commented Jun 22, 2023

This adds support for YAML comments.
Let me know if you want to see changes.

@Tim203 Tim203 changed the title Added support for YAML comments YAML comments support Jun 22, 2023
@zml2008
Copy link
Member

zml2008 commented Jun 24, 2023

Thanks for this contribution! I would love to have full support for reading comments back from configuration files, but I think this could be a decent stopgap until that work is complete.

@Tim203
Copy link
Author

Tim203 commented Jun 24, 2023

I wasn't aware that comments are also supposed to be read back.
After quite a bit of digging I've added support for that in the latest commit.

I might change the way the comments are read back for map keys a bit, but the general concept is there.

Edit: made the changes

@SpongePowered SpongePowered deleted a comment from NichtStudioCode Jul 21, 2023
@kyngs
Copy link

kyngs commented Jul 27, 2023

Any update on this?

@zml2008
Copy link
Member

zml2008 commented Jul 27, 2023

no

@kyngs
Copy link

kyngs commented Jul 27, 2023

no

Sorry, should've asked differently: "What's stopping this from getting merged?"

@zml2008
Copy link
Member

zml2008 commented Jul 27, 2023

time

@Skyslycer

This comment was marked as spam.

@SpongePowered SpongePowered locked as spam and limited conversation to collaborators Aug 24, 2023
@zml2008 zml2008 added this to the 4.2.0 milestone Aug 28, 2023
@SpongePowered SpongePowered unlocked this conversation Oct 15, 2023
@Override
protected Object constructObjectNoCheck(final Node yamlNode) {
//noinspection DataFlowIssue guarenteed NonNull by getSingleData, which load(Reader) uses
final CommentedConfigurationNode node = CommentedConfigurationNode.root(this.options);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not a fan of the fact that by creating a new root node here, we effectively construct two nodes per node when loading in a file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're then mainly talking about the mapping part right? When looking at the differences between a root node and a .node node it looks like only the path and parent differs.
We could add a method that works essentially like attachIfNecessary / parentEnsureAttached, but allows you to set the parent & path as well.

@zml2008 zml2008 mentioned this pull request Jan 11, 2024
@Reddishye

This comment was marked as spam.

@zml2008 zml2008 modified the milestones: 4.2.0, 4.3.0 Feb 24, 2025
@OGBlackDiamond

This comment has been minimized.

@szymon-off
Copy link

Is it currently possible to disable a new line being created before every comment? When defining comments using the @ Comment annotation, the generated file has an empty line before the comment itself.

For example:

@ConfigSerializable
public class MainConfig {
    @Comment("Fruit")
    String string = "Apple";
    @Comment("Number")
    int integer = 25 
}

will end up looking like this:

 
# Fruit
string: Apple

# Number
integer: 25

Other than that, this PR appears to be fully functional for my use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants