on master help sign in
Insert space before promoted types where necessary
116a5a8sphaso
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)
52import Data.Text (Text)
52import Data.Text (Text)
53import Ormolu.Printer.Comments
53import Ormolu.Printer.Comments
54import Ormolu.Printer.Internal
54import Ormolu.Printer.Internal
55−import Ormolu.Utils (isModule)
55+import Ormolu.Utils (isModule, showOutputable)
56−import Outputable (Outputable (..), showSDocUnsafe)
56+import Outputable (Outputable)
57import SrcLoc
57import SrcLoc
58import qualified Data.Text as T
58import qualified Data.Text as T
59
59
@@ -72,7 +72,7 @@ txt t = ensureIndent >> spit t
72-- does have an 'Outputable' instance.
72-- does have an 'Outputable' instance.
73
73
74atom :: Outputable a => a -> R ()
74atom :: Outputable a => a -> R ()
75−atom = txt . T.pack . showSDocUnsafe . ppr
75+atom = txt . T.pack . showOutputable
76
76
77-- | Enter a 'Located' entity. This combinator handles outputting comments
77-- | Enter a 'Located' entity. This combinator handles outputting comments
78-- and sets layout (single-line vs multi-line) for the inner computation.
78-- 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
37 case p of
37 case p of
38 Promoted -> txt "'"
38 Promoted -> txt "'"
39 NotPromoted -> return ()
39 NotPromoted -> return ()
40+ case showOutputable (unLoc n) of
41+ _ : '\'' : _ -> space
42+ _ -> return ()
40 p_rdrName n
43 p_rdrName n
41 HsAppTy NoExt f x -> sitcc $ do
44 HsAppTy NoExt f x -> sitcc $ do
42 located f p_hsType
45 located f p_hsType
@@ -100,7 +103,11 @@ p_hsType = \case
100 case p of
103 case p of
101 Promoted -> txt "'"
104 Promoted -> txt "'"
102 NotPromoted -> return ()
105 NotPromoted -> return ()
106+ brackets $ do
107+ case xs of
108+ ((L _ (HsTyVar _ Promoted _)):_) -> space
109+ _ -> return ()
103− brackets . velt $ withSep comma (located' p_hsType) xs
110+ velt $ withSep comma (located' p_hsType) xs
104 HsExplicitTupleTy NoExt xs -> do
111 HsExplicitTupleTy NoExt xs -> do
105 txt "'"
112 txt "'"
106 parens . velt $ withSep comma (located' p_hsType) xs
113 parens . velt $ withSep comma (located' p_hsType) xs