on master help sign in
Implement properly indented constraint contexts

Essentially, it simply indents the constraints one layer, instead of hanging the constraints off of `class` or `instance`.

commitba64967c030ff76a9b7798242ac33923ff89a6e6 authoryumiova <yumiova@protonmail.ch> dateThu 27 Jun 2019, 23:01 (7 years ago) parentc5ed521
13 files changed+145−66
data/examples/declaration/class/dependency-super-classes-out.hs+6−5 data/examples/declaration/class/functional-dependencies-out.hs+7−6 data/examples/declaration/class/multi-parameters-out.hs+9−8 data/examples/declaration/class/poly-kinded-classes-out.hs+5−4 data/examples/declaration/class/super-classes-out.hs+9−7 data/examples/declaration/class/type-operators-out.hs+20−15 data/examples/declaration/instance/contexts-out.hs+34−5 data/examples/declaration/instance/contexts.hs+26 data/examples/declaration/instance/overlappable-instances-out.hs+4−1 data/examples/declaration/instance/overlappable-instances.hs+3−1 src/Ormolu/Printer/Meat/Declaration/Class.hs+12−10 src/Ormolu/Printer/Meat/Declaration/Instance.hs+6−3 src/Ormolu/Printer/Meat/Type.hs+4−1
data/examples/declaration/class/dependency-super-classes-out.hs+6−5
@@ -8,11 +8,12 @@ class (MonadReader r s, MonadWriter w m) => MonadState s m | m -> s where
88 put :: s -> m ()
99
1010-- | 'MonadParsec'
11−class ( Stream s -- Token streams
12− , MonadPlus m -- Potential for failure
13− )
14− => MonadParsec e s m
15− | m -> e s where
11+class
12+ ( Stream s -- Token streams
13+ , MonadPlus m -- Potential for failure
14+ )
15+ => MonadParsec e s m
16+ | m -> e s where
1617
1718 -- | 'getState' returns state
1819 getState
data/examples/declaration/class/functional-dependencies-out.hs+7−6
@@ -8,11 +8,12 @@ class Bar a b | a -> b, b -> a where
88 bar :: a
99
1010-- | Something else.
11−class Baz a b c d
12− | a b -> c d -- Foo
13− , b c -> a d -- Bar
14− , a c -> b d -- Baz
15− , a c d -> b
16− , a b d -> a b c d where
11+class
12+ Baz a b c d
13+ | a b -> c d -- Foo
14+ , b c -> a d -- Bar
15+ , a c -> b d -- Baz
16+ , a c d -> b
17+ , a b d -> a b c d where
1718
1819 baz :: a -> b
data/examples/declaration/class/multi-parameters-out.hs+9−8
@@ -13,18 +13,19 @@ class Bar a b c d where
1313 -> d
1414
1515class -- Before name
16− Baz where
16+ Baz where
1717
1818 baz :: Int
1919
2020-- | Something else.
21−class BarBaz
22− a -- Foo
23− b -- Bar
24− c -- Baz bar
25− d -- Baz baz
26− e -- Rest
27− f where
21+class
22+ BarBaz
23+ a -- Foo
24+ b -- Bar
25+ c -- Baz bar
26+ d -- Baz baz
27+ e -- Rest
28+ f where
2829
2930 barbaz
3031 :: a -> f
data/examples/declaration/class/poly-kinded-classes-out.hs+5−4
@@ -1,7 +1,8 @@
11{-# LANGUAGE PolyKinds #-}
22class Foo (a :: k)
33
4−class Bar
5− ( a -- Variable
6− :: * -- Star
7− )
4+class
5+ Bar
6+ ( a -- Variable
7+ :: * -- Star
8+ )
data/examples/declaration/class/super-classes-out.hs+9−7
@@ -2,11 +2,13 @@ class Foo a
22
33class Foo a => Bar a
44
5−class (Foo a, Bar a)
6− => Baz a
5+class
6+ (Foo a, Bar a)
7+ => Baz a
78
8−class ( Foo a -- Foo?
9− , Bar a -- Bar?
10− , Baz a -- Baz
11− )
12− => BarBar a
9+class
10+ ( Foo a -- Foo?
11+ , Bar a -- Bar?
12+ , Baz a -- Baz
13+ )
14+ => BarBar a
data/examples/declaration/class/type-operators-out.hs+20−15
@@ -2,28 +2,33 @@
22{-# LANGUAGE TypeOperators #-}
33class (:$) a b
44
5−class (:&)
6− a
7− b
5+class
6+ (:&)
7+ a
8+ b
89
910class a :* b
1011
11−class a :+ -- Before operator
12− b -- After operator
12+class
13+ a :+ -- Before operator
14+ b -- After operator
1315
14−class ( f :.
15− g
16− )
17− a
16+class
17+ ( f :.
18+ g
19+ )
20+ a
1821
1922class a `Pair` b
2023
21−class a `Sum`
22− b
24+class
25+ a `Sum`
26+ b
2327
2428class (f `Product` g) a
2529
26−class ( f `Sum`
27− g
28− )
29− a
30+class
31+ ( f `Sum`
32+ g
33+ )
34+ a
data/examples/declaration/instance/contexts-out.hs+34−5
@@ -2,10 +2,39 @@ instance Eq a => Eq [a] where
22
33 (==) _ _ = False
44
5−instance ( Ord a
6− , Ord b
7− )
8− => Ord
9− (a, b) where
5+instance
6+ ( Ord a
7+ , Ord b
8+ )
9+ => Ord (a, b) where
1010
1111 compare _ _ = GT
12+
13+instance
14+ (Show a, Show b)
15+ => Show
16+ ( a
17+ , b
18+ ) where
19+
20+ showsPrec _ _ = showString ""
21+
22+instance
23+ ( Read a -- Foo
24+ , Read b
25+ , Read
26+ ( c
27+ , -- Bar
28+ d
29+ )
30+ )
31+ => Read
32+ ( a
33+ , -- Baz
34+ b
35+ , ( c -- Quux
36+ , d
37+ )
38+ ) where
39+
40+ readsPrec = undefined
data/examples/declaration/instance/contexts.hs+26
@@ -5,3 +5,29 @@ instance (
55 Ord b
66 ) => Ord (a,b) where
77 compare _ _ = GT
8+
9+instance (Show a, Show b) =>
10+ Show (
11+ a,
12+ b
13+ ) where
14+ showsPrec _ _ = showString ""
15+
16+instance (
17+ Read a, -- Foo
18+ Read b
19+ , Read (
20+ c, -- Bar
21+ d
22+ )
23+ )
24+ =>
25+ Read (
26+ a, -- Baz
27+ b
28+ ,(
29+ c, -- Quux
30+ d
31+ )
32+ ) where
33+ readsPrec = undefined
data/examples/declaration/instance/overlappable-instances-out.hs+4−1
@@ -10,6 +10,9 @@ instance {-# OVERLAPS #-} Eq Double where
1010
1111 (==) _ _ = False
1212
13−instance {-# INCOHERENT #-} Ord Double where
13+instance
14+ {-# INCOHERENT #-}
15+ Ord
16+ Double where
1417
1518 compare _ _ = GT
data/examples/declaration/instance/overlappable-instances.hs+3−1
@@ -7,5 +7,7 @@ instance {-# OVERLAPS #-} Eq Double where
77 (==) _ _ = False
88
99instance
10− {-# INCOHERENT #-} Ord Double where
10+ {-# INCOHERENT #-}
11+ Ord
12+ Double where
1113 compare _ _ = GT
src/Ormolu/Printer/Meat/Declaration/Class.hs+12−10
@@ -44,16 +44,18 @@ p_classDecl ctx name tvars fixity fdeps csigs cdefs cats catdefs = do
4444 getLoc ctx `combineSrcSpans`
4545 signatureSpans `combineSrcSpans`
4646 dependencySpans
47− txt "class "
48− sitcc $ do
49− switchLayout combinedSpans $ p_classContext ctx
50− switchLayout signatureSpans $ do
51− p_infixDefHelper
52− (isInfix fixity)
53− inci
54− (p_rdrName name)
55− (located' p_hsTyVarBndr <$> hsq_explicit)
56− switchLayout combinedSpans $ p_classFundeps fdeps
47+ txt "class"
48+ switchLayout combinedSpans $ do
49+ breakpoint
50+ inci $ do
51+ p_classContext ctx
52+ switchLayout signatureSpans $ do
53+ p_infixDefHelper
54+ (isInfix fixity)
55+ inci
56+ (p_rdrName name)
57+ (located' p_hsTyVarBndr <$> hsq_explicit)
58+ inci (p_classFundeps fdeps)
5759 -- GHC's AST does not necessarily store each kind of element in source
5860 -- location order. This happens because different declarations are stored in
5961 -- different lists. Consequently, to get all the declarations in proper order,
src/Ormolu/Printer/Meat/Declaration/Instance.hs+6−3
@@ -65,10 +65,13 @@ p_standaloneDerivDecl (XDerivDecl _) = notImplemented "XDerivDecl"
6565p_clsInstDecl :: ClsInstDecl GhcPs -> R ()
6666p_clsInstDecl = \case
6767 ClsInstDecl {..} -> do
68− txt "instance "
69− match_overlap_mode cid_overlap_mode space
68+ txt "instance"
7069 case cid_poly_ty of
71− HsIB {..} -> sitcc (located hsib_body p_hsType)
70+ HsIB {..} -> located hsib_body $ \x -> do
71+ breakpoint
72+ inci $ do
73+ match_overlap_mode cid_overlap_mode breakpoint
74+ p_hsType x
7275 XHsImplicitBndrs NoExt -> notImplemented "XHsImplicitBndrs"
7376 -- GHC's AST does not necessarily store each kind of element in source
7477 -- location order. This happens because different declarations are stored in
src/Ormolu/Printer/Meat/Type.hs+4−1
@@ -29,7 +29,10 @@ p_hsType = \case
2929 located qs p_hsContext
3030 breakpoint
3131 txt "=> "
32− locatedVia Nothing t p_hsType
32+ case unLoc t of
33+ HsQualTy {} -> locatedVia Nothing t p_hsType
34+ HsFunTy {} -> locatedVia Nothing t p_hsType
35+ _ -> located t p_hsType
3336 HsTyVar NoExt p n -> do
3437 case p of
3538 Promoted -> txt "'"