on master help sign in
Insert space before promoted types where necessary
commit116a5a81df57e01062f821adcb0b97e77dea90b5 authorsphaso <sphaso@gmail.com> dateSat 20 Jul 2019, 12:17 (7 years ago) parent46a1c22
4 files changed+25−4
data/examples/declaration/type/promotion-out.hs+7 data/examples/declaration/type/promotion.hs+7 src/Ormolu/Printer/Combinators.hs+3−3 src/Ormolu/Printer/Meat/Type.hs+8−1
data/examples/declaration/type/promotion-out.hsnew file+7
@@ -0,0 +1,7 @@
1+type Foo = Cluster '[ 'NodeCore, 'NodeRelay', 'NodeEdge]
2+
3+data T = T' | T'T
4+
5+type S0 = ' T'
6+
7+type S1 = ' T'T
data/examples/declaration/type/promotion.hsnew file+7
@@ -0,0 +1,7 @@
1+type Foo = Cluster '[ 'NodeCore, 'NodeRelay', 'NodeEdge ]
2+
3+data T = T' | T'T
4+
5+type S0 = ' T'
6+
7+type S1 = ' T'T
src/Ormolu/Printer/Combinators.hs+3−3
@@ -52,8 +52,8 @@ import Data.List (intersperse)
5252import Data.Text (Text)
5353import Ormolu.Printer.Comments
5454import Ormolu.Printer.Internal
55−import Ormolu.Utils (isModule)
56−import Outputable (Outputable (..), showSDocUnsafe)
55+import Ormolu.Utils (isModule, showOutputable)
56+import Outputable (Outputable)
5757import SrcLoc
5858import qualified Data.Text as T
5959
@@ -72,7 +72,7 @@ txt t = ensureIndent >> spit t
7272-- does have an 'Outputable' instance.
7373
7474atom :: Outputable a => a -> R ()
75−atom = txt . T.pack . showSDocUnsafe . ppr
75+atom = txt . T.pack . showOutputable
7676
7777-- | Enter a 'Located' entity. This combinator handles outputting comments
7878-- and sets layout (single-line vs multi-line) for the inner computation.
src/Ormolu/Printer/Meat/Type.hs+8−1
@@ -37,6 +37,9 @@ p_hsType = \case
3737 case p of
3838 Promoted -> txt "'"
3939 NotPromoted -> return ()
40+ case showOutputable (unLoc n) of
41+ _ : '\'' : _ -> space
42+ _ -> return ()
4043 p_rdrName n
4144 HsAppTy NoExt f x -> sitcc $ do
4245 located f p_hsType
@@ -100,7 +103,11 @@ p_hsType = \case
100103 case p of
101104 Promoted -> txt "'"
102105 NotPromoted -> return ()
103− brackets . velt $ withSep comma (located' p_hsType) xs
106+ brackets $ do
107+ case xs of
108+ ((L _ (HsTyVar _ Promoted _)):_) -> space
109+ _ -> return ()
110+ velt $ withSep comma (located' p_hsType) xs
104111 HsExplicitTupleTy NoExt xs -> do
105112 txt "'"
106113 parens . velt $ withSep comma (located' p_hsType) xs