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

YAML comments support #410

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open

YAML comments support #410

wants to merge 18 commits into from

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.

Comment on lines 268 to +272
protected void loadInternal(final CommentedConfigurationNode node, final BufferedReader reader) {
node.raw(this.yaml.get().load(reader));
// the constructor needs ConfigurationOptions for the to be created nodes
// and since it's a thread-local, this won't cause any issues
this.constructor.get().options = node.options();
node.from(this.yaml.get().load(reader));
Copy link

Choose a reason for hiding this comment

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

There is a regression here: load returns null when the file is empty, which ConfigurationNode#from can't receive.

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.

6 participants