Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve blank lines between case branches #902

Open
ocharles opened this issue Jun 22, 2022 · 1 comment
Open

Preserve blank lines between case branches #902

ocharles opened this issue Jun 22, 2022 · 1 comment
Labels
style Nitpicking and things related to purely visual aspect for formatting.

Comments

@ocharles
Copy link

ocharles commented Jun 22, 2022

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

The following input code

readPackets s requests notifications = forever do
  packet@AMSPacket{payload, commandId} <- readPacket s
  atomically do
    case commandId of
      8 ->
        case Decode.parseOnly parseDeviceNotification payload of
          Left e ->
            throwSTM $ CouldNotParseResponse e
            
          Right deviceNotification ->
            writeTChan notifications deviceNotification

      _ -> do
        maybePacket <-
          stateTVar requests $
            IntMap.updateLookupWithKey (\_ _ -> Nothing) (fromIntegral (invokeId packet))

        case maybePacket of
          Nothing -> throwSTM $ UnexpectedMessage packet
          Just consume -> consume packet

Gets squashed into

readPackets s requests notifications = forever do
  packet@AMSPacket {payload, commandId} <- readPacket s
  atomically do
    case commandId of
      8 ->
        case Decode.parseOnly parseDeviceNotification payload of
          Left e ->
            throwSTM $ CouldNotParseResponse e
          Right deviceNotification ->
            writeTChan notifications deviceNotification
      _ -> do
        maybePacket <-
          stateTVar requests $
            IntMap.updateLookupWithKey (\_ _ -> Nothing) (fromIntegral (invokeId packet))

        case maybePacket of
          Nothing -> throwSTM $ UnexpectedMessage packet
          Just consume -> consume packet

I struggle to follow the flow like this, and would like Ormolu to preserve the blank lines.

Describe the solution you'd like
Ormolu preserves blank lines between case branches.

Describe alternatives you've considered
I could rewrite my code so each branch is a where clause. If I did this, I probably wouldn't need the branches to be separated by blank lines, and blank lines are preserved in where clauses.

@amesgen amesgen added the style Nitpicking and things related to purely visual aspect for formatting. label Jun 25, 2022
@ntc2
Copy link

ntc2 commented Jul 7, 2022

I think this is another variant of #635 and #802. Again, I suggest that Ormolu just preserve groupings in all cases: don't insert blank lines where there were none, and don't remove blank lines where they existed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style Nitpicking and things related to purely visual aspect for formatting.
Projects
None yet
Development

No branches or pull requests

3 participants