-
Notifications
You must be signed in to change notification settings - Fork 149
Support generation of YAML with comments #181
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
base: master
Are you sure you want to change the base?
Conversation
|
||
#[derive(Clone, PartialEq, PartialOrd, Debug, Eq, Ord, Hash)] | ||
pub struct Comments { | ||
/// A before comment is a vector of strinsg representing the text from full |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// A before comment is a vector of strinsg representing the text from full | |
/// A before comment is a vector of strings representing the text from full |
@@ -44,6 +53,8 @@ pub enum Yaml { | |||
Hash(self::Hash), | |||
/// Alias, not fully supported yet. | |||
Alias(usize), | |||
/// Yaml node with block or line comments | |||
CommentedYaml(self::CommentedYaml), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is a breaking change, so I guess, it'll require bumping minor version (0.4.5 to 0.5.0), maybe? But I'm not the maintainer :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a breaking change, it might also potentially be worth adding non_exhaustic to the enum, so in the future, changes like this won't be breaking.
#[derive(Clone, PartialEq, PartialOrd, Debug, Eq, Ord, Hash)] | ||
pub struct CommentedYaml(pub Box<Yaml>, pub Comments); | ||
|
||
#[derive(Clone, PartialEq, PartialOrd, Debug, Eq, Ord, Hash)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#[derive(Clone, PartialEq, PartialOrd, Debug, Eq, Ord, Hash)] | |
#[derive(Clone, PartialEq, PartialOrd, Debug, Eq, Ord, Hash, Default)] |
It would be nice to have a default implementation given there are so many fields.
@jrandall Did you look into it? |
Address half of #146 by adding support to generate YAML with comments. Parsing YAML with comments into the internal form (and making round-tripping possible) would be the next step, but we had an immediate need on the generation side so we went ahead and implemented that, and hope that it might be useful to others as well.
Because we don't have a parser yet, the tests for comment generation are somewhat verbose (involving literal expected values). Once the parser is implemented, these tests can be replaced by round-trip tests as are used for much of the other functionality.