Split a long property array into multiple lines.#48
Open
gnoliyil wants to merge 1 commit into
Open
Conversation
Previously, a property array was always formatted into a single line regardless of its length. For a property with a lot of elements, this made it very difficult to read. This change adds a way to determine whether the Printer should split a long property array into multiple lines: If the property contains more than 120 bytes, then we always add a new line after the comma separator. A long array like ``` reg = <0x00 0x1000 0x01 0x02>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>; ``` will be formatted to ``` reg = <0x00 0x1000 0x01 0x02>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>, <0x01 0x1100 0x02 0x03>; ``` Test: added properties.txt Bug: mskelton#47
mskelton
reviewed
Mar 11, 2026
| pub keymap: bool, | ||
| pub bindings: bool, | ||
|
|
||
| // True iff a new line should be added after comma separated elements, |
Owner
There was a problem hiding this comment.
Suggested change
| // True iff a new line should be added after comma separated elements, | |
| // True if a new line should be added after comma separated elements, |
mskelton
reviewed
Mar 11, 2026
Comment on lines
+217
to
+221
| const NODE_BYTE_SIZE_THRESHOLD_TO_SPLIT_LINES: usize = 120; | ||
| let node_bytes = node.end_byte() - node.start_byte(); | ||
| let ctx = ctx.new_line_after_comma( | ||
| node_bytes > NODE_BYTE_SIZE_THRESHOLD_TO_SPLIT_LINES, | ||
| ); |
Owner
There was a problem hiding this comment.
Seems like this current method would change how it formats based on the input text, which is against the core principle of how dtsfmt works
Collaborator
|
I had a change in process to do similar and what I did here was tie the wrapping to the closest #address-cells and #size-cells found in node parents. I think it generally fits well with what the formatter does elsewhere, doesn't potentially require a configuration knob for the size, and better visualizes each reg. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously, a property array was always formatted into a single line regardless of its length. For a property with a lot of elements, this made it very difficult to read.
This change adds a way to determine whether the Printer should split a long property array into multiple lines: If the property contains more than 120 bytes, then we always add a new line after the comma separator.
A long array like
will be formatted to
Test: added properties.txt
Bug: #47