You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The formatting seems stable, but some of those are over 120 characters line, and I can't reason intelligently about the line break choices that the program has made. Why does it join some lines that are almost identical, but then leave others all alone?
The text was updated successfully, but these errors were encountered:
dfmt has a few different formatting procedures for long lines of things. I don't know what the top unittest code is supposed to be though, T x = { a = "foo", b = "bar" } doesn't seem to be any valid syntax (struct initializers use : like the bottom code)
In the unittest at the bottom it looks like valid struct initializer syntax. I'm not sure what special cases there were, but if it's the same as with associative arrays, the code parser first analyzes the whole tree, stores at which locations with [ (or here {) AAs were defined and in the formatter when it's at a [ token it checks that lookup table to see what exactly is following now. Depending on that it selects a formatter.
The long line splitting there works by testing in full if the whole current AST node (the full array) fits in one line, in which case it's formatted like so, but could still get wrapped because of weird edge cases or because in the middle it decided there is enough space to put more tokens in one line after all, after wrapping a line. It's kind of a mess I think, we should more consistently use full AST formatting e.g. to keep keys and values together, to consistently wrap all items inside an array or struct initializer, etc. (just need to make sure they don't oscillate back and forth on every format)
Best explanation is by demonstration:
Here's the input:
Running with stock dfmt (no .editorconfig file, bultin defaults), here's the result:
The formatting seems stable, but some of those are over 120 characters line, and I can't reason intelligently about the line break choices that the program has made. Why does it join some lines that are almost identical, but then leave others all alone?
The text was updated successfully, but these errors were encountered: