on master help sign in
Implement signature declarations
3553fc3mrkkrp
data/examples/declaration/data/gadt/multiline-out.hs+1−3
@@ -4,9 +4,7 @@
4data Foo a where
4data Foo a where
5 -- | 'Foo' is wonderful.
5 -- | 'Foo' is wonderful.
6 Foo
6 Foo
7− :: forall a b. ( Show a
7+ :: forall a b. (Show a, Eq b) -- foo
8− , Eq b -- foo
9− )
10 => -- bar
8 => -- bar
11 a
9 a
12 -> b
10 -> b
data/examples/declaration/type/arguments-out.hsnew file+14
@@ -0,0 +1,14 @@
1+{-# LANGUAGE RankNTypes #-}
2+functionName
3+ :: (C1, C2, C3, C4, C5)
4+ => a
5+ -> b
6+ -> ( forall a. (C6, C7)
7+ => LongDataTypeName
8+ -> a
9+ -> AnotherLongDataTypeName
10+ -> b
11+ -> c
12+ )
13+ -> (c -> d)
14+ -> (a, b, c, d)
data/examples/declaration/type/arguments.hsnew file+16
@@ -0,0 +1,16 @@
1+{-# LANGUAGE RankNTypes #-}
2+
3+functionName
4+ :: (C1, C2, C3, C4, C5)
5+ => a
6+ -> b
7+ -> (forall a.
8+ (C6, C7)
9+ => LongDataTypeName
10+ -> a
11+ -> AnotherLongDataTypeName
12+ -> b
13+ -> c
14+ )
15+ -> (c -> d)
16+ -> (a, b, c, d)
data/examples/declaration/type/context-multi-line-out.hsnew file+10
@@ -0,0 +1,10 @@
1+functionName
2+ :: ( C1
3+ , C2
4+ , C3
5+ )
6+ => a
7+ -> b
8+ -> c
9+ -> d
10+ -> (a, b, c, d)
data/examples/declaration/type/context-multi-line.hsnew file+10
@@ -0,0 +1,10 @@
1+functionName
2+ :: ( C1
3+ , C2
4+ , C3
5+ )
6+ => a
7+ -> b
8+ -> c
9+ -> d
10+ -> (a, b, c, d)
data/examples/declaration/type/context-single-line-out.hsnew file+7
@@ -0,0 +1,7 @@
1+functionName
2+ :: (C1, C2, C3)
3+ => a
4+ -> b
5+ -> c
6+ -> d
7+ -> (a, b, c, d)
data/examples/declaration/type/context-single-line.hsnew file+7
@@ -0,0 +1,7 @@
1+functionName
2+ :: (C1, C2, C3)
3+ => a
4+ -> b
5+ -> c
6+ -> d
7+ -> (a, b, c, d)
data/examples/declaration/type/infix-promoted-type-constructor-out.hsnew file+3
@@ -0,0 +1,3 @@
1+fun1 :: Def ('[Ref s (Stored Uint32), IBool] T.:-> IBool)
2+
3+fun2 :: Def ('[Ref s (Stored Uint32), IBool] :-> IBool)
data/examples/declaration/type/infix-promoted-type-constructor.hsnew file+2
@@ -0,0 +1,2 @@
1+fun1 :: Def ('[ Ref s (Stored Uint32), IBool] 'T.:-> IBool)
2+fun2 :: Def ('[ Ref s (Stored Uint32), IBool] ':-> IBool)
data/examples/declaration/type/long-function-name-out.hsnew file+6
@@ -0,0 +1,6 @@
1+longFunctionName
2+ :: a
3+ -> b
4+ -> c
5+ -> d
6+ -> (a, b, c, d)
data/examples/declaration/type/long-function-name.hsnew file+6
@@ -0,0 +1,6 @@
1+longFunctionName
2+ :: a
3+ -> b
4+ -> c
5+ -> d
6+ -> (a, b, c, d)
data/examples/declaration/type/long-multiline-applications-out.hsnew file+15
@@ -0,0 +1,15 @@
1+functionName
2+ :: (C1, C2, C3, C4, C5)
3+ => a
4+ -> b
5+ -> ( LongDataTypeName
6+ AnotherLongDataTypeName
7+ AnotherLongDataTypeName2
8+ AnotherLongDataTypeName3
9+ -> a
10+ -> AnotherLongDataTypeName4
11+ -> b
12+ -> c
13+ )
14+ -> (c -> d)
15+ -> (a, b, c, d)
data/examples/declaration/type/long-multiline-applications.hsnew file+15
@@ -0,0 +1,15 @@
1+functionName
2+ :: (C1, C2, C3, C4, C5)
3+ => a
4+ -> b
5+ -> ( LongDataTypeName
6+ AnotherLongDataTypeName
7+ AnotherLongDataTypeName2
8+ AnotherLongDataTypeName3
9+ -> a
10+ -> AnotherLongDataTypeName4
11+ -> b
12+ -> c
13+ )
14+ -> (c -> d)
15+ -> (a, b, c, d)
ormolu.cabal+1
@@ -60,6 +60,7 @@ library
60 , Ormolu.Printer.Meat.Common
60 , Ormolu.Printer.Meat.Common
61 , Ormolu.Printer.Meat.Declaration
61 , Ormolu.Printer.Meat.Declaration
62 , Ormolu.Printer.Meat.Declaration.Data
62 , Ormolu.Printer.Meat.Declaration.Data
63+ , Ormolu.Printer.Meat.Declaration.Signature
63 , Ormolu.Printer.Meat.Declaration.Type
64 , Ormolu.Printer.Meat.Declaration.Type
64 , Ormolu.Printer.Meat.Declaration.TypeFamily
65 , Ormolu.Printer.Meat.Declaration.TypeFamily
65 , Ormolu.Printer.Meat.ImportExport
66 , Ormolu.Printer.Meat.ImportExport
src/Ormolu/Printer/Meat/Declaration.hs+2
@@ -11,12 +11,14 @@ where
11import GHC
11import GHC
12import Ormolu.Printer.Combinators
12import Ormolu.Printer.Combinators
13import Ormolu.Printer.Meat.Declaration.Data
13import Ormolu.Printer.Meat.Declaration.Data
14+import Ormolu.Printer.Meat.Declaration.Signature
14import Ormolu.Printer.Meat.Declaration.Type
15import Ormolu.Printer.Meat.Declaration.Type
15import Ormolu.Printer.Meat.Declaration.TypeFamily
16import Ormolu.Printer.Meat.Declaration.TypeFamily
16
17
17p_hsDecl :: HsDecl GhcPs -> R ()
18p_hsDecl :: HsDecl GhcPs -> R ()
18p_hsDecl = \case
19p_hsDecl = \case
19 TyClD x -> p_tyClDecl x
20 TyClD x -> p_tyClDecl x
21+ SigD x -> p_sigDecl x
20 _ -> error "this is not yet supported"
22 _ -> error "this is not yet supported"
21
23
22p_tyClDecl :: TyClDecl GhcPs -> R ()
24p_tyClDecl :: TyClDecl GhcPs -> R ()
src/Ormolu/Printer/Meat/Declaration/Signature.hsnew file+30
@@ -0,0 +1,30 @@
1+{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE OverloadedStrings #-}
3+{-# LANGUAGE RecordWildCards #-}
4+
5+-- | Type signature declarations.
6+
7+module Ormolu.Printer.Meat.Declaration.Signature
8+ ( p_sigDecl )
9+where
10+
11+import GHC
12+import Ormolu.Printer.Combinators
13+import Ormolu.Printer.Meat.Common
14+import Ormolu.Printer.Meat.Type
15+
16+p_sigDecl :: Sig GhcPs -> R ()
17+p_sigDecl = \case
18+ TypeSig names hswc -> line (p_typeSig names hswc)
19+ _ -> error "Ormolu.Printer.Meat.Declaration.Signature: unimplemented signatures"
20+
21+p_typeSig
22+ :: [Located RdrName]
23+ -> LHsSigWcType GhcPs
24+ -> R ()
25+p_typeSig names HsWC {..} = do
26+ spaceSep (located' p_rdrName) names
27+ breakpoint
28+ inci $ do
29+ txt ":: "
30+ relaxComments $ located (hsib_body hswc_body) p_hsType
src/Ormolu/Printer/Meat/Type.hs+1−1
@@ -24,7 +24,7 @@ p_hsType = \case
24 txt ". "
24 txt ". "
25 locatedVia Nothing t p_hsType
25 locatedVia Nothing t p_hsType
26 HsQualTy qs t -> do
26 HsQualTy qs t -> do
27− locatedVia Nothing qs p_hsContext
27+ located qs p_hsContext
28 breakpoint
28 breakpoint
29 txt "=> "
29 txt "=> "
30 locatedVia Nothing t p_hsType
30 locatedVia Nothing t p_hsType