on master help sign in
Fix formatting of infix type synonyms using ‘p_infixDefHelper’
57373e5Utku Demir
data/examples/declaration/type-synonyms/multi-line-out.hs+6
@@ -1,6 +1,12 @@
1type Foo a b c
1type Foo a b c
2 = Bar c a b
2 = Bar c a b
3
3
4+type Foo
5+ a
6+ b
7+ c
8+ = Bar c a b
9+
4type Foo
10type Foo
5 = Bar
11 = Bar
6 Baz
12 Baz
data/examples/declaration/type-synonyms/multi-line.hs+5
@@ -1,6 +1,11 @@
1type Foo a b c
1type Foo a b c
2 = Bar c a b
2 = Bar c a b
3
3
4+type Foo
5+ a
6+ b c
7+ = Bar c a b
8+
4type Foo =
9type Foo =
5 Bar
10 Bar
6 Baz
11 Baz
data/examples/declaration/type-synonyms/simple-out.hs+4
@@ -1,2 +1,6 @@
1-- | Documentation.
1-- | Documentation.
2type Foo a b c = Bar c a b
2type Foo a b c = Bar c a b
3+
4+type a ~> b = TyFun a b -> Type
5+
6+type (a :+: b) c d e = ()
data/examples/declaration/type-synonyms/simple.hs+4
@@ -1,3 +1,7 @@
1-- | Documentation.
1-- | Documentation.
2
2
3type Foo a b c = Bar c a b
3type Foo a b c = Bar c a b
4+
5+type a ~> b = TyFun a b -> Type
6+
7+type (a :+: b) c d e = ()
src/Ormolu/Printer/Meat/Declaration.hs+1−1
@@ -65,7 +65,7 @@ p_hsDecl style = \case
65p_tyClDecl :: FamilyStyle -> TyClDecl GhcPs -> R ()
65p_tyClDecl :: FamilyStyle -> TyClDecl GhcPs -> R ()
66p_tyClDecl style = \case
66p_tyClDecl style = \case
67 FamDecl NoExt x -> p_famDecl style x
67 FamDecl NoExt x -> p_famDecl style x
68− SynDecl {..} -> p_synDecl tcdLName tcdTyVars tcdRhs
68+ SynDecl {..} -> p_synDecl tcdLName tcdFixity tcdTyVars tcdRhs
69 DataDecl {..} ->
69 DataDecl {..} ->
70 p_dataDecl
70 p_dataDecl
71 Associated
71 Associated
src/Ormolu/Printer/Meat/Declaration/Type.hs+8−5
@@ -8,7 +8,6 @@ module Ormolu.Printer.Meat.Declaration.Type
8 )
8 )
9where
9where
10
10
11−import Control.Monad
12import GHC
11import GHC
13import Ormolu.Printer.Combinators
12import Ormolu.Printer.Combinators
14import Ormolu.Printer.Meat.Common
13import Ormolu.Printer.Meat.Common
@@ -18,14 +17,18 @@ import SrcLoc (Located)
18
17
19p_synDecl
18p_synDecl
20 :: Located RdrName -- ^ Type constructor
19 :: Located RdrName -- ^ Type constructor
20+ -> LexicalFixity -- ^ Fixity
21 -> LHsQTyVars GhcPs -- ^ Type variables
21 -> LHsQTyVars GhcPs -- ^ Type variables
22 -> LHsType GhcPs -- ^ RHS of type declaration
22 -> LHsType GhcPs -- ^ RHS of type declaration
23 -> R ()
23 -> R ()
24−p_synDecl name tvars t = do
24+p_synDecl name fixity tvars t = do
25 txt "type "
25 txt "type "
26− p_rdrName name
27 let HsQTvs {..} = tvars
26 let HsQTvs {..} = tvars
28− unless (null hsq_explicit) space
27+ switchLayout (getLoc name : map getLoc hsq_explicit) $ do
28+ p_infixDefHelper
29+ (case fixity of Infix -> True; _ -> False)
30+ inci
31+ (p_rdrName name)
29− sep space (located' p_hsTyVarBndr) hsq_explicit
32+ (map (located' p_hsTyVarBndr) hsq_explicit)
30 breakpoint
33 breakpoint
31 inci (txt "= " >> located t p_hsType)
34 inci (txt "= " >> located t p_hsType)