tweag / ormolu

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

StandaloneKindSignatures: grouping does not work for type synonyms #683

Closed amesgen closed 3 years ago

amesgen commented 3 years ago

With ormolu 0.1.4.1:

type Bla :: Type
type Bla = Int

is transformed into

type Bla :: Type

type Bla = Int

but I would expect it to be a fixed point.

This simply appears to be an oversight in #533.

This diff fixes the issue:

diff --git a/src/Ormolu/Printer/Meat/Declaration.hs b/src/Ormolu/Printer/Meat/Declaration.hs
index dba14d9..5415fe0 100644
--- a/src/Ormolu/Printer/Meat/Declaration.hs
+++ b/src/Ormolu/Printer/Meat/Declaration.hs
@@ -188,6 +188,7 @@ groupedDecls (L l_x x') (L l_y y') =
     (KindSignature n, DataDeclaration n') -> n == n'
     (KindSignature n, ClassDeclaration n') -> n == n'
     (KindSignature n, FamilyDeclaration n') -> n == n'
+    (KindSignature n, TypeSynonym n') -> n == n'
     -- Special case for TH splices, we look at locations
     (Splice, Splice) -> not (separatedByBlank id l_x l_y)
     -- This looks only at Haddocks, normal comments are handled elsewhere
@@ -247,7 +248,8 @@ pattern
   DataDeclaration,
   ClassDeclaration,
   KindSignature,
-  FamilyDeclaration ::
+  FamilyDeclaration,
+  TypeSynonym ::
     RdrName -> HsDecl GhcPs
 pattern InlinePragma n <- SigD NoExtField (InlineSig NoExtField (L _ n) _)
 pattern SpecializePragma n <- SigD NoExtField (SpecSig NoExtField (L _ n) _ _)
@@ -259,6 +261,7 @@ pattern DataDeclaration n <- TyClD NoExtField (DataDecl NoExtField (L _ n) _ _ _
 pattern ClassDeclaration n <- TyClD NoExtField (ClassDecl NoExtField _ (L _ n) _ _ _ _ _ _ _ _)
 pattern KindSignature n <- KindSigD NoExtField (StandaloneKindSig NoExtField (L _ n) _)
 pattern FamilyDeclaration n <- TyClD NoExtField (FamDecl NoExtField (FamilyDecl NoExtField _ (L _ n) _ _ _ _))
+pattern TypeSynonym n <- TyClD NoExtField (SynDecl NoExtField (L _ n) _ _ _)

 -- Declarations which can refer to multiple names

Can create a PR if desired.

mrkkrp commented 3 years ago

@amesgen Please go ahead with the PR!