night-config icon indicating copy to clipboard operation
night-config copied to clipboard

Add Comments to Yaml

Open Articdive opened this issue 5 years ago • 9 comments

I'm aware of SnakeYaml not supporting comments during the parse, however since you have your own yaml writer you can definitely support outputting comments, you would just need to bridge the YamlCommentedConfiguration's comment Map to your Writer and then when writing line for line, check if it's a node, if it is a node, add said comment for said node. Obviously you also need to calculate things such as Whitespace e.t.c and it wouldn't be the easiest solution, but it would allow for Comment output on Yaml

Articdive avatar Mar 24 '19 07:03 Articdive

A proof of concept would be here in the save() method.

Articdive avatar Mar 24 '19 07:03 Articdive

Actually my "yaml writer" only exists to unwrap Config to Map<String, Object>. It then gives everything to snakeyaml, which does the real writing.

Supporting comments in yaml would indeed be very nice, both in reading and writing. However that would require more work and isn't a top priority, I'll add it to the backlog.

TheElectronWill avatar Mar 24 '19 08:03 TheElectronWill

I created my own custom implementation of this, if you are interested I can also PR it, however It's not the most efficient code and I'm nearly positive it can be improved.

Articdive avatar Mar 24 '19 20:03 Articdive

Yep I'm interested. I would have liked to be able to read and write comments in order to preserve the configs but just writing comments is better than nothing :smiley:

TheElectronWill avatar Mar 26 '19 19:03 TheElectronWill

Yep I'm interested. I would have liked to be able to read and write comments in order to preserve the configs but just writing comments is better than nothing 😃

https://github.com/Articdive/EnumToConfiguration/tree/master/src/main/java/de/articdive/enum_to_configuration/yaml

Articdive avatar Mar 27 '19 11:03 Articdive

Is this still being considered?

ArcheCraft avatar Nov 09 '21 19:11 ArcheCraft

It is, but it won't be ready before several months because it requires some work. I know the snakeyaml's limitation is problematic.

TheElectronWill avatar Nov 10 '21 12:11 TheElectronWill

Any updates on this?

maurxce avatar Jul 04 '23 06:07 maurxce

Not yet, I would have to write a new yaml parser :sweat_smile:

TheElectronWill avatar Jul 06 '23 07:07 TheElectronWill