Conversation
269c70d to
2edefe2
Compare
2edefe2 to
f46ef18
Compare
|
I rather like this solution; I hadn't thought of focusing on and only solving it for the indentation of a pair's value, but that is indeed the place where it's most relevant. My only concerns here are that I'd like to avoid the need for the So (pretty much thinking out loud here) maybe we want to add an optional |
39d6f93 to
cc85148
Compare
cc85148 to
e844f59
Compare
|
Hey @eemeli, just getting around to this 2 months later, sorry about that. I thought more carefully about your suggestion and I think the ability for people to change indentation however they want prorgrammatically is a pretty compelling reason to extract out the logic a property on There are also weird cases where you might want to graft a Node from a parsed tree where it makes more sense to store indents as relative (rather than the absolute value encoded into the the I landed on adding an It is probably possible to extend this to flow nodes, but would require a bit more work in terms of preserving formatting for the fully general case there since you could have a lot more weird things happen in flow (e.g. 3 elements on each line or something) that cannot happen in block. Also as a fair disclaimer, this was partially written by AI (basically just tests / docs). |
Adds a keepIndentStep parse option that preserves the original indentation between keys and values in block maps. When enabled, each Pair stores its original indentStep string, which stringifyPair uses instead of the context's default.
previous keepIndent option 83326fa
I believe this fixes #283 by adding a
keepIndentoption to toString.I temporarily enabled this
keepIndent+keepSourceTokenon by default and ran all the tests and it seems to work.Alternatively, indent could be an optional property on the AST, which is maybe better in theory but also leads to some odd situations. Another alternative to this implementation might be something more general like
keepSourceFormattingwhere in addition to formatting changes, we would attempt to keep more formatting e.g. in multiline flow text we wouldn't re-fold text if sourceToken exists.This would be really helpful for us at Stainless, as we apply "transforms" to a yaml file, but also need to textually diff the original yaml file against the transformed file to show changes to our users. Spurius diffs make this process really difficult to inspect.
And while I'm at it just want to say thank you for your work on this library, much of my work at Stainles would just not be possible without it. Diffing, transforming, adding comments, etc. to yaml files are a core part of what we do, and we use this library for things like just parsing YAML, analyzing source in our language server, showing great diffs in our transforms product, and so, so many more things.