on master help sign in
introduce some more direct doc generators like D.fromVersion
commit811d2803c632d8dfeaa8953f2666d0d13396b947 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 3 Jun 2019, 14:16 (7 years ago) parent7a12c54
1 file changed+61−23
compiler/src/Reporting/Doc.hs+61−23
compiler/src/Reporting/Doc.hs+61−23
@@ -7,16 +7,38 @@ module Reporting.Doc
77 , P.hcat, P.hsep, P.indent, P.sep, P.vcat
88 , P.red, P.cyan, P.magenta, P.green, P.blue, P.black, P.yellow
99 , P.dullred, P.dullcyan, P.dullyellow
10−
11− , fromChars, fromName, fromInt, fromUtf8
12− , toAnsi, toString, toLine
10+ --
11+ , fromChars
12+ , fromName
13+ , fromVersion
14+ , fromPackage
15+ , fromInt
16+ --
17+ , toAnsi
18+ , toString
19+ , toLine
20+ --
1321 , encode
14−
15− , stack, reflow, commaSep
16− , toSimpleNote, toSimpleHint, toFancyHint
17− , link, fancyLink, reflowLink, makeLink, makeNakedLink
18− , args, moreArgs
19− , ordinal, intToOrdinal
22+ --
23+ , stack
24+ , reflow
25+ , commaSep
26+ --
27+ , toSimpleNote
28+ , toFancyNote
29+ , toSimpleHint
30+ , toFancyHint
31+ --
32+ , link
33+ , fancyLink
34+ , reflowLink
35+ , makeLink
36+ , makeNakedLink
37+ --
38+ , args
39+ , moreArgs
40+ , ordinal
41+ , intToOrdinal
2042 , cycle
2143 )
2244 where
@@ -26,14 +48,16 @@ import Prelude hiding (cycle)
2648import qualified Data.List as List
2749import Data.Monoid ((<>))
2850import qualified Data.Name as Name
29−import qualified Data.Utf8 as Utf8
3051import qualified System.Console.ANSI.Types as Ansi
3152import qualified System.Info as Info
3253import System.IO (Handle)
3354import qualified Text.PrettyPrint.ANSI.Leijen as P
3455
3556import qualified Data.Index as Index
57+import qualified Elm.Package as Pkg
58+import qualified Elm.Version as V
3659import qualified Json.Encode as E
60+import qualified Json.String as Json
3761
3862
3963
@@ -50,16 +74,21 @@ fromName name =
5074 P.text (Name.toChars name)
5175
5276
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+
5387fromInt :: Int -> P.Doc
5488fromInt n =
5589 P.text (show n)
5690
5791
58−fromUtf8 :: Utf8.String -> P.Doc
59−fromUtf8 utf8 =
60− P.text (Utf8.toChars utf8)
61−
62−
6392
6493-- TO STRING
6594
@@ -111,12 +140,21 @@ commaSep conjunction addStyle names =
111140
112141
113142
114−-- HINTS
143+-- NOTES
115144
116145
117146toSimpleNote :: String -> P.Doc
118147toSimpleNote message =
119− P.fillSep ((P.underline "Note" <> ":") : map P.text (words message))
148+ toFancyNote (map P.text (words message))
149+
150+
151+toFancyNote :: [P.Doc] -> P.Doc
152+toFancyNote chunks =
153+ P.fillSep (P.underline "Note" <> ":" : chunks)
154+
155+
156+
157+-- HINTS
120158
121159
122160toSimpleHint :: String -> P.Doc
@@ -148,17 +186,17 @@ fancyLink word before fileName after =
148186 (P.underline word <> ":") : before ++ P.text (makeLink fileName) : after
149187
150188
151−makeLink :: String -> String
189+makeLink :: [Char] -> [Char]
152190makeLink fileName =
153− "<https://elm-lang.org/" <> error "TODO V.toString V.compiler" <> "/" <> fileName <> ">"
191+ "<https://elm-lang.org/" <> V.toChars V.compiler <> "/" <> fileName <> ">"
154192
155193
156−makeNakedLink :: String -> String
194+makeNakedLink :: [Char] -> [Char]
157195makeNakedLink fileName =
158− "https://elm-lang.org/" <> error "TODO V.toString V.compiler" <> "/" <> fileName
196+ "https://elm-lang.org/" <> V.toChars V.compiler <> "/" <> fileName
159197
160198
161−reflowLink :: String -> String -> String -> P.Doc
199+reflowLink :: [Char] -> [Char] -> [Char] -> P.Doc
162200reflowLink before fileName after =
163201 P.fillSep $
164202 map P.text (words before)
@@ -379,7 +417,7 @@ encodeChunks (Style bold underline color) revChunks =
379417
380418encodeColor :: Color -> E.Value
381419encodeColor color =
382− E.string $
420+ E.string $ Json.fromChars $
383421 case color of
384422 Red -> "red"
385423 RED -> "RED"