Remix.run Logo
frizlab 9 hours ago

This is interesting. I’d very much like to see a code formatter do that kind of thing; currently formatters are pretty much inflexible, which makes getting structure out of a formatted code sometimes hard.

thechao 8 hours ago | parent | next [-]

I just built a C++ formatter that does this (owned by my employee, unfortunately). There's really only two formatting objects: tab-aligned tables, and single line rows. Both objects also support a right-floating column/tab aligned "//" comment.

Both objects desugar to a sequence of segments (lines).

The result is that you can freely mix expression/assignment blocks & statements. Things like switch-case blocks & macro tables are suddenly trivial to format in 2d.

Because comments are handled as right floating, all comments nicely align.

I vibe coded the base layer in an hour. I'm using with autogenerated code, so output is manually coded based on my input. The tricky bit would be "discovering" tables & block. I'd jus use a combo of an LSP and direct observation of sequential statements.

marxisttemp 7 hours ago | parent [-]

You built it, but your employee owns it? That sounds highly unusual.

thechao 4 hours ago | parent | next [-]

Autocorrect — employer. Too late to change, now!

jtbayly 6 hours ago | parent | prev | next [-]

Probably a single-letter typo. Makes complete sense if changed to “employer.”

pona-a 6 hours ago | parent | prev [-]

Auto corrected employer?

barishnamazov 9 hours ago | parent | prev [-]

Right. In my previous work, I wrote a custom XML formatter for making it look table-like which was our use case. Of course, an ideal solution would have been to move away from XML, but can't run away from legacy.