tweag / ormolu

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

Extra indentation for hanging `\case` statements with `(&)` #1107

Open ocharles opened 2 months ago

ocharles commented 2 months ago

Is your feature request related to a problem? Please describe.

I have the following code:

{-# language TemplateHaskell #-}

foo = 
  runBlah
    & handeError @Foo \case
        X -> Y
        A -> B
    & handeError @Bar \case
        U -> V

Currently Ormolu formats this as:

{-# LANGUAGE TemplateHaskell #-}

foo =
  runBlah
    & handeError @Foo \case
      X -> Y
      A -> B
    & handeError @Bar \case
      U -> V

I consider this suboptimal, and the lost indentation makes this hard to read.

Describe the solution you'd like

Ormolu indents each case:

{-# LANGUAGE TemplateHaskell #-}

foo =
  runBlah
    & handeError @Foo \case
        X -> Y
        A -> B
    & handeError @Bar \case
        U -> V
ocharles commented 2 months ago

I've also noticed

{-# language TemplateHaskell #-}

foo = 
  runBlah
    & fmap \foo ->
        bar

becomes

{-# LANGUAGE TemplateHaskell #-}

foo =
  runBlah
    & fmap \foo ->
      bar

which is a similar problem, so maybe this is more about (&) in general