on master help sign in
Fix formatting of infix type synonyms using ‘p_infixDefHelper’
commit57373e536d55a0fd9eb65dc0093148f15b4f21f8 authorUtku Demir <me@utdemir.com> dateWed 14 Aug 2019, 12:53 (7 years ago) parentacc7700
6 files changed+28−6
data/examples/declaration/type-synonyms/multi-line-out.hs+6 data/examples/declaration/type-synonyms/multi-line.hs+5 data/examples/declaration/type-synonyms/simple-out.hs+4 data/examples/declaration/type-synonyms/simple.hs+4 src/Ormolu/Printer/Meat/Declaration.hs+1−1 src/Ormolu/Printer/Meat/Declaration/Type.hs+8−5
data/examples/declaration/type-synonyms/multi-line-out.hs+6
@@ -1,6 +1,12 @@
11type Foo a b c
22 = Bar c a b
33
4+type Foo
5+ a
6+ b
7+ c
8+ = Bar c a b
9+
410type Foo
511 = Bar
612 Baz
data/examples/declaration/type-synonyms/multi-line.hs+5
@@ -1,6 +1,11 @@
11type Foo a b c
22 = Bar c a b
33
4+type Foo
5+ a
6+ b c
7+ = Bar c a b
8+
49type Foo =
510 Bar
611 Baz
data/examples/declaration/type-synonyms/simple-out.hs+4
@@ -1,2 +1,6 @@
11-- | Documentation.
22type 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 @@
11-- | Documentation.
22
33type 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
6565p_tyClDecl :: FamilyStyle -> TyClDecl GhcPs -> R ()
6666p_tyClDecl style = \case
6767 FamDecl NoExt x -> p_famDecl style x
68− SynDecl {..} -> p_synDecl tcdLName tcdTyVars tcdRhs
68+ SynDecl {..} -> p_synDecl tcdLName tcdFixity tcdTyVars tcdRhs
6969 DataDecl {..} ->
7070 p_dataDecl
7171 Associated
src/Ormolu/Printer/Meat/Declaration/Type.hs+8−5
@@ -8,7 +8,6 @@ module Ormolu.Printer.Meat.Declaration.Type
88 )
99where
1010
11−import Control.Monad
1211import GHC
1312import Ormolu.Printer.Combinators
1413import Ormolu.Printer.Meat.Common
@@ -18,14 +17,18 @@ import SrcLoc (Located)
1817
1918p_synDecl
2019 :: Located RdrName -- ^ Type constructor
20+ -> LexicalFixity -- ^ Fixity
2121 -> LHsQTyVars GhcPs -- ^ Type variables
2222 -> LHsType GhcPs -- ^ RHS of type declaration
2323 -> R ()
24−p_synDecl name tvars t = do
24+p_synDecl name fixity tvars t = do
2525 txt "type "
26− p_rdrName name
2726 let HsQTvs {..} = tvars
28− unless (null hsq_explicit) space
29− sep space (located' p_hsTyVarBndr) hsq_explicit
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)
32+ (map (located' p_hsTyVarBndr) hsq_explicit)
3033 breakpoint
3134 inci (txt "= " >> located t p_hsType)