I am interested in refining the code that aligns the various parts of struct fields.
Currently the alignments are wonky and difficult to read if a contiguous list of fields include a mix of identified and anonymous fields, tags, and comments.
For example (ugliest example I could make): Actual.png (attached)
Normally I define and group fields more carefully and the formatting is nice, but there are cases where it is natural to include anonymous, tagged, and commented fields contiguous with others, and situations where I think contiguous alignment per part (names/embedded, types for named field, tags, and then comments) would be better.
Here's what I have in mind: Concept.png (attached)
To do this would require something akin to computing the positions of the types for named fields in a contiguous section (until a line that doesn't define a field), aligning those to the rightmost, and then repeating for tags, and then for comments. If there is only one type, tag, or comment in a contiguous section, then that part can float as far left as possible, as it already does. At minimum this will require changes to printer.fieldList in src/pkg/go/printer/nodes.go
There are a few ambiguous cases that would have to be identified precisely. For example, currently the formatter aligns the first parts, the second parts, and so on, resetting alignment where an intermediate line doesn't have the same number of parts: Ambig.png (attached)
The changes I would like to investigate would align the parts per kind, rather than per number, and (possibly, to be decided) would align all the parts of the same kind within a contiguous list of fields until a blank line or comment rather than resetting at a line not including the same kind of part.
The only downside that comes to mind is that if this kind of change were merged, the next release would mean reformatted code all across the board.
At this point I am looking for feedback on whether these refinements would be welcomed.
- Matt