Skip to content

Split a long property array into multiple lines.#48

Open
gnoliyil wants to merge 1 commit into
mskelton:mainfrom
gnoliyil:array
Open

Split a long property array into multiple lines.#48
gnoliyil wants to merge 1 commit into
mskelton:mainfrom
gnoliyil:array

Conversation

@gnoliyil

Copy link
Copy Markdown
Collaborator

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: #47

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
Comment thread src/context.rs
pub keymap: bool,
pub bindings: bool,

// True iff a new line should be added after comma separated elements,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Comment thread src/printer.rs
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,
);

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way we can use lookahead?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@nvll

nvll commented May 7, 2026

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants