on master help sign in
Make sure types print out prettier
69b783fEvan Czaplicki
builder/src/Elm/Diff.hs+2−2
@@ -252,7 +252,7 @@ aliasToDoc name (Docs.Alias _ tvars tipe) =
252
252
253valueToDoc :: N.Name -> Docs.Value -> P.Doc
253valueToDoc :: N.Name -> Docs.Value -> P.Doc
254valueToDoc name (Docs.Value _ tipe) =
254valueToDoc name (Docs.Value _ tipe) =
255− nameToDoc name <+> P.colon <+> typeDoc tipe
255+ P.hang 4 $ P.sep [ nameToDoc name <+> P.colon, typeDoc tipe ]
256
256
257
257
258binopToDoc :: N.Name -> Docs.Binop -> P.Doc
258binopToDoc :: N.Name -> Docs.Binop -> P.Doc
@@ -271,7 +271,7 @@ binopToDoc name (Docs.Binop _ tipe associativity (Docs.Precedence n)) =
271
271
272typeDoc :: Type.Type -> P.Doc
272typeDoc :: Type.Type -> P.Doc
273typeDoc tipe =
273typeDoc tipe =
274− P.text (Type.toString Type.OneLine tipe)
274+ Type.toDoc Type.None tipe
275
275
276
276
277nameToDoc :: N.Name -> P.Doc
277nameToDoc :: N.Name -> P.Doc
compiler/src/Elm/Compiler/Type.hs+5−17
@@ -2,8 +2,8 @@
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Elm.Compiler.Type
3module Elm.Compiler.Type
4 ( Type(..)
4 ( Type(..)
5− , Format(..)
5+ , Context(..)
6− , toString
6+ , toDoc
7 , DebugMetadata(..)
7 , DebugMetadata(..)
8 , Alias(..)
8 , Alias(..)
9 , Union(..)
9 , Union(..)
@@ -55,20 +55,7 @@ data Union = Union N.Name [N.Name] [(N.Name, [Type])]
55
55
56
56
57
57
58−-- TO STRING
58+-- TO DOC
59−
60−
61−data Format = OneLine | MultiLine
62−
63−
64−toString :: Format -> Type -> String
65−toString format tipe =
66− case format of
67− OneLine ->
68− P.displayS (P.renderPretty 1.0 maxBound (toDoc None tipe)) ""
69−
70− MultiLine ->
71− P.displayS (P.renderPretty 1.0 80 (toDoc None tipe)) ""
72
59
73
60
74data Context = None | InType | InFunction
61data Context = None | InType | InFunction
@@ -162,7 +149,8 @@ collectLambdas tipe =
162
149
163encode :: Type -> Encode.Value
150encode :: Type -> Encode.Value
164encode tipe =
151encode tipe =
165− Encode.text (Text.pack (toString OneLine tipe))
152+ Encode.text $ Text.pack $
153+ P.displayS (P.renderPretty 1.0 (maxBound `div` 2) (toDoc None tipe)) ""
166
154
167
155
168decoder :: Decode.Decoder () Type
156decoder :: Decode.Decoder () Type
compiler/src/Generate/JavaScript.hs+2−1
@@ -17,6 +17,7 @@ import qualified Data.Map as Map
17import qualified Data.Set as Set
17import qualified Data.Set as Set
18import qualified Data.Text as Text
18import qualified Data.Text as Text
19import qualified Data.Text.Encoding as Text
19import qualified Data.Text.Encoding as Text
20+import qualified Text.PrettyPrint.ANSI.Leijen as P
20
21
21import qualified AST.Optimized as Opt
22import qualified AST.Optimized as Opt
22import qualified AST.Module.Name as ModuleName
23import qualified AST.Module.Name as ModuleName
@@ -90,7 +91,7 @@ print interfaces home name =
90 value = Name.toBuilder (Name.fromGlobal home name)
91 value = Name.toBuilder (Name.fromGlobal home name)
91 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
92 toString = Name.toBuilder (Name.fromKernel N.debug "toString")
92 annotation = I._types (interfaces ! home) ! name
93 annotation = I._types (interfaces ! home) ! name
93− tipe = Type.toString Type.MultiLine $ Extract.fromAnnotation annotation
94+ tipe = P.displayS (P.renderPretty 1.0 80 (Type.toDoc Type.None (Extract.fromAnnotation annotation))) ""
94 in
95 in
95 "var _value = " <> toString <> "(" <> value <> ");\n" <>
96 "var _value = " <> toString <> "(" <> value <> ");\n" <>
96 "var _type = '" <> B.stringUtf8 (show tipe) <> "';\n\
97 "var _type = '" <> B.stringUtf8 (show tipe) <> "';\n\