tweag / ormolu

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

Format selection containing `->` #1099

Closed emlautarom1 closed 4 months ago

emlautarom1 commented 4 months ago

Describe the bug Ormolu is unable to format a selection when it contains a -> symbol (ex. case expressions)

To Reproduce

  1. Create a Haskell file with the following code
    x = case () of
    () ->     ()
  2. Select the () -> () line
  3. Use the Format Selection command

Expected behavior The code should be formatted to () -> () (removes the additional spaces between -> and ())

Environment

Additional context Originally, I thought that this problem was with HLS (see: https://github.com/haskell/haskell-language-server/issues/4074) but I was able to narrow it down to Ormolu. The original use case is to format only modified lines, which sometimes can be patterns in case expressions.

amesgen commented 4 months ago

Thanks for the report! Region formatting only works when the selection is still parseable Haskell code on its own, as Ormolu relies on the GHC parser. Hence, we currently don't support your use case.

We could mention this in the corresponding README paragraph.