redhat-developer / vscode-xml

Editing XML in Visual Studio Code made easy
Eclipse Public License 2.0
262 stars 82 forks source link

Formatter breaks hexBinary by inserting newline and spaces #1010

Open netmikey opened 5 months ago

netmikey commented 5 months ago

When we have an element containing long hexBinary data like this:

  <atr>6f1087c8105312e302e30820408a00005001588306312e3021000000a5049f1c611a4d02156501ff</atr>

The formatter modifies it to become:

  <atr>
    6f1087c8105312e302e30820408a00005001588306312e3021000000a5049f1c611a4d02156501ff</atr>

This however causes trouble down the line. Furthermore there's ultimately no real added benefit for breaking here since the resulting line cannot be further broken down and still doesn't fit into the maximum line length.

I didn't find an option to not break long single-word element content. I think such a configuration option should be considered and maybe even enabled by default.

angelozerr commented 5 months ago

Have you tried to set to 0 (see doc at https://github.com/redhat-developer/vscode-xml/blob/main/docs/Formatting.md#xmlformatmaxlinewidth)

netmikey commented 5 months ago

I've seen this setting and I'm confident it could be a workaround.

However, as far as I understand, this would also prevent all other content, like elements with regular, non-binary text content, to be formatted to fit the screen. Furthermore, the thought behind this report was more to have the formatter behave in a clever but conservative way by default so as to not cause trouble in its default configuration. I'd rather not rely on each developer editing XML files (probably on the fly without a dedicated workspace set up) that contain hexBinary elements to first go through the formatter configuration.

angelozerr commented 5 months ago

You mean that you would like:

If it that I don't know how to do that,in XML Document long hexBinary data or text is considered as Text node.

netmikey commented 5 months ago

I understand. Would it be an option to try detecting "long hexBinary lines (something along the lines of [0-9a-fA-F]{50,})" and changing the formatter's bahavior accordingly?

angelozerr commented 5 months ago

No there is no option for this usecase.

Do you know an xml formatter which does that?

netmikey commented 5 months ago

We've checked a couple of other XML formatters in this regard:

Inserting whitespace characters into hexBinary values like this by default caused us quite some trouble(shooting), so I thought it'd be nice if vscode-xml behaved better than other formatters by default, and since there are quite reliable ways to make it better I thought I'd give it a shot and open an issue.