tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

non-diff-friendly behavior with `$` #593

Open sellout opened 4 years ago

sellout commented 4 years ago

Describe the bug The positioning of $ changes depending other line breaks in the expression.

To Reproduce

shortExpr $
  otherExpr

Now add a composition before the application:

shortExpr . composedExpr $
  otherExpr

So far, so good, but if composedExpr makes the line too long, I break it:

shortExpr
  . composedExpr $
  otherExpr

Then Ormolu reformats it like

shortExpr
  . composedExpr
  $ otherExpr

changing the otherExpr line, which was previously diff-clean. This seems to go against the diff-friendliness of Ormolu. Also, AFAICT, it's special handling of $ -- other operators seem to always be after a line break, but I'm not sure if that's true or if there's a subtle distinction I'm missing.

Expected behavior Probably, I expect the first expression above to be formatted

shortExpr
  $ otherExpr

keeping the second line stable no matter how long the expression before it gets. In fact, this formatting keeps both the shortExpr and otherExpr line clean, and the current behavior makes them both dirty.

Environment

Additional context

neongreen commented 3 years ago

This got worse recently, with every added foo $ in the pipeline shifting the subsequent expression block by two chars.

foo =
  x $
    y $ do
      a
      b
dpwiz commented 3 years ago

This got worse recently

The example may look ugly with single-letter names, but IMO that's on single-letter names.

reasonably =
  namedWrapper $
    doingSomeStuff $ do
      this
      that
neongreen commented 3 years ago

Sure. The problem is that I can't choose whether I want namedWrapper $ doingSomeStuff $ do to be on one line or two lines. I have to replace $ with ..

neongreen commented 3 years ago

No wait, nevermind, that's an unrelated problem.