ormolu icon indicating copy to clipboard operation
ormolu copied to clipboard

Better multiline standalone deriving

Open brandonchinn178 opened this issue 1 year ago • 1 comments

Without DerivingStrategies, it's reasonable to think that "deriving instance" together defines a standalone deriving statement, but with DerivingStrategies, it seems more intuitive for deriving + the strategy to be one unit, and instance + types being another. This makes the styling look just like a normal instance block.

Current

newtype Foo = Foo Int

deriving instance
  Show Foo

deriving via
  (Hex Int)
  instance
    Show Foo

deriving newtype instance
  Show Foo

Desired

newtype Foo = Foo Int

deriving 
  instance Show Foo

deriving newtype
  instance Show Foo

deriving via (Hex Int)
  instance Show Foo

-- if the user explicitly puts it on the next line, perhaps even
-- deriving
--   via (Hex Int)
--   instance Show Foo

Environment

  • OS name + version:
  • Version of the code:

Additional context Related: https://github.com/ghc-proposals/ghc-proposals/pull/446

brandonchinn178 avatar Dec 08 '22 00:12 brandonchinn178

Sounds neat, being anticipatorily forward-compatible with https://github.com/ghc-proposals/ghc-proposals/pull/446 could be sufficient reason to change formatting here (multi-line deriving clauses are also usually pretty self-contained), such that this will be a fixed point:

deriving newtype
  instance Show Foo
  instance Read Foo

deriving via -- or also change the newline insertion here
  (Hex Int)  -- as suggested in your examples
  instance
    Show Foo
    Read Foo

amesgen avatar Dec 08 '22 09:12 amesgen