@@ -1,6 +1,7 @@
1{-# LANGUAGE LambdaCase #-}
1{-# LANGUAGE LambdaCase #-}
2{-# LANGUAGE PatternSynonyms #-}
2{-# LANGUAGE PatternSynonyms #-}
3{-# LANGUAGE RecordWildCards #-}
3{-# LANGUAGE RecordWildCards #-}
4+{-# LANGUAGE ViewPatterns #-}
5-- | Rendering of declarations.
6-- | Rendering of declarations.
@@ -29,23 +30,24 @@ import Ormolu.Printer.Meat.Declaration.Value
29import Ormolu.Printer.Meat.Type
30import Ormolu.Printer.Meat.Type
30import Ormolu.Utils
31import Ormolu.Utils
32−p_hsDecls :: [LHsDecl GhcPs] -> R ()
33+p_hsDecls :: FamilyStyle -> [LHsDecl GhcPs] -> R ()
33−p_hsDecls decls =
34+p_hsDecls style decls =
34− forM_ (zip decls ((Just <$> drop 1 decls) ++ [Nothing])) $
35+ forM_ (zip decls ((Just <$> drop 1 decls) ++ [Nothing])) $ \(d, md) ->
36− case md of
36+ case md of
37− Nothing -> located d p_hsDecl
37+ Nothing -> located d pDecl
38− Just d' ->
38+ Just d' ->
39− if separatedDecls (unLoc d) (unLoc d')
39+ if separatedDecls (unLoc d) (unLoc d')
40− then line (located d p_hsDecl)
40+ then line (located d pDecl)
41− else located d p_hsDecl
41+ else located d pDecl
43+ pDecl = p_hsDecl style
43−p_hsDecl :: HsDecl GhcPs -> R ()
45+p_hsDecl :: FamilyStyle -> HsDecl GhcPs -> R ()
44−p_hsDecl = \case
46+p_hsDecl style = \case
45− TyClD NoExt x -> p_tyClDecl x
47+ TyClD NoExt x -> p_tyClDecl style x
46 ValD NoExt x -> p_valDecl x
48 ValD NoExt x -> p_valDecl x
47 SigD NoExt x -> p_sigDecl x
49 SigD NoExt x -> p_sigDecl x
48− InstD NoExt x -> p_instDecl x
50+ InstD NoExt x -> p_instDecl style x
49 DerivD NoExt x -> p_derivDecl x
51 DerivD NoExt x -> p_derivDecl x
50 DefD NoExt x -> p_defaultDecl x
52 DefD NoExt x -> p_defaultDecl x
51 ForD NoExt x -> p_foreignDecl x
53 ForD NoExt x -> p_foreignDecl x
@@ -57,9 +59,9 @@ p_hsDecl = \case
57 RoleAnnotD NoExt x -> p_roleAnnot x
59 RoleAnnotD NoExt x -> p_roleAnnot x
58 XHsDecl _ -> notImplemented "XHsDecl"
60 XHsDecl _ -> notImplemented "XHsDecl"
60−p_tyClDecl :: TyClDecl GhcPs -> R ()
62+p_tyClDecl :: FamilyStyle -> TyClDecl GhcPs -> R ()
61−p_tyClDecl = \case
63+p_tyClDecl style = \case
62− FamDecl NoExt x -> p_famDecl Free x
64+ FamDecl NoExt x -> p_famDecl style x
63 SynDecl {..} -> p_synDecl tcdLName tcdTyVars tcdRhs
65 SynDecl {..} -> p_synDecl tcdLName tcdTyVars tcdRhs
64 DataDecl {..} ->
66 DataDecl {..} ->
65 p_dataDecl Associated tcdLName (tyVarsToTypes tcdTyVars) tcdDataDefn
67 p_dataDecl Associated tcdLName (tyVarsToTypes tcdTyVars) tcdDataDefn
@@ -76,11 +78,11 @@ p_tyClDecl = \case
77 XTyClDecl {} -> notImplemented "XTyClDecl"
79 XTyClDecl {} -> notImplemented "XTyClDecl"
79−p_instDecl :: InstDecl GhcPs -> R ()
81+p_instDecl :: FamilyStyle -> InstDecl GhcPs -> R ()
80−p_instDecl = \case
82+p_instDecl style = \case
81 ClsInstD NoExt x -> p_clsInstDecl x
83 ClsInstD NoExt x -> p_clsInstDecl x
82− TyFamInstD NoExt x -> p_tyFamInstDecl Free x
84+ TyFamInstD NoExt x -> p_tyFamInstDecl style x
83− DataFamInstD NoExt x -> p_dataFamInstDecl Free x
85+ DataFamInstD NoExt x -> p_dataFamInstDecl style x
84 XInstDecl _ -> notImplemented "XInstDecl"
86 XInstDecl _ -> notImplemented "XInstDecl"
86p_derivDecl :: DerivDecl GhcPs -> R ()
88p_derivDecl :: DerivDecl GhcPs -> R ()
@@ -114,8 +116,13 @@ pattern TypeSignature
114 , InlinePragma
116 , InlinePragma
115 , SpecializePragma
117 , SpecializePragma
116 , SCCPragma :: RdrName -> HsDecl GhcPs
118 , SCCPragma :: RdrName -> HsDecl GhcPs
117−pattern TypeSignature n <- SigD NoExt (TypeSig NoExt ((L _ n):_) _)
119+pattern TypeSignature n <- (sigRdrName -> Just n)
118pattern FunctionBody n <- ValD NoExt (FunBind NoExt (L _ n) _ _ _)
120pattern FunctionBody n <- ValD NoExt (FunBind NoExt (L _ n) _ _ _)
119pattern InlinePragma n <- SigD NoExt (InlineSig NoExt (L _ n) _)
121pattern InlinePragma n <- SigD NoExt (InlineSig NoExt (L _ n) _)
120pattern SpecializePragma n <- SigD NoExt (SpecSig NoExt (L _ n) _ _)
122pattern SpecializePragma n <- SigD NoExt (SpecSig NoExt (L _ n) _ _)
121pattern SCCPragma n <- SigD NoExt (SCCFunSig NoExt _ (L _ n) _)
123pattern SCCPragma n <- SigD NoExt (SCCFunSig NoExt _ (L _ n) _)
125+sigRdrName :: HsDecl GhcPs -> Maybe RdrName
126+sigRdrName (SigD NoExt (TypeSig NoExt ((L _ n):_) _)) = Just n
127+sigRdrName (SigD NoExt (ClassOpSig NoExt _ ((L _ n):_) _)) = Just n
128+sigRdrName _ = Nothing