on master help sign in
Insert newlines after annotations in certain cases

Just like other pragmas annotations will now “stick” to the definitions they pertain to. If it's not possible, there will be a newline separating them from other declarations in the module.

commit057977d60cde0c20b329ab280c4e6a595e9b1ec1 authormrkkrp <mark.karpov@tweag.io> dateFri 28 Jun 2019, 21:28 (7 years ago) parentba64967
4 files changed+23−5
data/examples/declaration/annotation/annotation-out.hs+9−1 data/examples/declaration/annotation/annotation.hs+6−2 src/Ormolu/Printer/Meat/Declaration.hs+7−1 src/Ormolu/Printer/Meat/Declaration/Annotation.hs+1−1
data/examples/declaration/annotation/annotation-out.hs+9−1
@@ -1,12 +1,20 @@
11{-# ANN module (5 :: Int) #-}
2+
23{-# ANN
34 module
45 ( 5
56 :: Int
67 )
78 #-}
9+
810{-# ANN foo "hey" #-}
11+foo :: Int
12+foo = 5
13+
914{-# ANN
1015 Char
1116 (Just 42)
12− #-}{- Comment -}
17+ #-}
18+
19+data Foo = Foo Int
20+{- Comment -}
data/examples/declaration/annotation/annotation.hs+6−2
@@ -5,10 +5,14 @@
55
66{-# ANN foo "hey" #-}
77
8−{-# ANN
9− Char
8+foo :: Int
9+foo = 5
1010
11+{-# ANN
12+ Char
1113
1214 (Just 42)#-}
1315
16+data Foo = Foo Int
17+
1418{- Comment -}
src/Ormolu/Printer/Meat/Declaration.hs+7−1
@@ -110,18 +110,24 @@ isPragma = \case
110110 InlinePragma n -> Just n
111111 SpecializePragma n -> Just n
112112 SCCPragma n -> Just n
113+ AnnTypePragma n -> Just n
114+ AnnValuePragma n -> Just n
113115 _ -> Nothing
114116
115117pattern TypeSignature
116118 , FunctionBody
117119 , InlinePragma
118120 , SpecializePragma
119− , SCCPragma :: RdrName -> HsDecl GhcPs
121+ , SCCPragma
122+ , AnnTypePragma
123+ , AnnValuePragma :: RdrName -> HsDecl GhcPs
120124pattern TypeSignature n <- (sigRdrName -> Just n)
121125pattern FunctionBody n <- ValD NoExt (FunBind NoExt (L _ n) _ _ _)
122126pattern InlinePragma n <- SigD NoExt (InlineSig NoExt (L _ n) _)
123127pattern SpecializePragma n <- SigD NoExt (SpecSig NoExt (L _ n) _ _)
124128pattern SCCPragma n <- SigD NoExt (SCCFunSig NoExt _ (L _ n) _)
129+pattern AnnTypePragma n <- AnnD NoExt (HsAnnotation NoExt _ (TypeAnnProvenance (L _ n)) _)
130+pattern AnnValuePragma n <- AnnD NoExt (HsAnnotation NoExt _ (ValueAnnProvenance (L _ n)) _)
125131
126132sigRdrName :: HsDecl GhcPs -> Maybe RdrName
127133sigRdrName (SigD NoExt (TypeSig NoExt ((L _ n):_) _)) = Just n
src/Ormolu/Printer/Meat/Declaration/Annotation.hs+1−1
@@ -14,7 +14,7 @@ import Ormolu.Utils
1414
1515p_annDecl :: AnnDecl GhcPs -> R ()
1616p_annDecl = \case
17− HsAnnotation NoExt _ annProv expr -> pragma "ANN" $ do
17+ HsAnnotation NoExt _ annProv expr -> line . pragma "ANN" $ do
1818 p_annProv annProv
1919 breakpoint
2020 located expr p_hsExpr