Support same-column sequence indentation in YAML#7135
Conversation
Adds `indentedSequences` property to `IndentsStyle` to distinguish between indented (` - item`) and same-column (`- item`) sequence styles. Autodetection compares sequence entry indent with parent mapping entry indent to determine the style in use. Fixes #7125
Main added handling for dash-on-own-line (multiline firstIndent) in the lastIndent computation. Resolved by combining both: use dashColumn (which accounts for same-column vs indented style) in the new linebreak/non-linebreak branching from main.
|
no, AFAICS @greg-at-moderne changed the indentation after the hyphen. In a yaml: |
timtebeek
left a comment
There was a problem hiding this comment.
Great to see this properly fixed, thanks!
If I'm not mistaken then any changes to style classes require a coordinated roll out, right?
|
Good to see you watching out. Will make some changes to be safer and only work when it really exists but not crash when not. |
Wrap the new style method call with evaluate() try/catch to handle NoSuchMethodError when parent runtimes haven't updated yet. Defaults to true (indented sequences) which matches pre-existing behavior.
| public class IndentsStyle implements YamlStyle { | ||
| private int indentSize; | ||
| int indentSize; | ||
|
|
||
| boolean indentedSequences; | ||
| } |
There was a problem hiding this comment.
Is there an implied former one arg constructor that we need to make explicit to ease the transition?
There was a problem hiding this comment.
I do not know / fully understand when these are used and when not, but just added them (+ a null supporting one) for safety here
timtebeek
left a comment
There was a problem hiding this comment.
Approved with one more question, just to avoid getting NoSuchMethodError at runtime.
Add deprecated single-arg constructor and @JsonCreator two-arg constructor with @nullable Boolean indentedSequences for coordinated rollout. Old LSTs without the field deserialize with null, which defaults to true (indented style).
Summary
Adds
indentedSequencesboolean toIndentsStyleto distinguish between indented style (- item) and same-column style (- itemat parent key column)Extends
Autodetectto detect which sequence indentation style a document uses by comparing sequence entry indent with parent mapping entry indentUpdates
IndentsVisitorto respect the detected style, placing dashes at the correct column and computinglastIndentso sibling mapping entries align properlyFixes IndentsVisitor does not support same-column sequence indentation style #7125
Test plan
IndentsTesttests pass (no regressions for indented style)SameColumnSequenceIndentnested test class: basic indent correction, preservation of correct indent, nested mappings, multiple entries, mixed-type sequencesAutodetectTest: detects indented style, detects same-column style, defaults to indented when no sequences presentrewrite-yamltest suite passes