on master help sign in
introduce some more direct doc generators like D.fromVersion
811d280Evan Czaplicki
compiler/src/Reporting/Doc.hs+61−23
@@ -7,16 +7,38 @@ module Reporting.Doc
7 , P.hcat, P.hsep, P.indent, P.sep, P.vcat
7 , P.hcat, P.hsep, P.indent, P.sep, P.vcat
8 , P.red, P.cyan, P.magenta, P.green, P.blue, P.black, P.yellow
8 , P.red, P.cyan, P.magenta, P.green, P.blue, P.black, P.yellow
9 , P.dullred, P.dullcyan, P.dullyellow
9 , P.dullred, P.dullcyan, P.dullyellow
10−
10+ --
11− , fromChars, fromName, fromInt, fromUtf8
11+ , fromChars
12+ , fromName
13+ , fromVersion
14+ , fromPackage
15+ , fromInt
16+ --
17+ , toAnsi
12− , toAnsi, toString, toLine
18+ , toString
19+ , toLine
20+ --
13 , encode
21 , encode
14−
22+ --
23+ , stack
24+ , reflow
15− , stack, reflow, commaSep
25+ , commaSep
26+ --
16− , toSimpleNote, toSimpleHint, toFancyHint
27+ , toSimpleNote
28+ , toFancyNote
29+ , toSimpleHint
30+ , toFancyHint
31+ --
32+ , link
33+ , fancyLink
34+ , reflowLink
35+ , makeLink
17− , link, fancyLink, reflowLink, makeLink, makeNakedLink
36+ , makeNakedLink
37+ --
38+ , args
18− , args, moreArgs
39+ , moreArgs
40+ , ordinal
19− , ordinal, intToOrdinal
41+ , intToOrdinal
20 , cycle
42 , cycle
21 )
43 )
22 where
44 where
@@ -26,14 +48,16 @@ import Prelude hiding (cycle)
26import qualified Data.List as List
48import qualified Data.List as List
27import Data.Monoid ((<>))
49import Data.Monoid ((<>))
28import qualified Data.Name as Name
50import qualified Data.Name as Name
29−import qualified Data.Utf8 as Utf8
30import qualified System.Console.ANSI.Types as Ansi
51import qualified System.Console.ANSI.Types as Ansi
31import qualified System.Info as Info
52import qualified System.Info as Info
32import System.IO (Handle)
53import System.IO (Handle)
33import qualified Text.PrettyPrint.ANSI.Leijen as P
54import qualified Text.PrettyPrint.ANSI.Leijen as P
34
55
35import qualified Data.Index as Index
56import qualified Data.Index as Index
57+import qualified Elm.Package as Pkg
58+import qualified Elm.Version as V
36import qualified Json.Encode as E
59import qualified Json.Encode as E
60+import qualified Json.String as Json
37
61
38
62
39
63
@@ -50,16 +74,21 @@ fromName name =
50 P.text (Name.toChars name)
74 P.text (Name.toChars name)
51
75
52
76
77+fromVersion :: V.Version -> P.Doc
78+fromVersion vsn =
79+ P.text (V.toChars vsn)
80+
81+
82+fromPackage :: Pkg.Name -> P.Doc
83+fromPackage pkg =
84+ P.text (Pkg.toChars pkg)
85+
86+
53fromInt :: Int -> P.Doc
87fromInt :: Int -> P.Doc
54fromInt n =
88fromInt n =
55 P.text (show n)
89 P.text (show n)
56
90
57
91
58−fromUtf8 :: Utf8.String -> P.Doc
59−fromUtf8 utf8 =
60− P.text (Utf8.toChars utf8)
61−
62−
63
92
64-- TO STRING
93-- TO STRING
65
94
@@ -111,12 +140,21 @@ commaSep conjunction addStyle names =
111
140
112
141
113
142
114−-- HINTS
143+-- NOTES
115
144
116
145
117toSimpleNote :: String -> P.Doc
146toSimpleNote :: String -> P.Doc
118toSimpleNote message =
147toSimpleNote message =
148+ toFancyNote (map P.text (words message))
149+
150+
151+toFancyNote :: [P.Doc] -> P.Doc
152+toFancyNote chunks =
119− P.fillSep ((P.underline "Note" <> ":") : map P.text (words message))
153+ P.fillSep (P.underline "Note" <> ":" : chunks)
154+
155+
156+
157+-- HINTS
120
158
121
159
122toSimpleHint :: String -> P.Doc
160toSimpleHint :: String -> P.Doc
@@ -148,17 +186,17 @@ fancyLink word before fileName after =
148 (P.underline word <> ":") : before ++ P.text (makeLink fileName) : after
186 (P.underline word <> ":") : before ++ P.text (makeLink fileName) : after
149
187
150
188
151−makeLink :: String -> String
189+makeLink :: [Char] -> [Char]
152makeLink fileName =
190makeLink fileName =
153− "<https://elm-lang.org/" <> error "TODO V.toString V.compiler" <> "/" <> fileName <> ">"
191+ "<https://elm-lang.org/" <> V.toChars V.compiler <> "/" <> fileName <> ">"
154
192
155
193
156−makeNakedLink :: String -> String
194+makeNakedLink :: [Char] -> [Char]
157makeNakedLink fileName =
195makeNakedLink fileName =
158− "https://elm-lang.org/" <> error "TODO V.toString V.compiler" <> "/" <> fileName
196+ "https://elm-lang.org/" <> V.toChars V.compiler <> "/" <> fileName
159
197
160
198
161−reflowLink :: String -> String -> String -> P.Doc
199+reflowLink :: [Char] -> [Char] -> [Char] -> P.Doc
162reflowLink before fileName after =
200reflowLink before fileName after =
163 P.fillSep $
201 P.fillSep $
164 map P.text (words before)
202 map P.text (words before)
@@ -379,7 +417,7 @@ encodeChunks (Style bold underline color) revChunks =
379
417
380encodeColor :: Color -> E.Value
418encodeColor :: Color -> E.Value
381encodeColor color =
419encodeColor color =
382− E.string $
420+ E.string $ Json.fromChars $
383 case color of
421 case color of
384 Red -> "red"
422 Red -> "red"
385 RED -> "RED"
423 RED -> "RED"