on master help sign in
Switch Reporting.Doc from Data.Text to Data.Utf8
be145bcEvan Czaplicki
compiler/src/Reporting/Doc.hs+18−33
@@ -8,7 +8,7 @@ module Reporting.Doc
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− , fromString, fromText, fromName, fromInt, fromUtf8
11+ , fromChars, fromName, fromInt, fromUtf8
12 , toAnsi, toString, toLine
12 , toAnsi, toString, toLine
13 , encode
13 , encode
14
14
@@ -26,17 +26,12 @@ import Prelude hiding (cycle)
26import qualified Data.List as List
26import qualified Data.List as List
27import Data.Monoid ((<>))
27import Data.Monoid ((<>))
28import qualified Data.Name as Name
28import qualified Data.Name as Name
29−import qualified Data.Text as Text
30−import qualified Data.Text.Lazy as TL
31−import qualified Data.Text.Lazy.Builder as TB
32import qualified Data.Utf8 as Utf8
29import qualified Data.Utf8 as Utf8
33import qualified System.Console.ANSI.Types as Ansi
30import qualified System.Console.ANSI.Types as Ansi
34import System.IO (Handle)
31import System.IO (Handle)
35import qualified Text.PrettyPrint.ANSI.Leijen as P
32import qualified Text.PrettyPrint.ANSI.Leijen as P
36
33
37import qualified Data.Index as Index
34import qualified Data.Index as Index
38−import qualified Elm.Compiler.Version as Compiler
39−import qualified Elm.Package as Pkg
40import qualified Json.Encode as E
35import qualified Json.Encode as E
41
36
42
37
@@ -44,19 +39,14 @@ import qualified Json.Encode as E
44-- FROM
39-- FROM
45
40
46
41
47−fromString :: String -> P.Doc
42+fromChars :: String -> P.Doc
48−fromString =
43+fromChars =
49 P.text
44 P.text
50
45
51
46
52−fromText :: Text.Text -> P.Doc
53−fromText txt =
54− P.text (Text.unpack txt)
55−
56−
57fromName :: Name.Name -> P.Doc
47fromName :: Name.Name -> P.Doc
58fromName name =
48fromName name =
59− P.text (Name.toString name)
49+ P.text (Name.toChars name)
60
50
61
51
62fromInt :: Int -> P.Doc
52fromInt :: Int -> P.Doc
@@ -64,9 +54,9 @@ fromInt n =
64 P.text (show n)
54 P.text (show n)
65
55
66
56
67−fromUtf8 :: Utf8.Utf8 -> P.Doc
57+fromUtf8 :: Utf8.String -> P.Doc
68fromUtf8 utf8 =
58fromUtf8 utf8 =
69− P.text (Utf8.toString utf8)
59+ P.text (Utf8.toChars utf8)
70
60
71
61
72
62
@@ -159,12 +149,12 @@ fancyLink word before fileName after =
159
149
160makeLink :: String -> String
150makeLink :: String -> String
161makeLink fileName =
151makeLink fileName =
162− "<https://elm-lang.org/" <> Pkg.versionToString Compiler.version <> "/" <> fileName <> ">"
152+ "<https://elm-lang.org/" <> error "TODO V.toString V.compiler" <> "/" <> fileName <> ">"
163
153
164
154
165makeNakedLink :: String -> String
155makeNakedLink :: String -> String
166makeNakedLink fileName =
156makeNakedLink fileName =
167− "https://elm-lang.org/" <> Pkg.versionToString Compiler.version <> "/" <> fileName
157+ "https://elm-lang.org/" <> error "TODO V.toString V.compiler" <> "/" <> fileName
168
158
169
159
170reflowLink :: String -> String -> String -> P.Doc
160reflowLink :: String -> String -> String -> P.Doc
@@ -267,8 +257,10 @@ data Color
267 | WHITE
257 | WHITE
268
258
269
259
270−toJsonHelp :: Style -> [TB.Builder] -> P.SimpleDoc -> [E.Value]
260+toJsonHelp :: Style -> [a] -> P.SimpleDoc -> [E.Value]
271toJsonHelp style revChunks simpleDoc =
261toJsonHelp style revChunks simpleDoc =
262+ error "TODO generate json on errors" style revChunks simpleDoc sgrToStyle encodeColor
263+{-
272 case simpleDoc of
264 case simpleDoc of
273 P.SFail ->
265 P.SFail ->
274 error $
266 error $
@@ -294,7 +286,7 @@ toJsonHelp style revChunks simpleDoc =
294spaces :: Int -> TB.Builder
286spaces :: Int -> TB.Builder
295spaces n =
287spaces n =
296 TB.fromText (Text.replicate n " ")
288 TB.fromText (Text.replicate n " ")
297−
289+-}
298
290
299sgrToStyle :: [Ansi.SGR] -> Style -> Style
291sgrToStyle :: [Ansi.SGR] -> Style -> Style
300sgrToStyle sgrs style@(Style bold underline color) =
292sgrToStyle sgrs style@(Style bold underline color) =
@@ -356,35 +348,28 @@ toColor layer intensity color =
356 Ansi.White -> pick White WHITE
348 Ansi.White -> pick White WHITE
357 Ansi.Black -> pick Black BLACK
349 Ansi.Black -> pick Black BLACK
358
350
359−
351+{-
360encodeChunks :: Style -> [TB.Builder] -> E.Value
352encodeChunks :: Style -> [TB.Builder] -> E.Value
361encodeChunks (Style bold underline color) revChunks =
353encodeChunks (Style bold underline color) revChunks =
362 let
354 let
363− text =
355+ !str = Utf8.concat (reverse revChunks)
364− case revChunks of
365− [] ->
366− Text.empty
367−
368− c:cs ->
369− TL.toStrict $ TB.toLazyText $
370− List.foldl' (\builder chunk -> chunk <> builder) c cs
371 in
356 in
372 case color of
357 case color of
373 Nothing | not bold && not underline ->
358 Nothing | not bold && not underline ->
374− E.text text
359+ E.string str
375
360
376 _ ->
361 _ ->
377 E.object
362 E.object
378 [ ("bold", E.bool bold)
363 [ ("bold", E.bool bold)
379 , ("underline", E.bool underline)
364 , ("underline", E.bool underline)
380 , ("color", maybe E.null encodeColor color)
365 , ("color", maybe E.null encodeColor color)
381− , ("string", E.text text)
366+ , ("string", E.string str)
382 ]
367 ]
383−
368+-}
384
369
385encodeColor :: Color -> E.Value
370encodeColor :: Color -> E.Value
386encodeColor color =
371encodeColor color =
387− E.text $
372+ E.string $
388 case color of
373 case color of
389 Red -> "red"
374 Red -> "red"
390 RED -> "RED"
375 RED -> "RED"