Formatter alignment - unsure about tutorial explanation
Hello,
I'm strugling with understanding tutorial for language plugin of Formatter's alignment/wrap.
I understand, that elements sharing the same alignment instance do align, what I don't understand is "and if the second block is the first non-whitespace block in its line".
var a = 1;
var aa = 1;
With simple example like this, how I should build blocks, since equal sign have to be aligned, but in order to have "=" as first non-whitespace block, I can't split given rows into multiple blocks - how should I set alignment for it?
The same goes for Wrapping - I assume that wrap should be specified in an expression so for example:
var a = "asd asd asd" + "asd asd asd" + "asd asd asd" + "asd asd asd"
Wrapping could be could be set on "+" sign, so it would result f.e.?
var a = "asd asd asd" + "asd asd asd"
+ "asd asd asd" + "asd asd asd"
Can it also be defined that Wrap happens always, once the whole expression is on 2 or more lines, instead of just after reaching right margin, so it would then result into something like this?
var a = "asd asd asd"
+ "asd asd asd"
+ "asd asd asd"
+ "asd asd asd"
Please sign in to leave a comment.
EDIT:
If I may, I'd like to extend the question, how does it fit with Spacing.
Do I understand correctly, that Aligment has to fit within it?
As example above, spacing around "=" sign should then be something like?
And if there were max spaces something like:
Then it could result into something like:
Can't figure it out yet.
Hi, little reminder if there is anyone who might help me with this?
No, spacing is appied only for the cases when alignment is not applicable.
Thank you, can you fill me on the rest as well please?
For some reason, everytime I try to implement alignment it always results the same way as in screen above.
Both equal signs have the same Align ID, are set to left and yet, it does not align at all.
I also still can't understand the statement about the element having to be the first non-whitespace block on the line as those eq signs will never actually be first on the line. Or are those results not done via default formatters at all?
There are two basic types of alignments which you already use according to the screenshot above. A regular one (no backward shift) requires that the element is the first non-whitespace element on the line, the backward shift-enabled alignment works for inline elements. It's hard to tell what's going on without looking at the actual code but at first glance it seems there are too many different alignments which probably are not needed. This may cause the alignment mechanism work wierdly sometimes. For example, you have two nested blocks which basically cover the same region but both having different alignments while the actual alignment is needed only for the `=` sign.
Thank you, I haven't even realized, that Alignment should be null apart from those specific tokens like assigments.