Xavalon / XamlStyler

Visual Studio extension to help format your XAML source code
Apache License 2.0
1.17k stars 128 forks source link

"Max attribute characters per line" is not respected even when "Attribute Tolerance"=5 and "Max attributes per line"=8 #450

Open philipag opened 9 months ago

philipag commented 9 months ago

Describe the bug The MACPL setting says that it will work with AT=5 and MAPL=8, but it has no effect. If I set MACPL=20, then the attributes do not wrap regardless of line length. Is MACPL fundamentally broken or am I doing something wrong?

To Reproduce Steps to reproduce the behavior: see above

Expected behavior If I have 5 properties which make a line of 100 characters, I expect them to be split into separate lines such that each line contains either only 1 property or <= 20 characters.

Screenshots image image

External Configuration NA

Version Info (please complete the following information): Version 17.9.0 Preview 1.0, latest XAML Styler

grochocki commented 8 months ago

In this case, AT will take precedence. Until you cross AT threshold, MAPL and MACPL will have no effect.

Notes on MAPL:

Defines the maximum number of attributes an element can have on each line after the start tag if the number of attributes exceeds the Attribute Tolerance.

You can test this by creating an element with more than 5 attributes:

image

We do not support a hard column limit, nor do we believe it makes much sense to do so with a markup language like XAML given the many other supported ways of breaking up attributes across lines (#12).

philipag commented 8 months ago

@grochocki In my particular case with the 4 attributes that I have ( I cannot add a 5th attribute just to cause wrapping), how can I cause formatting to wrap while keeping up to 5 short attributes (on another element) on the same line?

I tried setting AT=2 and MAPL=8 but that seems to always wrap after 2 attributes no matter what...

What would make sense to me is that if MACPL is exceeded, then attributes will be removed from the line until either MACPL is not exceeded or only 1 attribute is left. I set MACPL to my screen width this would avoid having to constantly scroll my view (sometimes really far) in order to see all the attributes. It would at the same time allow me to have several attributes on the same line if they are short.

ylyuanlei0110 commented 8 months ago

In this case, AT will take precedence. Until you cross AT threshold, MAPL and MACPL will have no effect.

Notes on MAPL:

Defines the maximum number of attributes an element can have on each line after the start tag if the number of attributes exceeds the Attribute Tolerance.

You can test this by creating an element with more than 5 attributes:

image

We do not support a hard column limit, nor do we believe it makes much sense to do so with a markup language like XAML given the many other supported ways of breaking up attributes across lines (#12).

image

How can I separate the two attributes in the first line.........

philipag commented 8 months ago

@ylyuanlei0110 Thanks for the clear explanation. Unfortunately this means there is no way to prevent the line from going far past the screen width in my scenario (I don't want to decrease AT since that will mess up other formatting, and I cannot add properties just for the sake of breaking up the super long line). This results in poorly formatted lines when 1 property is very long due to complex bindings with converters and parameters, but there < AT other properties on the same line.

ylyuanlei0110 commented 8 months ago

@ylyuanlei0110 Thanks for the clear explanation. Unfortunately this means there is no way to prevent the line from going far past the screen width in my scenario (I don't want to decrease AT since that will mess up other formatting, and I cannot add properties just for the sake of breaking up the super long line). This results in poorly formatted lines when 1 property is very long due to complex bindings with converters and parameters, but there < AT other properties on the same line.

Yeah, I'm confused for this problem recently. Seems no way to fix it with XamlStyler(⊙︿⊙)