tweag / topiary

https://topiary.tweag.io/
MIT License
511 stars 17 forks source link

Investigate viability of long-line wrapping #700

Open Xophmeister opened 3 months ago

Xophmeister commented 3 months ago

This has been mentioned a few times. For example:

  1. There doesn't seem to be a way to have something for max line width. Perhaps leveraging the softline captures to tell the formatter that it's ok to wrap long lines of code across multiple lines without requiring the developer to multiline first?

That's right; Topiary has no concept of line-length and using that as a constraint to force reflowing, like other formatters do. I'm not sure if this is "by design" or "by accident", but the general nature of Topiary means that it's not obvious how to wrap long lines in all cases.

Originally posted in https://github.com/tweag/topiary/pull/699#pullrequestreview-1988678032

Per the comment, Topiary currently doesn't do anything with long-lines. It would be worth investigating whether anything suitably general can be done (e.g., forcing multiline mode at a certain column, etc.).

aspiwack commented 3 months ago

The difficulty is that as soon as you deal with long lines, then you have an optimisation problem to solve.

If you decide, for instance, that all the forms that cross the maximum column are considered multiline, you'll often make a lot of very short lines. So you need a more complex strategy. It's kind of tricky, this is where pretty printing libraries come in handy. I don't have a clear idea how such pretty printers and our current output strategy would meld.

But it is definitely a feature that some people want.