on master help sign in
Switch everything over to going through Reporting.Doc
commita36152c14da34b0c2d056dd45d4a8377d3145e9e authorEvan Czaplicki <evancz@users.noreply.github.com> dateSat 7 Apr 2018, 22:36 (9 years ago) parent6ff0c83
20 files changed+405−466
builder/src/Deps/Get.hs+5−5 builder/src/Deps/Website.hs+3−2 builder/src/Elm/Bump.hs+9−9 builder/src/Elm/Diff.hs+35−40 builder/src/Elm/Install.hs+24−26 builder/src/Reporting/Exit.hs+22−30 builder/src/Reporting/Exit/Assets.hs+28−28 builder/src/Reporting/Exit/Bump.hs+7−8 builder/src/Reporting/Exit/Compile.hs+11−11 builder/src/Reporting/Exit/Crawl.hs+34−34 builder/src/Reporting/Exit/Deps.hs+18−19 builder/src/Reporting/Exit/Diff.hs+9−8 builder/src/Reporting/Exit/Help.hs+20−72 builder/src/Reporting/Exit/Http.hs+16−16 builder/src/Reporting/Exit/Publish.hs+45−46 builder/src/Reporting/Progress/Terminal.hs+19−21 compiler/src/Json/Decode/Error.hs+13−14 compiler/src/Reporting/Doc.hs+52−45 compiler/src/Reporting/Error/Pattern.hs+1−1 compiler/src/Reporting/Report.hs+34−31
builder/src/Deps/Get.hs+5−5
@@ -21,7 +21,6 @@ import Data.Map (Map)
2121import qualified Data.Text as Text
2222import qualified System.Directory as Dir
2323import System.FilePath ((</>))
24−import qualified Text.PrettyPrint.ANSI.Leijen as P
2524
2625import qualified Elm.Docs as Docs
2726import qualified Elm.Package as Pkg
@@ -29,12 +28,13 @@ import qualified Elm.Package as Pkg
2928import qualified Deps.Website as Website
3029import qualified Elm.Project.Json as Project
3130import qualified File.IO as IO
32−import qualified Reporting.Suggest as Suggest
31+import qualified Json.Decode as Decode
32+import qualified Reporting.Doc as D
3333import qualified Reporting.Exit as Exit
3434import qualified Reporting.Exit.Assets as E
3535import qualified Reporting.Progress as Progress
36+import qualified Reporting.Suggest as Suggest
3637import qualified Reporting.Task as Task
37−import qualified Json.Decode as Decode
3838
3939
4040
@@ -189,13 +189,13 @@ docs name version =
189189 Task.throw $ Exit.Assets $ E.CorruptDocumentation name version
190190
191191
192−errorToDocs :: Docs.Error -> [P.Doc]
192+errorToDocs :: Docs.Error -> [D.Doc]
193193errorToDocs err =
194194 let
195195 details =
196196 case err of
197197 Docs.BadAssociativity txt ->
198− ["Binary","operators","cannot","have",P.red (P.text (show txt)),"as","their","associativity."]
198+ ["Binary","operators","cannot","have",D.red (D.fromString (show txt)),"as","their","associativity."]
199199
200200 Docs.BadName ->
201201 ["It","is","not","a","valid","module","name."]
builder/src/Deps/Website.hs+3−2
@@ -13,6 +13,7 @@ module Deps.Website
1313 )
1414 where
1515
16+
1617import Prelude hiding (zip)
1718import qualified Codec.Archive.Zip as Zip
1819import Control.Monad (void)
@@ -29,12 +30,12 @@ import qualified Network.HTTP.Client.MultipartFormData as Multi
2930import qualified Network.HTTP.Types as Http
3031import qualified System.Directory as Dir
3132import System.FilePath ((</>), splitFileName)
32−import qualified Text.PrettyPrint.ANSI.Leijen as P
3333
3434import Elm.Package (Name, Version)
3535import qualified Elm.Package as Pkg
3636import qualified Json.Decode as D
3737
38+import qualified Reporting.Doc as D
3839import qualified Reporting.Exit.Http as E
3940import qualified Reporting.Progress as Progress
4041import qualified Reporting.Task as Task
@@ -128,7 +129,7 @@ fetchByteString path =
128129 return $ Right $ LBS.toStrict $ Client.responseBody response
129130
130131
131−fetchJson :: String -> (e -> [P.Doc]) -> D.Decoder e a -> String -> Http.Fetch a
132+fetchJson :: String -> (e -> [D.Doc]) -> D.Decoder e a -> String -> Http.Fetch a
132133fetchJson rootName errorToDocs decoder path =
133134 Http.package path [] $ \request manager ->
134135 do response <- Client.httpLbs request manager
builder/src/Elm/Bump.hs+9−9
@@ -8,8 +8,6 @@ module Elm.Bump
88
99import Control.Monad.Trans (liftIO)
1010import qualified Data.List as List
11−import Text.PrettyPrint.ANSI.Leijen ((<>), (<+>))
12−import qualified Text.PrettyPrint.ANSI.Leijen as P
1311
1412import qualified Deps.Diff as Diff
1513import qualified Deps.Get as Get
@@ -17,6 +15,8 @@ import qualified Elm.Package as Pkg
1715import qualified Elm.Project as Project
1816import qualified Elm.Project.Json as Project
1917import qualified Elm.Project.Summary as Summary
18+import Reporting.Doc ((<>), (<+>))
19+import qualified Reporting.Doc as D
2020import qualified Reporting.Exit as Exit
2121import qualified Reporting.Exit.Bump as E
2222import qualified Reporting.Exit.Help as Help
@@ -92,7 +92,7 @@ checkNewPackage root info@(Project.PkgInfo _ _ _ version _ _ _ _) =
9292 changeVersion root info Pkg.initialVersion $
9393 "It looks like the version in elm.json has been changed though!\n\
9494 \Would you like me to change it back to "
95− <> P.text (Pkg.versionToString Pkg.initialVersion) <> "? [Y/n] "
95+ <> D.fromText (Pkg.versionToText Pkg.initialVersion) <> "? [Y/n] "
9696
9797
9898
@@ -107,11 +107,11 @@ suggestVersion summary@(Summary.Summary root _ _ _ _) info@(Project.PkgInfo name
107107 let newVersion = Diff.bump changes version
108108 changeVersion root info newVersion $
109109 let
110− old = P.text $ Pkg.versionToString version
111− new = P.text $ Pkg.versionToString newVersion
112− mag = P.text $ Diff.magnitudeToString (Diff.toMagnitude changes)
110+ old = D.fromText $ Pkg.versionToText version
111+ new = D.fromText $ Pkg.versionToText newVersion
112+ mag = D.fromString $ Diff.magnitudeToString (Diff.toMagnitude changes)
113113 in
114− "Based on your new API, this should be a" <+> P.green mag <+> "change (" <> old <> " => " <> new <> ")\n"
114+ "Based on your new API, this should be a" <+> D.green mag <+> "change (" <> old <> " => " <> new <> ")\n"
115115 <> "Bail out of this command and run 'elm diff' for a full explanation.\n"
116116 <> "\n"
117117 <> "Should I perform the update (" <> old <> " => " <> new <> ") in elm.json? [Y/n] "
@@ -121,7 +121,7 @@ suggestVersion summary@(Summary.Summary root _ _ _ _) info@(Project.PkgInfo name
121121-- CHANGE VERSION
122122
123123
124−changeVersion :: FilePath -> Project.PkgInfo -> Pkg.Version -> P.Doc -> Task.Task ()
124+changeVersion :: FilePath -> Project.PkgInfo -> Pkg.Version -> D.Doc -> Task.Task ()
125125changeVersion root info targetVersion explanation =
126126 do liftIO $ Help.toStdout explanation
127127 approved <- Task.getApproval
@@ -135,5 +135,5 @@ changeVersion root info targetVersion explanation =
135135
136136 liftIO $ Help.toStdout $
137137 "Version changed to "
138− <> P.green (P.text (Pkg.versionToString targetVersion))
138+ <> D.green (D.fromText (Pkg.versionToText targetVersion))
139139 <> "!\n"
builder/src/Elm/Diff.hs+35−40
@@ -11,8 +11,6 @@ import Control.Monad.Except (liftIO)
1111import qualified Data.List as List
1212import qualified Data.Map as Map
1313import qualified Data.Maybe as Maybe
14−import Text.PrettyPrint.ANSI.Leijen ((<>), (<+>))
15−import qualified Text.PrettyPrint.ANSI.Leijen as P
1614
1715import Deps.Diff (PackageChanges(..), ModuleChanges(..), Changes(..), Magnitude(..))
1816import qualified Deps.Diff as Diff
@@ -25,6 +23,8 @@ import qualified Elm.Package as Pkg
2523import qualified Elm.Project as Project
2624import qualified Elm.Project.Json as Project
2725import qualified Elm.Project.Summary as Summary
26+import Reporting.Doc ((<>), (<+>))
27+import qualified Reporting.Doc as D
2828import qualified Reporting.Exit as Exit
2929import qualified Reporting.Exit.Diff as E
3030import qualified Reporting.Exit.Help as Help
@@ -109,7 +109,7 @@ getPackageInfo =
109109-- WRITE DOC
110110
111111
112−writeDoc :: P.Doc -> Task.Task ()
112+writeDoc :: D.Doc -> Task.Task ()
113113writeDoc doc =
114114 liftIO $ Help.toStdout (doc <> "\n")
115115
@@ -118,57 +118,57 @@ writeDoc doc =
118118-- TO DOC
119119
120120
121−toDoc :: PackageChanges -> P.Doc
121+toDoc :: PackageChanges -> D.Doc
122122toDoc changes@(PackageChanges added changed removed) =
123123 if null added && Map.null changed && null removed then
124− "No API changes detected, so this is a" <+> P.green "PATCH" <+> "change."
124+ "No API changes detected, so this is a" <+> D.green "PATCH" <+> "change."
125125 else
126126 let
127127 magDoc =
128− P.text (Diff.magnitudeToString (Diff.toMagnitude changes))
128+ D.fromString (Diff.magnitudeToString (Diff.toMagnitude changes))
129129
130130 header =
131− "This is a" <+> P.green magDoc <+> "change."
131+ "This is a" <+> D.green magDoc <+> "change."
132132
133133 addedChunk =
134134 if null added then [] else
135135 [ Chunk "ADDED MODULES" MINOR $
136− P.vcat $ map (P.text . Module.nameToString) added
136+ D.vcat $ map (D.fromString . Module.nameToString) added
137137 ]
138138
139139 removedChunk =
140140 if null removed then [] else
141141 [ Chunk "REMOVED MODULES" MAJOR $
142− P.vcat $ map (P.text . Module.nameToString) removed
142+ D.vcat $ map (D.fromString . Module.nameToString) removed
143143 ]
144144
145145 chunks =
146146 addedChunk ++ removedChunk ++ map changesToChunk (Map.toList changed)
147147 in
148− P.vcat (header : "" : map chunkToDoc chunks)
148+ D.vcat (header : "" : map chunkToDoc chunks)
149149
150150
151151data Chunk =
152152 Chunk
153153 { _title :: String
154154 , _magnitude :: Magnitude
155− , _details :: P.Doc
155+ , _details :: D.Doc
156156 }
157157
158158
159−chunkToDoc :: Chunk -> P.Doc
159+chunkToDoc :: Chunk -> D.Doc
160160chunkToDoc (Chunk title magnitude details) =
161161 let
162162 magDoc =
163163 Diff.magnitudeToString magnitude
164164
165165 header =
166− "----" <+> P.text title <+> "-" <+> P.text magDoc <+> "----"
166+ "----" <+> D.fromString title <+> "-" <+> D.fromString magDoc <+> "----"
167167 in
168− P.vcat
169− [ P.dullcyan header
168+ D.vcat
169+ [ D.dullcyan header
170170 , ""
171− , P.indent 4 details
171+ , D.indent 4 details
172172 , ""
173173 , ""
174174 ]
@@ -193,21 +193,21 @@ changesToChunk (name, changes@(ModuleChanges unions aliases values binops)) =
193193 changesToDocTriple binopToDoc binops
194194 in
195195 Chunk (N.toString name) magnitude $
196− P.vcat $ List.intersperse "" $ Maybe.catMaybes $
196+ D.vcat $ List.intersperse "" $ Maybe.catMaybes $
197197 [ changesToDoc "Added" unionAdd aliasAdd valueAdd binopAdd
198198 , changesToDoc "Removed" unionRemove aliasRemove valueRemove binopRemove
199199 , changesToDoc "Changed" unionChange aliasChange valueChange binopChange
200200 ]
201201
202202
203−changesToDocTriple :: (k -> v -> P.Doc) -> Changes k v -> ([P.Doc], [P.Doc], [P.Doc])
203+changesToDocTriple :: (k -> v -> D.Doc) -> Changes k v -> ([D.Doc], [D.Doc], [D.Doc])
204204changesToDocTriple entryToDoc (Changes added changed removed) =
205205 let
206206 indented (name, value) =
207− P.indent 4 (entryToDoc name value)
207+ D.indent 4 (entryToDoc name value)
208208
209209 diffed (name, (oldValue, newValue)) =
210− P.vcat
210+ D.vcat
211211 [ " - " <> entryToDoc name oldValue
212212 , " + " <> entryToDoc name newValue
213213 , ""
@@ -219,48 +219,48 @@ changesToDocTriple entryToDoc (Changes added changed removed) =
219219 )
220220
221221
222−changesToDoc :: String -> [P.Doc] -> [P.Doc] -> [P.Doc] -> [P.Doc] -> Maybe P.Doc
222+changesToDoc :: String -> [D.Doc] -> [D.Doc] -> [D.Doc] -> [D.Doc] -> Maybe D.Doc
223223changesToDoc categoryName unions aliases values binops =
224224 if null unions && null aliases && null values && null binops then
225225 Nothing
226226
227227 else
228− Just $ P.vcat $
229− P.text categoryName <> ":" : unions ++ aliases ++ binops ++ values
228+ Just $ D.vcat $
229+ D.fromString categoryName <> ":" : unions ++ aliases ++ binops ++ values
230230
231231
232−unionToDoc :: N.Name -> Docs.Union -> P.Doc
232+unionToDoc :: N.Name -> Docs.Union -> D.Doc
233233unionToDoc name (Docs.Union _ tvars ctors) =
234234 let
235235 setup =
236− "type" <+> nameToDoc name <+> P.hsep (map nameToDoc tvars)
236+ "type" <+> D.fromName name <+> D.hsep (map D.fromName tvars)
237237
238238 ctorDoc (ctor, tipes) =
239239 typeDoc (Type.Type ctor tipes)
240240 in
241− P.hang 4 (P.sep (setup : zipWith (<+>) ("=" : repeat "|") (map ctorDoc ctors)))
241+ D.hang 4 (D.sep (setup : zipWith (<+>) ("=" : repeat "|") (map ctorDoc ctors)))
242242
243243
244−aliasToDoc :: N.Name -> Docs.Alias -> P.Doc
244+aliasToDoc :: N.Name -> Docs.Alias -> D.Doc
245245aliasToDoc name (Docs.Alias _ tvars tipe) =
246246 let
247247 declaration =
248− "type" <+> "alias" <+> P.hsep (map nameToDoc (name:tvars)) <+> "="
248+ "type" <+> "alias" <+> D.hsep (map D.fromName (name:tvars)) <+> "="
249249 in
250− P.hang 4 (P.sep [ declaration, typeDoc tipe ])
250+ D.hang 4 (D.sep [ declaration, typeDoc tipe ])
251251
252252
253−valueToDoc :: N.Name -> Docs.Value -> P.Doc
253+valueToDoc :: N.Name -> Docs.Value -> D.Doc
254254valueToDoc name (Docs.Value _ tipe) =
255− P.hang 4 $ P.sep [ nameToDoc name <+> P.colon, typeDoc tipe ]
255+ D.hang 4 $ D.sep [ D.fromName name <+> ":", typeDoc tipe ]
256256
257257
258−binopToDoc :: N.Name -> Docs.Binop -> P.Doc
258+binopToDoc :: N.Name -> Docs.Binop -> D.Doc
259259binopToDoc name (Docs.Binop _ tipe associativity (Docs.Precedence n)) =
260− "(" <> nameToDoc name <> ")" <+> P.colon <+> typeDoc tipe <> P.black details
260+ "(" <> D.fromName name <> ")" <+> ":" <+> typeDoc tipe <> D.black details
261261 where
262262 details =
263− " (" <> nameToDoc assoc <> "/" <> P.int n <> ")"
263+ " (" <> D.fromName assoc <> "/" <> D.fromInt n <> ")"
264264
265265 assoc =
266266 case associativity of
@@ -269,11 +269,6 @@ binopToDoc name (Docs.Binop _ tipe associativity (Docs.Precedence n)) =
269269 Docs.Right -> "right"
270270
271271
272−typeDoc :: Type.Type -> P.Doc
272+typeDoc :: Type.Type -> D.Doc
273273typeDoc tipe =
274274 Type.toDoc Type.None tipe
275−
276−
277−nameToDoc :: N.Name -> P.Doc
278−nameToDoc name =
279− P.text (N.toString name)
builder/src/Elm/Install.hs+24−26
@@ -1,3 +1,4 @@
1+{-# LANGUAGE OverloadedStrings #-}
12module Elm.Install
23 ( install
34 )
@@ -9,9 +10,7 @@ import Control.Monad.Except (catchError, lift, liftIO)
910import Data.Map (Map, (!))
1011import qualified Data.Map as Map
1112import qualified Data.Map.Merge.Lazy as Map
12−import qualified System.IO as IO
13−import Text.PrettyPrint.ANSI.Leijen ((<>), (<+>))
14−import qualified Text.PrettyPrint.ANSI.Leijen as P
13+import System.IO (stdout)
1514
1615import qualified Elm.Package as Pkg
1716import Elm.Package (Name, Version)
@@ -24,6 +23,8 @@ import Elm.Project.Constraint (Constraint)
2423import qualified Elm.Project.Constraint as Con
2524import qualified Elm.Project.Json as Project
2625import qualified Elm.Project.Root as Root
26+import Reporting.Doc ((<>), (<+>))
27+import qualified Reporting.Doc as D
2728import qualified Reporting.Exit as Exit
2829import qualified Reporting.Task as Task
2930
@@ -226,9 +227,6 @@ withApproval toString changes attemptInstall =
226227
227228 changeDocs =
228229 Map.foldrWithKey (addChange toString widths) (Docs [] [] []) changes
229−
230− printDoc doc =
231− P.displayIO IO.stdout $ P.renderPretty 1 80 doc
232230 in
233231 case changeDocs of
234232 Docs [] [] [] ->
@@ -236,13 +234,13 @@ withApproval toString changes attemptInstall =
236234
237235 Docs inserts [] [] ->
238236 do liftIO $ putStrLn "Adding the following dependencies:\n"
239− liftIO $ printDoc $ P.indent 2 (P.vcat (reverse inserts))
237+ liftIO $ D.toAnsi stdout $ D.indent 2 (D.vcat (reverse inserts))
240238 liftIO $ putStrLn "\n"
241239 attemptInstall
242240
243241 Docs _ _ _ ->
244242 do liftIO $ putStrLn "Here is my plan:"
245− liftIO $ printDoc $ viewChangeDocs changeDocs
243+ liftIO $ D.toAnsi stdout $ viewChangeDocs changeDocs
246244 liftIO $ putStrLn "\nDo you approve? [Y/n]: "
247245 Task.withApproval attemptInstall
248246
@@ -253,29 +251,29 @@ withApproval toString changes attemptInstall =
253251
254252data ChangeDocs =
255253 Docs
256− { _doc_inserts :: [P.Doc]
257− , _doc_changes :: [P.Doc]
258− , _doc_removes :: [P.Doc]
254+ { _doc_inserts :: [D.Doc]
255+ , _doc_changes :: [D.Doc]
256+ , _doc_removes :: [D.Doc]
259257 }
260258
261259
262−viewChangeDocs :: ChangeDocs -> P.Doc
260+viewChangeDocs :: ChangeDocs -> D.Doc
263261viewChangeDocs (Docs inserts changes removes) =
264− P.indent 2 $ P.vcat $ concat $
262+ D.indent 2 $ D.vcat $ concat $
265263 [ viewNonZero "Add:" inserts
266264 , viewNonZero "Change:" changes
267265 , viewNonZero "Remove:" removes
268266 ]
269267
270268
271−viewNonZero :: String -> [P.Doc] -> [P.Doc]
269+viewNonZero :: String -> [D.Doc] -> [D.Doc]
272270viewNonZero title entries =
273271 if null entries then
274272 []
275273 else
276− [ P.text ""
277− , P.text title
278− , P.indent 2 (P.vcat (reverse entries))
274+ [ ""
275+ , D.fromString title
276+ , D.indent 2 (D.vcat (reverse entries))
279277 ]
280278
281279
@@ -296,34 +294,34 @@ addChange toString widths name change (Docs inserts changes removes) =
296294 Docs inserts changes (viewRemove toString widths name old : removes)
297295
298296
299−viewInsert :: (a -> String) -> Widths -> Name -> a -> P.Doc
297+viewInsert :: (a -> String) -> Widths -> Name -> a -> D.Doc
300298viewInsert toString (Widths nameWidth leftWidth _) name new =
301299 viewName nameWidth name <+> pad leftWidth (toString new)
302300
303301
304−viewChange :: (a -> String) -> Widths -> Name -> a -> a -> P.Doc
302+viewChange :: (a -> String) -> Widths -> Name -> a -> a -> D.Doc
305303viewChange toString (Widths nameWidth leftWidth rightWidth) name old new =
306− P.hsep
304+ D.hsep
307305 [ viewName nameWidth name
308306 , pad leftWidth (toString old)
309− , P.text "=>"
307+ , "=>"
310308 , pad rightWidth (toString new)
311309 ]
312310
313311
314−viewRemove :: (a -> String) -> Widths -> Name -> a -> P.Doc
312+viewRemove :: (a -> String) -> Widths -> Name -> a -> D.Doc
315313viewRemove toString (Widths nameWidth leftWidth _) name old =
316314 viewName nameWidth name <+> pad leftWidth (toString old)
317315
318316
319−viewName :: Int -> Name -> P.Doc
317+viewName :: Int -> Name -> D.Doc
320318viewName width name =
321− P.fill (width + 3) (P.text (Pkg.toString name))
319+ D.fill (width + 3) (D.fromText (Pkg.toText name))
322320
323321
324−pad :: Int -> String -> P.Doc
322+pad :: Int -> String -> D.Doc
325323pad width string =
326− P.text (replicate (width - length string) ' ') <> P.text string
324+ D.fromString (replicate (width - length string) ' ') <> D.fromString string
327325
328326
329327
builder/src/Reporting/Exit.hs+22−30
@@ -8,9 +8,6 @@ module Reporting.Exit
88 where
99
1010
11−import Data.Monoid ((<>))
12−import qualified Text.PrettyPrint.ANSI.Leijen as P
13−
1411import qualified Elm.Compiler as Compiler
1512import qualified Elm.Compiler.Module as Module
1613import qualified Elm.Package as Pkg
@@ -74,18 +71,18 @@ toReport exit =
7471 NoElmJson ->
7572 Help.report "WELCOME" Nothing
7673 "It looks like you are trying to start a new Elm project. Very exciting! :D"
77− [ P.fillSep
74+ [ D.fillSep
7875 ["I","very","highly","recommend","working","through"
79− ,P.green "<https://guide.elm-lang.org>","which","will","teach","you","the"
76+ ,D.green "<https://guide.elm-lang.org>","which","will","teach","you","the"
8077 ,"basics","of","Elm,","including","how","to","start","new","projects."
8178 ]
82− , P.fillSep
79+ , D.fillSep
8380 ["For","folks","who","have","already","built","stuff","with","Elm,","the"
84− ,"problem","is","just","that","there","is","no",P.dullyellow "elm.json","yet."
81+ ,"problem","is","just","that","there","is","no",D.dullyellow "elm.json","yet."
8582 ,"If","you","want","to","work","from","an","example,","check","out","the"
8683 ,"one","at","<https://github.com/evancz/elm-todomvc/blob/master/elm.json>"
8784 ]
88− , Help.reflow
85+ , D.reflow
8986 "Whatever your scenario, I hope you have a lovely time using Elm!"
9087 ]
9188
@@ -105,9 +102,9 @@ toReport exit =
105102 Help.report "IMPORT CYCLE" Nothing
106103 "Your module imports form a cycle:"
107104 [ D.cycle 4 names
108− , Help.reflow $
105+ , D.reflow $
109106 "Learn more about why this is disallowed and how to break cycles here:"
110− ++ Help.hintLink "import-cycles"
107+ ++ D.makeLink "import-cycles"
111108 ]
112109
113110 Deps depsError ->
@@ -129,8 +126,8 @@ toReport exit =
129126 "This usually happens if you try to modify dependency constraints by\
130127 \ hand. I recommend deleting any dependency you added recently (or all\
131128 \ of them if things are bad) and then adding them again with:"
132− [ P.indent 4 $ P.green "elm install"
133− , Help.reflow $
129+ [ D.indent 4 $ D.green "elm install"
130+ , D.reflow $
134131 "And do not be afaid to ask for help on Slack if you get stuck!"
135132 ]
136133
@@ -138,12 +135,12 @@ toReport exit =
138135 Help.report "OLD DEPENDENCIES" (Just "elm.json")
139136 ( "The following packages do not work with Elm " ++ Pkg.versionToString Compiler.version ++ " right now:"
140137 )
141− [ P.indent 4 $ P.vcat $ map (P.red . P.text . Pkg.toString) badPackages
142− , Help.reflow $
138+ [ D.indent 4 $ D.vcat $ map (D.red . D.fromString . Pkg.toString) badPackages
139+ , D.reflow $
143140 "This may be because it is not upgraded yet. It may be because a\
144141 \ better solution came along, so there was no need to upgrade it.\
145142 \ Etc. Try asking around on Slack to learn more about the topic."
146− , Help.note
143+ , D.toSimpleNote
147144 "Whatever the case, please be kind to the relevant package authors! Having\
148145 \ friendly interactions with users is great motivation, and conversely, getting\
149146 \ berated by strangers on the internet sucks your soul dry. Furthermore, package\
@@ -155,37 +152,32 @@ toReport exit =
155152 CannotMakeNothing ->
156153 Help.report "NO INPUT" Nothing
157154 "What should I make though? I need more information, like:"
158− [ P.vcat
159− [ P.indent 4 $ P.green "elm make MyThing.elm"
160− , P.indent 4 $ P.green "elm make This.elm That.elm"
155+ [ D.vcat
156+ [ D.indent 4 $ D.green "elm make MyThing.elm"
157+ , D.indent 4 $ D.green "elm make This.elm That.elm"
161158 ]
162− , Help.reflow
159+ , D.reflow
163160 "However many files you give, I will create one JS file out of them."
164161 ]
165162
166163 CannotOptimizeDebug m ms ->
167164 Help.report "DEBUG REMNANTS" Nothing
168165 "There are uses of the `Debug` module in the following modules:"
169− [ P.indent 4 $ P.red $ P.vcat $ map (P.text . Module.nameToString) (m:ms)
170− , Help.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
171− , toSimpleNote $
166+ [ D.indent 4 $ D.red $ D.vcat $ map (D.fromString . Module.nameToString) (m:ms)
167+ , D.reflow "But the --optimize flag only works if all `Debug` functions are removed!"
168+ , D.toSimpleNote $
172169 "The issue is that --optimize strips out info needed by `Debug` functions.\
173170 \ Here are two examples:"
174− , P.indent 4 $ Help.reflow $
171+ , D.indent 4 $ D.reflow $
175172 "(1) It shortens record field names. This makes the generated JavaScript is\
176173 \ smaller, but `Debug.toString` cannot know the real field names anymore."
177− , P.indent 4 $ Help.reflow $
174+ , D.indent 4 $ D.reflow $
178175 "(2) Values like `type Height = Height Float` are unboxed. This reduces\
179176 \ allocation, but it also means that `Debug.toString` cannot tell if it is\
180177 \ looking at a `Height` or `Float` value."
181− , Help.reflow $
178+ , D.reflow $
182179 "There are a few other cases like that, and it will be much worse once we start\
183180 \ inlining code. That optimization could move `Debug.log` and `Debug.todo` calls,\
184181 \ resulting in unpredictable behavior. I hope that clarifies why this restriction\
185182 \ exists!"
186183 ]
187−
188−
189−toSimpleNote :: String -> P.Doc
190−toSimpleNote message =
191− P.fillSep ((P.underline "Note" <> ":") : map P.text (words message))
builder/src/Reporting/Exit/Assets.hs+28−28
@@ -9,11 +9,11 @@ module Reporting.Exit.Assets
99 where
1010
1111
12−import Data.Monoid ((<>))
1312import qualified Data.Text as Text
14−import qualified Text.PrettyPrint.ANSI.Leijen as P
1513
1614import qualified Elm.Package as Pkg
15+import Reporting.Doc ((<>))
16+import qualified Reporting.Doc as D
1717import qualified Reporting.Exit.Help as Help
1818
1919
@@ -33,7 +33,7 @@ data Exit
3333
3434
3535data ElmJsonProblem
36− = BadJson P.Doc
36+ = BadJson D.Doc
3737 | BadDepDup String String Pkg.Name [Pkg.Name]
3838 | BadSrcDir FilePath
3939
@@ -54,7 +54,7 @@ toReport exit =
5454 CorruptBinary path ->
5555 Help.report "CORRUPT BINARY" (Just path)
5656 ("The binary data at " ++ path ++ " is corrupt.")
57− [ Help.reflow $
57+ [ D.reflow $
5858 "Maybe a program is modifying your elm-stuff/ or ELM_HOME\
5959 \ directory in unexpected ways? Both of those are just caches, so\
6060 \ you can try deleting them and they will be rebuilt from scratch."
@@ -74,7 +74,7 @@ corruptJsonToReport path pkg vsn =
7474 ( "The " ++ path ++ " for " ++ Pkg.toString pkg
7575 ++ " " ++ Pkg.versionToString vsn ++ " got corrupted somehow."
7676 )
77− [ Help.reflow $
77+ [ D.reflow $
7878 "I removed it from my file cache, so if it was some transient\
7979 \ error it should be fixed if you try the same thing again.\
8080 \ Please report this if it seems like an Elm problem though!"
@@ -94,8 +94,8 @@ elmJsonProblemToReport problem =
9494 BadSrcDir dir ->
9595 Help.report "BAD JSON" (Just "elm.json")
9696 "The \"source-directories\" in your elm.json lists the following directory:"
97− [ P.indent 4 (P.dullyellow (P.text dir))
98− , Help.reflow "I cannot find that directory though! Is it missing? Is there a typo?"
97+ [ D.indent 4 (D.dullyellow (D.fromString dir))
98+ , D.reflow "I cannot find that directory though! Is it missing? Is there a typo?"
9999 ]
100100
101101 BadDepDup field1 field2 dup dups ->
@@ -116,13 +116,13 @@ elmJsonProblemToReport problem =
116116 else
117117 "The following packages appear twice in your elm.json file:"
118118 )
119− [ P.dullyellow $ P.indent 4 $ P.vcat $
120− map (P.text . Pkg.toString) (dup:dups)
121− , Help.reflow $
119+ [ D.dullyellow $ D.indent 4 $ D.vcat $
120+ map (D.fromString . Pkg.toString) (dup:dups)
121+ , D.reflow $
122122 "The " ++ packagesAre ++ " available in \"" ++ field1
123123 ++ "\", so it is redundant to list it again in \"" ++ field2
124124 ++ "\". It is already available! " ++ advice
125− , Help.reflow "More help at <https://github.com/elm-lang/elm-package/blob/master/TODO>"
125+ , D.reflow "More help at <https://github.com/elm-lang/elm-package/blob/master/TODO>"
126126 ]
127127
128128
@@ -143,49 +143,49 @@ data BadElmJsonContent
143143 | BadSummaryTooLong
144144
145145
146−badContentToDocs :: BadElmJsonContent -> [P.Doc]
146+badContentToDocs :: BadElmJsonContent -> [D.Doc]
147147badContentToDocs badContent =
148148 case badContent of
149149 BadType _ ->
150150 ["The","only","valid","types","of","elm.json","are"
151− ,P.green "\"application\"","and",P.green "\"package\"" <> "."
151+ ,D.green "\"application\"","and",D.green "\"package\"" <> "."
152152 ]
153153
154154 BadPkgName problem ->
155− map P.text (words problem)
155+ map D.fromString (words problem)
156156
157157 BadVersion txt ->
158− ["You","provided",P.red (P.text (show txt))
158+ ["You","provided",D.red (D.fromString (show txt))
159159 ,"which","is","not","a","valid","version.","I","need","something","like"
160− ,P.green "\"1.0.0\"","or",P.green "\"2.0.4\"" <> "."
160+ ,D.green "\"1.0.0\"","or",D.green "\"2.0.4\"" <> "."
161161 ]
162162
163163 BadConstraint problem ->
164− map P.text (words ("It is not a valid constraint. " ++ problem))
164+ map D.fromString (words ("It is not a valid constraint. " ++ problem))
165165
166166 BadModuleName name ->
167− ["You","provided",P.text (show name),"which","is","not","a","valid","module","name."
168− ,"I","need","something","like",P.green "\"Html.Events\"","or",P.green "\"Browser.Navigation\"" <> "."
167+ ["You","provided",D.fromString (show name),"which","is","not","a","valid","module","name."
168+ ,"I","need","something","like",D.green "\"Html.Events\"","or",D.green "\"Browser.Navigation\"" <> "."
169169 ]
170170
171171 BadModuleHeaderTooLong header ->
172− ["The",P.text (show header),"header","is","too","long."
173− ,"I","need","it","to","be",P.green "under",P.green "20",P.green "characters"
172+ ["The",D.fromString (show header),"header","is","too","long."
173+ ,"I","need","it","to","be",D.green "under",D.green "20",D.green "characters"
174174 ,"to","ensure","that","formatting","is","nice","on","the","package","website."
175175 ]
176176
177177 BadDependencyName name ->
178− ["The",P.text (show name),"entry","is","not","a","valid","package","name."
178+ ["The",D.fromString (show name),"entry","is","not","a","valid","package","name."
179179 ,"I","recommend","deleting","it,","finding","the","package","you","want","on"
180180 ,"the","package","website,","and","installing","it","with","the"
181− ,P.green "`elm install`","command","instead."
181+ ,D.green "`elm install`","command","instead."
182182 ]
183183
184184 BadLicense _given suggestions ->
185185 case suggestions of
186186 [] ->
187187 ["I","need","an","OSI","approved","SPDX","license,","like"
188− ,P.green "\"BSD-3-Clause\"","or",P.green "\"MIT\".","See"
188+ ,D.green "\"BSD-3-Clause\"","or",D.green "\"MIT\".","See"
189189 ,"<https://spdx.org/licenses/>","for","a","full","list","of","options."
190190 ]
191191
@@ -195,20 +195,20 @@ badContentToDocs badContent =
195195 ++ ["See","<https://spdx.org/licenses/>","for","a","full","list","of","options."]
196196
197197 BadDirectoryNotString ->
198− ["I","need","a",P.green "STRING","that","points","to","a","directory","of","Elm","code."
198+ ["I","need","a",D.green "STRING","that","points","to","a","directory","of","Elm","code."
199199 ]
200200
201201 BadSummaryTooLong ->
202202 ["Your","summary","is","too","long.","I","need","it","to"
203− ,"be",P.green "under",P.green "80",P.green "characters."
203+ ,"be",D.green "under",D.green "80",D.green "characters."
204204 ]
205205
206206
207−oneOf :: Text.Text -> [Text.Text] -> [P.Doc]
207+oneOf :: Text.Text -> [Text.Text] -> [D.Doc]
208208oneOf code codes =
209209 let
210210 toDoc spdx =
211− P.green (P.text (show spdx))
211+ D.green (D.fromString (show spdx))
212212 in
213213 case codes of
214214 [] ->
builder/src/Reporting/Exit/Bump.hs+7−8
@@ -6,10 +6,9 @@ module Reporting.Exit.Bump
66 where
77
88
9−import Data.Monoid ((<>))
10−import qualified Text.PrettyPrint.ANSI.Leijen as P
11−
129import qualified Elm.Package as Pkg
10+import Reporting.Doc ((<>))
11+import qualified Reporting.Doc as D
1312import qualified Reporting.Exit.Help as Help
1413
1514
@@ -37,16 +36,16 @@ toReport exit =
3736
3837 Unbumpable vsn versions ->
3938 Help.docReport "UNBUMPABLE" (Just "elm.json")
40− ( P.fillSep
39+ ( D.fillSep
4140 ["Your","elm.json","says","I","should","bump","relative","to","version"
42− ,P.red (P.text (Pkg.versionToString vsn)) <> ","
41+ ,D.red (D.fromText (Pkg.versionToText vsn)) <> ","
4342 ,"but","I","cannot","find","that","version","on","<https://package.elm-lang.org>."
4443 ,"That","means","there","is","no","API","for","me","to","diff","against","and"
4544 ,"figure","out","if","these","are","MAJOR,","MINOR,","or","PATCH","changes."
4645 ]
4746 )
48− [ P.fillSep $
49− ["Try","bumping","again","after","changing","the",P.dullyellow "\"version\"","in","elm.json"]
47+ [ D.fillSep $
48+ ["Try","bumping","again","after","changing","the",D.dullyellow "\"version\"","in","elm.json"]
5049 ++ if length versions == 1 then ["to:"] else ["to","one","of","these:"]
51− , P.vcat $ map (P.green . P.text . Pkg.versionToString) versions
50+ , D.vcat $ map (D.green . D.fromText . Pkg.versionToText) versions
5251 ]
builder/src/Reporting/Exit/Compile.hs+11−11
@@ -11,11 +11,11 @@ module Reporting.Exit.Compile
1111import qualified Data.List as List
1212import qualified Data.Text as Text
1313import qualified Data.Time.Clock as Time
14−import qualified Text.PrettyPrint.ANSI.Leijen as P
1514
1615import qualified Elm.Compiler as Compiler
1716import qualified Elm.Compiler.Module as Module
1817import qualified Json.Encode as Encode
18+import qualified Reporting.Doc as D
1919
2020
2121
@@ -45,15 +45,15 @@ toJson (Exit name path _ source errors) =
4545-- TO DOC
4646
4747
48−toDoc :: Exit -> [Exit] -> P.Doc
48+toDoc :: Exit -> [Exit] -> D.Doc
4949toDoc e es =
5050 let
5151 (exit, exits) = sortByTime e es
5252 in
53− P.vcat (toDocHelp exit exits)
53+ D.vcat (toDocHelp exit exits)
5454
5555
56−toDocHelp :: Exit -> [Exit] -> [P.Doc]
56+toDocHelp :: Exit -> [Exit] -> [D.Doc]
5757toDocHelp e1 exits =
5858 case exits of
5959 [] ->
@@ -63,23 +63,23 @@ toDocHelp e1 exits =
6363 exitToDoc e1 : separator (_name e1) (_name e2) : toDocHelp e2 otherErrors
6464
6565
66−exitToDoc :: Exit -> P.Doc
66+exitToDoc :: Exit -> D.Doc
6767exitToDoc (Exit _name path _time source errors) =
6868 Compiler.errorsToDoc path source errors
6969
7070
71−separator :: Module.Raw -> Module.Raw -> P.Doc
71+separator :: Module.Raw -> Module.Raw -> D.Doc
7272separator beforeName afterName =
7373 let
7474 before = Module.nameToString beforeName ++ " ↑ "
7575 after = " ↓ " ++ Module.nameToString afterName
7676 in
77− P.dullred $ P.vcat $
78− [ P.indent (80 - length before) (P.text before)
77+ D.dullred $ D.vcat $
78+ [ D.indent (80 - length before) (D.fromString before)
7979 , "====o======================================================================o===="
80− , P.text after
81− , P.empty
82− , P.empty
80+ , D.fromString after
81+ , D.empty
82+ , D.empty
8383 ]
8484
8585
builder/src/Reporting/Exit/Crawl.hs+34−34
@@ -13,12 +13,12 @@ import qualified Data.Char as Char
1313import qualified Data.Map as Map
1414import qualified Data.Text.Encoding as Text
1515import qualified Data.Time.Clock as Time
16−import qualified Text.PrettyPrint.ANSI.Leijen as P
17−import Text.PrettyPrint.ANSI.Leijen ((<+>), (<>))
1816
1917import qualified Elm.Compiler as Compiler
2018import qualified Elm.Compiler.Module as Module
2119import qualified Elm.Package as Pkg
20+import Reporting.Doc ((<+>), (<>))
21+import qualified Reporting.Doc as D
2222import qualified Reporting.Exit.Compile as Compile
2323import qualified Reporting.Exit.Help as Help
2424
@@ -65,18 +65,18 @@ toReport exit =
6565 RootFileNotFound path ->
6666 Help.report "FILE NOT FOUND" Nothing
6767 "You want me to compile this file:"
68− [ P.indent 4 $ P.dullyellow $ P.text path
68+ [ D.indent 4 $ D.dullyellow $ D.fromString path
6969 , "I cannot find it though! Is there a typo?"
7070 ]
7171
7272 RootModuleNameDuplicate name paths ->
7373 Help.report "DUPLICATE NAMES" Nothing
7474 "I am trying to compile multiple modules with the same name:"
75− [ P.indent 4 $ P.dullyellow $ P.vcat $
76− map P.text paths
77− , P.fillSep $
75+ [ D.indent 4 $ D.dullyellow $ D.vcat $
76+ map D.fromString paths
77+ , D.fillSep $
7878 [ "These", "modules", if length paths == 2 then "both" else "all", "claim"
79− , "to", "be", "named", P.dullyellow (P.text (Module.nameToString name)) <> "."
79+ , "to", "be", "named", D.dullyellow (D.fromString (Module.nameToString name)) <> "."
8080 , "Change", "them", "to", "have", "unique", "names", "and", "you"
8181 , "should", "be", "all", "set!"
8282 ]
@@ -97,8 +97,8 @@ toReport exit =
9797 BadKernelHeader filePath ->
9898 Help.report "BAD KERNEL HEADER" Nothing
9999 "I ran into a bad header in this file:"
100− [ P.indent 4 $ P.dullyellow $ P.text filePath
101− , Help.reflow $
100+ [ D.indent 4 $ D.dullyellow $ D.fromString filePath
101+ , D.reflow $
102102 "NOTE: Kernel code is only available to core Elm libraries to ensure\
103103 \ the portability and security of the Elm ecosystem. This restriction\
104104 \ also makes it possible to improve code gen (i.e. performance) without\
@@ -133,9 +133,9 @@ problemToReport problem =
133133 Help.report "MODULE NAME MISMATCH" (Just path)
134134 ( "The file at " ++ path ++ " has a typo in the module name. It says:"
135135 )
136− [ P.indent 4 $ P.dullyellow $ "module" <+> P.red (P.text (Module.nameToString actual)) <+> "exposing (..)"
136+ [ D.indent 4 $ D.dullyellow $ "module" <+> D.red (D.fromString (Module.nameToString actual)) <+> "exposing (..)"
137137 , "Looks like a typo or copy/paste error. Instead it needs to say:"
138− , P.indent 4 $ P.dullyellow $ "module" <+> P.green (P.text (Module.nameToString expected)) <+> "exposing (..)"
138+ , D.indent 4 $ D.dullyellow $ "module" <+> D.green (D.fromString (Module.nameToString expected)) <+> "exposing (..)"
139139 , "Make the change and you should be all set!"
140140 ]
141141
@@ -159,16 +159,16 @@ badTagToDoc path name tag hintName summary =
159159 ("UNEXPECTED " ++ map Char.toUpper tag ++ " MODULE")
160160 (Just path)
161161 summary
162− [ P.fillSep $
162+ [ D.fillSep $
163163 [ "Get", "rid", "of", "all", "the"
164− , P.red (P.text tag)
164+ , D.red (D.fromString tag)
165165 , "stuff", "in"
166− , P.dullyellow (P.text (Module.nameToString name))
166+ , D.dullyellow (D.fromString (Module.nameToString name))
167167 , "to", "proceed."
168168 ]
169− , Help.note $
169+ , D.toSimpleNote $
170170 "You can learn the reasoning behind this design choice at "
171− ++ Help.hintLink hintName
171+ ++ D.makeLink hintName
172172 ]
173173
174174
@@ -182,11 +182,11 @@ namelessToDoc path name =
182182 ( "The `" ++ Module.nameToString name
183183 ++ "` module must start with a line like this:"
184184 )
185− [ P.indent 4 $ P.dullyellow $ P.text $
185+ [ D.indent 4 $ D.dullyellow $ D.fromString $
186186 "module " ++ Module.nameToString name ++ " exposing (..)"
187− , Help.reflow $
187+ , D.reflow $
188188 "Try adding that as the first line of your file!"
189− , Help.note $
189+ , D.toSimpleNote $
190190 "It is best to replace (..) with an explicit list of types and\
191191 \ functions you want to expose. If you know a value is only used\
192192 \ WITHIN this module, it is extra easy to refactor. This kind of\
@@ -200,8 +200,8 @@ notFoundToDoc origin child dirs =
200200 ElmJson ->
201201 Help.report "MODULE NOT FOUND" (Just "elm.json")
202202 "Your elm.json says your project has the following module:"
203− [ P.indent 4 $ P.red $ P.text $ Module.nameToString child
204− , Help.reflow $
203+ [ D.indent 4 $ D.red $ D.fromString $ Module.nameToString child
204+ , D.reflow $
205205 "When creating packages, all modules must live in the\
206206 \ src/ directory, but I cannot find it there."
207207 ]
@@ -217,20 +217,20 @@ notFoundToDoc origin child dirs =
217217 (notFoundDetails child dirs)
218218
219219
220−notFoundDetails :: Module.Raw -> [FilePath] -> [P.Doc]
220+notFoundDetails :: Module.Raw -> [FilePath] -> [D.Doc]
221221notFoundDetails child dirs =
222222 let
223223 simulatedCode =
224− P.indent 4 $ P.red $ P.text $ "import " ++ Module.nameToString child
224+ D.indent 4 $ D.red $ D.fromString $ "import " ++ Module.nameToString child
225225 in
226226 case Map.lookup child Pkg.suggestions of
227227 Just pkg ->
228228 [ simulatedCode
229− , Help.reflow $
229+ , D.reflow $
230230 "Do you want the one from the " ++ Pkg.toString pkg
231231 ++ " package? If so, run this command to add that dependency to your elm.json file:"
232− , P.indent 4 $ P.green $ P.text $ "elm install " ++ Pkg.toString pkg
233− , Help.reflow $
232+ , D.indent 4 $ D.green $ D.fromString $ "elm install " ++ Pkg.toString pkg
233+ , D.reflow $
234234 "If you want a local file, make sure the directory that contains the `"
235235 ++ Module.nameToString child
236236 ++ "` module is listed in your elm.json \"source-directories\" field."
@@ -239,7 +239,7 @@ notFoundDetails child dirs =
239239 Nothing ->
240240 [ simulatedCode
241241 , "I cannot find that module! Is there a typo in the module name?"
242− , Help.reflow $
242+ , D.reflow $
243243 case dirs of
244244 [] ->
245245 "The \"source-directories\" field of your elm.json is empty, so I only\
@@ -263,12 +263,12 @@ ambiguousToDoc origin child paths pkgs =
263263
264264 makeReport maybePath summary yellowString =
265265 Help.report "AMBIGUOUS IMPORT" maybePath summary
266− [ P.indent 4 $ P.dullyellow $ P.text yellowString
267− , Help.reflow $
266+ [ D.indent 4 $ D.dullyellow $ D.fromString yellowString
267+ , D.reflow $
268268 "I found multiple module with that name though:"
269− , P.indent 4 $ P.dullyellow $ P.vcat $
270− map P.text $ paths ++ map pkgToString pkgs
271− , Help.reflow $
269+ , D.indent 4 $ D.dullyellow $ D.vcat $
270+ map D.fromString $ paths ++ map pkgToString pkgs
271+ , D.reflow $
272272 if null paths then
273273 "It looks like the name clash is in your dependencies, which is\
274274 \ out of your control. Elm does not support this scenario right\
@@ -319,8 +319,8 @@ kernelNameToDoc origin kernelName =
319319 )
320320 in
321321 Help.report "BAD MODULE NAME" maybePath statement
322− [ P.indent 4 $ P.dullyellow $ P.text $ Module.nameToString kernelName
323− , Help.reflow $
322+ [ D.indent 4 $ D.dullyellow $ D.fromString $ Module.nameToString kernelName
323+ , D.reflow $
324324 "But names like that are reserved for internal use.\
325325 \ Switch to a name outside of the Elm/Kernel/ namespace."
326326 ]
builder/src/Reporting/Exit/Deps.hs+18−19
@@ -6,12 +6,11 @@ module Reporting.Exit.Deps
66 where
77
88
9−import Text.PrettyPrint.ANSI.Leijen ((<>))
10−import qualified Text.PrettyPrint.ANSI.Leijen as P
11−
129import qualified Elm.Compiler as Compiler
1310import qualified Elm.Package as Pkg
1411import qualified Elm.Project.Constraint as Con
12+import Reporting.Doc ((<>))
13+import qualified Reporting.Doc as D
1514import qualified Reporting.Exit.Help as Help
1615
1716
@@ -40,8 +39,8 @@ toReport exit =
4039 Help.report "CORRUPT CACHE" Nothing
4140 ( "I ran into an unknown package while exploring dependencies:"
4241 )
43− [ P.indent 4 $ P.dullyellow $ P.text $ Pkg.toString pkg
44− , Help.reflow $
42+ [ D.indent 4 $ D.dullyellow $ D.fromString $ Pkg.toString pkg
43+ , D.reflow $
4544 "This suggests that your ELM_HOME directory has been corrupted.\
4645 \ Maybe some program is messing with it? It is just cached files,\
4746 \ so you can delete it and see if that fixes the issue."
@@ -49,25 +48,25 @@ toReport exit =
4948
5049 PackageNotFound package suggestions ->
5150 Help.docReport "PACKAGE NOT FOUND" Nothing
52− ( P.fillSep
51+ ( D.fillSep
5352 ["I","cannot","find","a"
54− ,P.red (P.text (Pkg.toString package))
53+ ,D.red (D.fromString (Pkg.toString package))
5554 ,"package","on","the","package","website."
5655 ]
5756 )
5857 [ "Maybe you want one of these instead?"
59− , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
58+ , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromString . Pkg.toString) suggestions
6059 , "But check <https://package.elm-lang.org> to see all possibilities!"
6160 ]
6261
6362 AppBadElm version ->
6463 Help.report "ELM VERSION MISMATCH" Nothing
6564 "Your elm.json says this application needs a different version of Elm."
66− [ P.fillSep
65+ [ D.fillSep
6766 [ "It", "requires"
68− , P.green (P.text (Pkg.versionToString version)) <> ","
67+ , D.green (D.fromString (Pkg.versionToString version)) <> ","
6968 , "but", "you", "are", "using"
70− , P.red (P.text (Pkg.versionToString Compiler.version))
69+ , D.red (D.fromString (Pkg.versionToString Compiler.version))
7170 , "right", "now."
7271 ]
7372 ]
@@ -75,10 +74,10 @@ toReport exit =
7574 PkgBadElm constraint ->
7675 Help.report "ELM VERSION MISMATCH" Nothing
7776 "Your elm.json says this package needs a version of Elm in this range:"
78− [ P.indent 4 $ P.dullyellow $ P.text $ Con.toString constraint
79− , P.fillSep
77+ [ D.indent 4 $ D.dullyellow $ D.fromString $ Con.toString constraint
78+ , D.fillSep
8079 [ "But", "you", "are", "using", "Elm"
81− , P.red (P.text (Pkg.versionToString Compiler.version))
80+ , D.red (D.fromString (Pkg.versionToString Compiler.version))
8281 , "right", "now."
8382 ]
8483 ]
@@ -86,11 +85,11 @@ toReport exit =
8685 BadDeps ->
8786 Help.report "CLASHING PACKAGE DEPENDENCIES" Nothing
8887 "The dependencies in your elm.json are not compatible."
89− [ Help.reflow $
88+ [ D.reflow $
9089 "Did you change them by hand? Try to change it back! It is much\
9190 \ better to add dependencies with commands like this:"
92− , P.indent 4 $ P.dullyellow $ P.text $ "elm install elm-lang/http"
93− , Help.reflow $
91+ , D.indent 4 $ D.dullyellow "elm install elm-lang/http"
92+ , D.reflow $
9493 "Please ask for help on the Elm slack <http://elmlang.herokuapp.com/> if\
9594 \ you are running into something that seems trickier than this."
9695 ]
@@ -98,8 +97,8 @@ toReport exit =
9897 BuildFailure pkg vsn ->
9998 Help.report "CORRUPT DEPENDENCY" Nothing
10099 "I ran into a problem while building the following package:"
101− [ P.indent 4 $ P.dullyellow $ P.text $ Pkg.toString pkg ++ " " ++ Pkg.versionToString vsn
102− , Help.reflow $
100+ [ D.indent 4 $ D.dullyellow $ D.fromString $ Pkg.toString pkg ++ " " ++ Pkg.versionToString vsn
101+ , D.reflow $
103102 "This probably means the downloaded files got corrupted somehow.\
104103 \ Maybe try deleting your ELM_HOME and see if that resolves the issue?"
105104 ]
builder/src/Reporting/Exit/Diff.hs+9−8
@@ -5,10 +5,11 @@ module Reporting.Exit.Diff
55 )
66 where
77
8+
89import qualified Data.List as List
9−import qualified Text.PrettyPrint.ANSI.Leijen as P
1010
1111import qualified Elm.Package as Pkg
12+import qualified Reporting.Doc as D
1213import qualified Reporting.Exit.Help as Help
1314
1415
@@ -33,32 +34,32 @@ toReport exit =
3334 Help.report "CANNOT DIFF APPLICATIONS" Nothing
3435 "I cannot perform diffs on applications, only packages! If you are\
3536 \ just curious to see a diff, try running this command:"
36− [ P.indent 4 $ P.green $ "elm diff elm-lang/html 5.1.1 6.0.0"
37+ [ D.indent 4 $ D.green $ "elm diff elm-lang/html 5.1.1 6.0.0"
3738 ]
3839
3940 UnknownPackage pkg suggestions ->
4041 Help.report "UNKNOWN PACKAGE" Nothing
4142 ( "I cannot find a package called:"
4243 )
43− [ P.indent 4 $ P.red $ P.text $ Pkg.toString pkg
44+ [ D.indent 4 $ D.red $ D.fromText $ Pkg.toText pkg
4445 , "Maybe you want one of these instead?"
45− , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
46+ , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromText . Pkg.toText) suggestions
4647 , "But check <https://package.elm-lang.org> to see all possibilities!"
4748 ]
4849
4950 UnknownVersion _pkg vsn realVersions ->
5051 Help.docReport "UNKNOWN VERSION" Nothing
51− ( P.fillSep $
52− [ "Version", P.red (P.text (Pkg.versionToString vsn))
52+ ( D.fillSep $
53+ [ "Version", D.red (D.fromText (Pkg.versionToText vsn))
5354 , "has", "never", "been", "published,", "so", "I"
5455 , "cannot", "diff", "against", "it."
5556 ]
5657 )
5758 [ "Here are all the versions that HAVE been published:"
58− , P.indent 4 $ P.dullyellow $ P.vcat $
59+ , D.indent 4 $ D.dullyellow $ D.vcat $
5960 let
6061 sameMajor v1 v2 = Pkg._major v1 == Pkg._major v2
61− mkRow vsns = P.hsep $ map (P.text . Pkg.versionToString) vsns
62+ mkRow vsns = D.hsep $ map (D.fromText . Pkg.versionToText) vsns
6263 in
6364 map mkRow $ List.groupBy sameMajor (List.sort realVersions)
6465 , "Want one of those instead?"
builder/src/Reporting/Exit/Help.hs+20−72
@@ -7,10 +7,6 @@ module Reporting.Exit.Help
77 , compilerReport
88 , reportToDoc
99 , reportToJson
10− , hintLink
11− , stack
12− , reflow
13− , note
1410 , toString
1511 , toStdout
1612 , toStderr
@@ -18,16 +14,13 @@ module Reporting.Exit.Help
1814 where
1915
2016
21−import qualified Data.List as List
2217import qualified Data.Text as Text
2318import GHC.IO.Handle (hIsTerminalDevice)
2419import System.IO (Handle, hPutStr, stderr, stdout)
25−import qualified Text.PrettyPrint.ANSI.Leijen as P
26−import Text.PrettyPrint.ANSI.Leijen ((<>),(<+>))
2720
28−import qualified Elm.Compiler as Compiler
29−import qualified Elm.Package as Pkg
3021import qualified Json.Encode as Encode
22+import Reporting.Doc ((<+>))
23+import qualified Reporting.Doc as D
3124import qualified Reporting.Exit.Compile as Compile
3225
3326
@@ -40,21 +33,21 @@ data Report
4033 | Report
4134 { _title :: String
4235 , _path :: Maybe FilePath
43− , _message :: P.Doc
36+ , _message :: D.Doc
4437 }
4538
4639
47−report :: String -> Maybe FilePath -> String -> [P.Doc] -> Report
40+report :: String -> Maybe FilePath -> String -> [D.Doc] -> Report
4841report title path startString others =
49− Report title path $ stack (reflow startString:others)
42+ Report title path $ D.stack (D.reflow startString:others)
5043
5144
52−docReport :: String -> Maybe FilePath -> P.Doc -> [P.Doc] -> Report
45+docReport :: String -> Maybe FilePath -> D.Doc -> [D.Doc] -> Report
5346docReport title path startDoc others =
54− Report title path $ stack (startDoc:others)
47+ Report title path $ D.stack (startDoc:others)
5548
5649
57−jsonReport :: String -> Maybe FilePath -> P.Doc -> Report
50+jsonReport :: String -> Maybe FilePath -> D.Doc -> Report
5851jsonReport =
5952 Report
6053
@@ -68,7 +61,7 @@ compilerReport =
6861-- TO DOC
6962
7063
71−reportToDoc :: Report -> P.Doc
64+reportToDoc :: Report -> D.Doc
7265reportToDoc report_ =
7366 case report_ of
7467 CompilerReport e es ->
@@ -88,10 +81,10 @@ reportToDoc report_ =
8881 makeDashes (5 + length title + length path) ++ " " ++ path
8982
9083 errorBar =
91− P.dullcyan $
92− "--" <+> P.text title <+> P.text errorBarEnd
84+ D.dullcyan $
85+ "--" <+> D.fromString title <+> D.fromString errorBarEnd
9386 in
94− stack [errorBar, message, ""]
87+ D.stack [errorBar, message, ""]
9588
9689
9790
@@ -108,81 +101,36 @@ reportToJson report_ =
108101 ]
109102
110103 Report title maybePath message ->
111− let
112− messageString =
113− P.displayS (P.renderPretty 1 80 message) ""
114− in
115104 Encode.object
116105 [ ("type", Encode.text "error")
117106 , ("path", maybe Encode.null (Encode.text . Text.pack) maybePath)
118107 , ("title", Encode.text (Text.pack title))
119− , ("message", Encode.text (Text.pack messageString))
108+ , ("message", D.encode message)
120109 ]
121110
122111
123112
124−-- HINT LINKS
125−
126−
127−hintLink :: String -> String
128−hintLink hintName =
129− "<https://github.com/elm-lang/elm-compiler/blob/"
130− ++ Pkg.versionToString Compiler.version
131− ++ "/hints/" ++ hintName ++ ".md>"
132−
133−
134−
135−-- HELPERS
136−
137−
138−stack :: [P.Doc] -> P.Doc
139−stack allDocs =
140− case allDocs of
141− [] ->
142− error "Do not use `stack` on empty lists."
143−
144− doc : docs ->
145− List.foldl' verticalAppend doc docs
146−
147−
148−verticalAppend :: P.Doc -> P.Doc -> P.Doc
149−verticalAppend a b =
150− a <> P.hardline <> P.hardline <> b
151−
152−
153−reflow :: String -> P.Doc
154−reflow paragraph =
155− P.fillSep (map P.text (words paragraph))
156−
157−
158−note :: String -> P.Doc
159−note details =
160− P.fillSep $
161− (P.underline "Note" <> ":") : map P.text (words details)
162−
163−
164−
165113-- OUTPUT
166114
167115
168−toString :: P.Doc -> String
169−toString doc =
170− P.displayS (P.renderPretty 1 80 (P.plain doc)) ""
116+toString :: D.Doc -> String
117+toString =
118+ D.toString
171119
172120
173−toStdout :: P.Doc -> IO ()
121+toStdout :: D.Doc -> IO ()
174122toStdout doc =
175123 toHandle stdout doc
176124
177125
178−toStderr :: P.Doc -> IO ()
126+toStderr :: D.Doc -> IO ()
179127toStderr doc =
180128 toHandle stderr doc
181129
182130
183−toHandle :: Handle -> P.Doc -> IO ()
131+toHandle :: Handle -> D.Doc -> IO ()
184132toHandle handle doc =
185133 do isTerminal <- hIsTerminalDevice handle
186134 if isTerminal
187− then P.displayIO handle (P.renderPretty 1 80 doc)
135+ then D.toAnsi handle doc
188136 else hPutStr handle (toString doc)
builder/src/Reporting/Exit/Http.hs+16−16
@@ -9,9 +9,9 @@ module Reporting.Exit.Http
99
1010
1111import qualified Data.Text as Text
12−import Text.PrettyPrint.ANSI.Leijen ((<>))
13−import qualified Text.PrettyPrint.ANSI.Leijen as P
1412
13+import Reporting.Doc ((<>))
14+import qualified Reporting.Doc as D
1515import qualified Reporting.Exit.Help as Help
1616
1717
@@ -21,7 +21,7 @@ import qualified Reporting.Exit.Help as Help
2121
2222data Exit
2323 = Unknown String
24− | BadJson String P.Doc
24+ | BadJson String D.Doc
2525 | BadZipData
2626 | BadZipSha String String
2727
@@ -34,15 +34,15 @@ toReport :: String -> Exit -> Help.Report
3434toReport url exit =
3535 let
3636 urlDoc =
37− P.indent 4 $ P.dullyellow $ "<" <> P.text url <> ">"
37+ D.indent 4 $ D.dullyellow $ "<" <> D.fromString url <> ">"
3838 in
3939 case exit of
4040 Unknown message ->
4141 Help.report "HTTP PROBLEM" Nothing "The following HTTP request failed:"
4242 [ urlDoc
43− , Help.stack
43+ , D.stack
4444 [ "Here is the error message I was able to extract:"
45− , P.indent 4 $ Help.reflow message
45+ , D.indent 4 $ D.reflow message
4646 ]
4747 ]
4848
@@ -52,7 +52,7 @@ toReport url exit =
5252 BadZipData ->
5353 Help.report "CORRUPT ZIP" Nothing "I could not unzip the file downloaded from:"
5454 [ urlDoc
55− , Help.reflow $
55+ , D.reflow $
5656 "If it is a transient issue, it should be fixed if you try this\
5757 \ again. If it seems like an Elm problem, please report it though!"
5858 ]
@@ -60,10 +60,10 @@ toReport url exit =
6060 BadZipSha expectedHash actualHash ->
6161 Help.report "CORRUPT ZIP" Nothing "I got an unexpected zip file from:"
6262 [ urlDoc
63− , Help.reflow $
63+ , D.reflow $
6464 "I was expecting the hash of content to be " ++ expectedHash
6565 ++ ", but it is " ++ actualHash
66− , Help.reflow $
66+ , D.reflow $
6767 "Most likely the package author may have moved the version\
6868 \ tag, so report it to them and see if that is the issue."
6969 ]
@@ -79,23 +79,23 @@ data BadJson
7979 | BadAllVsn Text.Text
8080
8181
82−badJsonToDocs :: BadJson -> [P.Doc]
82+badJsonToDocs :: BadJson -> [D.Doc]
8383badJsonToDocs badJson =
8484 case badJson of
8585 BadNewPkg txt ->
86− ["I","ran","into",P.red (P.text (show txt)) <> ","
86+ ["I","ran","into",D.red (D.fromString (show txt)) <> ","
8787 ,"but","I","need","entries","like"
88− ,P.green "\"elm-lang/core@6.0.0\"" <> "."
88+ ,D.green "\"elm-lang/core@6.0.0\"" <> "."
8989 ]
9090
9191 BadAllPkg txt suggestion ->
92− ["The",P.red (P.text (show txt)),"value","is","not","a","valid","package","name."
92+ ["The",D.red (D.fromString (show txt)),"value","is","not","a","valid","package","name."
9393 ]
94− ++ map P.text (words suggestion)
94+ ++ map D.fromString (words suggestion)
9595
9696 BadAllVsn txt ->
97− ["You","provided",P.red (P.text (show txt))
97+ ["You","provided",D.red (D.fromString (show txt))
9898 ,"which","is","not","a","valid","version.","I","need","something","like"
99− ,P.green "\"1.0.0\"","or",P.green "\"2.0.4\"" <> "."
99+ ,D.green "\"1.0.0\"","or",D.green "\"2.0.4\"" <> "."
100100 ]
101101
builder/src/Reporting/Exit/Publish.hs+45−46
@@ -6,11 +6,10 @@ module Reporting.Exit.Publish
66 where
77
88
9−import qualified Text.PrettyPrint.ANSI.Leijen as P
10−import Text.PrettyPrint.ANSI.Leijen ((<>))
11−
129import Deps.Diff (Magnitude, magnitudeToString)
1310import qualified Elm.Package as Pkg
11+import Reporting.Doc ((<>))
12+import qualified Reporting.Doc as D
1413import qualified Reporting.Exit.Help as Help
1514
1615
@@ -46,52 +45,52 @@ toReport exit =
4645
4746 NotInitialVersion vsn ->
4847 Help.docReport "INVALID VERSION" Nothing
49− ( P.fillSep
48+ ( D.fillSep
5049 ["I","cannot","publish"
51− ,P.red (P.text (Pkg.versionToString vsn))
50+ ,D.red (D.fromString (Pkg.versionToString vsn))
5251 ,"as","the","initial","version."
5352 ]
5453 )
55− [ P.fillSep
56− ["Change","it","to",P.green "1.0.0","which","is"
54+ [ D.fillSep
55+ ["Change","it","to",D.green "1.0.0","which","is"
5756 ,"the","initial","version","for","all","Elm","packages."
5857 ]
5958 ]
6059
6160 AlreadyPublished vsn ->
6261 Help.docReport "ALREADY PUBLISHED" Nothing
63− ( P.vcat
64− [ P.fillSep
65− [ "Version", P.green (P.text (Pkg.versionToString vsn))
62+ ( D.vcat
63+ [ D.fillSep
64+ [ "Version", D.green (D.fromString (Pkg.versionToString vsn))
6665 , "has", "already", "been", "published.", "You", "cannot"
6766 , "publish", "it", "again!"
6867 ]
6968 , "Try using the `bump` command:"
7069 ]
7170 )
72− [ P.dullyellow $ P.indent 4 $ P.text "elm bump"
73− , Help.reflow $
71+ [ D.dullyellow $ D.indent 4 "elm bump"
72+ , D.reflow $
7473 "It computes the version number based on API changes, ensuring\
7574 \ that no breaking changes end up in PATCH releases!"
7675 ]
7776
7877 InvalidBump statedVersion latestVersion ->
7978 Help.docReport "INVALID VERSION" (Just "elm.json")
80− ( P.fillSep $
79+ ( D.fillSep $
8180 ["Your","elm.json","says","the","next","version","should","be"
82− ,P.red (P.text (Pkg.versionToString statedVersion)) <> ","
81+ ,D.red (D.fromString (Pkg.versionToString statedVersion)) <> ","
8382 ,"but","that","is","not","valid","based","on","the","previously"
8483 ,"published","versions."
8584 ]
8685 )
87− [ P.fillSep $
86+ [ D.fillSep $
8887 ["Change","the","version","back","to"
89− ,P.green (P.text (Pkg.versionToString latestVersion))
88+ ,D.green (D.fromString (Pkg.versionToString latestVersion))
9089 ,"which","is","the","most","recently","published","version."
9190 ,"From","there,","have","Elm","bump","the","version","by","running:"
9291 ]
93− , P.indent 4 $ P.green "elm bump"
94− , Help.reflow $
92+ , D.indent 4 $ D.green "elm bump"
93+ , D.reflow $
9594 "If you want more insight on the API changes Elm detects, you\
9695 \ can run `elm diff` at this point as well."
9796 ]
@@ -99,51 +98,51 @@ toReport exit =
9998 BadBump old new magnitude realNew realMagnitude ->
10099 Help.docReport "INVALID VERSION" (Just "elm.json")
101100 (
102− P.fillSep $
101+ D.fillSep $
103102 ["Your","elm.json","says","the","next","version","should","be"
104− ,P.red (P.text (Pkg.versionToString new)) <> ","
105− ,"indicating","a",P.text (magnitudeToString magnitude)
103+ ,D.red (D.fromString (Pkg.versionToString new)) <> ","
104+ ,"indicating","a",D.fromString (magnitudeToString magnitude)
106105 ,"change","to","the","public","API."
107106 ,"This","does","not","match","the","API","diff","given","by:"
108107 ]
109108 )
110− [ P.indent 4 $ P.text $
109+ [ D.indent 4 $ D.fromString $
111110 "elm diff " ++ Pkg.versionToString old
112111
113− , P.fillSep $
112+ , D.fillSep $
114113 ["This","command","says","this","is","a"
115− ,P.text (magnitudeToString realMagnitude)
114+ ,D.fromString (magnitudeToString realMagnitude)
116115 ,"change,","so","the","next","version","should","be"
117− ,P.green (P.text (Pkg.versionToString realNew)) <> "."
116+ ,D.green (D.fromString (Pkg.versionToString realNew)) <> "."
118117 ,"Double","check","everything","to","make","sure","you"
119118 ,"are","publishing","what","you","want!"
120119 ]
121− , Help.reflow $
120+ , D.reflow $
122121 "Also, next time use `elm bump` and I'll figure all this out for you!"
123122 ]
124123
125124 NoSummary ->
126125 Help.docReport "NO SUMMARY" (Just "elm.json")
127− ( P.fillSep $
126+ ( D.fillSep $
128127 [ "To", "publish", "a", "package,", "your", "elm.json", "must"
129− , "have", "a", P.dullyellow "\"summary\"", "field", "that", "gives"
128+ , "have", "a", D.dullyellow "\"summary\"", "field", "that", "gives"
130129 , "a", "consice", "overview", "of", "your", "project."
131130 ]
132131 )
133− [ Help.reflow $
132+ [ D.reflow $
134133 "The summary must be less than 80 characters. It should describe\
135134 \ the concrete use of your package as clearly and as plainly as possible."
136135 ]
137136
138137 NoExposed ->
139138 Help.docReport "NO EXPOSED MODULES" (Just "elm.json")
140− ( P.fillSep $
139+ ( D.fillSep $
141140 [ "To", "publish", "a", "package,", "the"
142− , P.dullyellow "\"exposed-modules\"", "field", "of", "your"
141+ , D.dullyellow "\"exposed-modules\"", "field", "of", "your"
143142 , "elm.json", "must", "list", "at", "least", "one", "module."
144143 ]
145144 )
146− [ Help.reflow $
145+ [ D.reflow $
147146 "What is the point of a package that has no modules?!"
148147 ]
149148
@@ -162,7 +161,7 @@ toReport exit =
162161 "By publishing a package you are inviting the Elm community to build\
163162 \ upon your work. But without knowing your license, we have no idea if\
164163 \ that is legal!"
165− [ Help.reflow $
164+ [ D.reflow $
166165 "Once you pick an OSI approved license from <https://spdx.org/licenses/>,\
167166 \ you must share that choice in two places. First, the license\
168167 \ identifier must appear in your elm.json file. Second, the full\
@@ -173,16 +172,16 @@ toReport exit =
173172 MissingTag version ->
174173 let vsn = Pkg.versionToString version in
175174 Help.docReport "NO TAG" Nothing
176− ( P.fillSep $
175+ ( D.fillSep $
177176 [ "Packages", "must", "be", "tagged", "in", "git,", "but", "I"
178− , "cannot", "find", "a", P.green (P.text vsn), "tag."
177+ , "cannot", "find", "a", D.green (D.fromString vsn), "tag."
179178 ]
180179 )
181− [ P.vcat
180+ [ D.vcat
182181 [ "These tags make it possible to find this specific version on GitHub."
183182 , "To tag the most recent commit and push it to GitHub, run this:"
184183 ]
185− , P.indent 4 $ P.dullyellow $ P.vcat $ map P.text $
184+ , D.indent 4 $ D.dullyellow $ D.vcat $ map D.fromString $
186185 [ "git tag -a alpha-" ++ vsn ++ " -m \"preparing for Elm 0.19\""
187186 , "git push origin alpha-" ++ vsn
188187 ]
@@ -193,27 +192,27 @@ toReport exit =
193192 Help.report "NO GIT" Nothing
194193 "I searched your PATH environment variable for `git` and could not\
195194 \ find it. Is it available through your PATH?"
196− [ Help.reflow $
195+ [ D.reflow $
197196 "Who cares about this? Well, I currently use `git` to check if there\
198197 \ are any local changes in your code. Local changes are a good sign\
199198 \ that some important improvements have gotten mistagged, so this\
200199 \ check can be extremely helpful for package authors!"
201− , Help.note $
200+ , D.toSimpleNote $
202201 "We plan to do this without the `git` binary in a future release."
203202 ]
204203
205204 LocalChanges version ->
206205 let vsn = Pkg.versionToString version in
207206 Help.docReport "LOCAL CHANGES" Nothing
208− ( P.fillSep $
209− [ "The", "code", "tagged", "as", P.green (P.text vsn), "in"
207+ ( D.fillSep $
208+ [ "The", "code", "tagged", "as", D.green (D.fromString vsn), "in"
210209 , "git", "does", "not", "match", "the", "code", "in", "your"
211210 , "working", "directory.", "This", "means", "you", "have"
212211 , "commits", "or", "local", "changes", "that", "are", "not"
213212 , "going", "to", "be", "published!"
214213 ]
215214 )
216− [ Help.note $
215+ [ D.toSimpleNote $
217216 "If you are sure everything is in order, you can run `git checkout "
218217 ++ vsn ++ "` and publish your code from there."
219218 ]
@@ -222,17 +221,17 @@ toReport exit =
222221badReadmeReport :: String -> String -> Help.Report
223222badReadmeReport title summary =
224223 Help.report title (Just "README.md") summary
225− [ Help.reflow $
224+ [ D.reflow $
226225 "When people look at your README, they are wondering:"
227− , P.vcat
226+ , D.vcat
228227 [ " - What does this package even do?"
229228 , " - Will it help me solve MY problems?"
230229 ]
231− , Help.reflow $
230+ , D.reflow $
232231 "So I recommend starting your README with a small example of the\
233232 \ most common usage scenario. Show people what they can expect if\
234233 \ they learn more!"
235− , Help.note $
234+ , D.toSimpleNote $
236235 "By publishing your package, you are inviting people to invest time\
237236 \ in understanding your work. Spending an hour to communicate your\
238237 \ knowledge more clearly can save the community days or weeks of time\
builder/src/Reporting/Progress/Terminal.hs+19−21
@@ -1,3 +1,4 @@
1+{-# LANGUAGE OverloadedStrings #-}
12module Reporting.Progress.Terminal
23 ( create
34 , newPackageOverview
@@ -10,12 +11,12 @@ import Control.Concurrent.Chan (Chan, newChan, readChan)
1011import Control.Concurrent.MVar (newEmptyMVar, putMVar)
1112import qualified System.Info as System
1213import System.IO (hFlush, hPutStr, stdout)
13−import Text.PrettyPrint.ANSI.Leijen ((<>), (<+>))
14−import qualified Text.PrettyPrint.ANSI.Leijen as P
1514import qualified Elm.Package as Pkg
1615import Elm.Package (Name, Version)
1716
1817import qualified Deps.Diff as Diff
18+import Reporting.Doc ((<>), (<+>))
19+import qualified Reporting.Doc as D
1920import qualified Reporting.Exit as Exit
2021import qualified Reporting.Exit.Help as Help
2122import Reporting.Progress (Msg(..), Progress(..), Outcome(..), PublishPhase(..), BumpPhase(..))
@@ -185,7 +186,7 @@ loopHelp chan progress state@(State total good bad) =
185186
186187 UnableToLoadLatestPackages ->
187188 do putStrLn ""
188− Help.toStdout $ P.dullyellow (P.text "WARNING:") <+> P.text "I normally check <https://package.elm-lang.org> for new packages\n"
189+ Help.toStdout $ D.dullyellow "WARNING:" <+> "I normally check <https://package.elm-lang.org> for new packages\n"
189190 putStrLn "here, but my request failed. Are you offline? I will try to continue anyway.\n"
190191 loop chan state
191192
@@ -194,38 +195,35 @@ loopHelp chan progress state@(State total good bad) =
194195-- BULLETS
195196
196197
197−makeBullet :: Name -> Version -> Outcome -> P.Doc
198+makeBullet :: Name -> Version -> Outcome -> D.Doc
198199makeBullet name version outcome =
199200 let
200− nm =
201− P.text (Pkg.toString name)
202−
203− vsn =
204− P.text (Pkg.versionToString version)
201+ nm = D.fromText (Pkg.toText name)
202+ vsn = D.fromText (Pkg.versionToText version)
205203
206204 bullet =
207205 case outcome of
208206 Good -> goodMark
209207 Bad -> badMark
210208 in
211− P.indent 2 $ bullet <+> nm <+> vsn <> P.text "\n"
209+ D.indent 2 $ bullet <+> nm <+> vsn <> "\n"
212210
213211
214−goodMark :: P.Doc
212+goodMark :: D.Doc
215213goodMark =
216− P.green $ P.text $
214+ D.green $
217215 if System.os == "mingw32" then "+" else "●"
218216
219217
220−badMark :: P.Doc
218+badMark :: D.Doc
221219badMark =
222− P.red $ P.text $
220+ D.red $
223221 if System.os == "mingw32" then "X" else "✗"
224222
225223
226−waitingMark :: P.Doc
224+waitingMark :: D.Doc
227225waitingMark =
228− P.dullyellow $ P.text $
226+ D.dullyellow $
229227 if System.os == "mingw32" then "-" else "→"
230228
231229
@@ -257,7 +255,7 @@ newPackageOverview =
257255-- CHECKLIST
258256
259257
260−toChecklistDoc :: Maybe Outcome -> ChecklistMessages -> P.Doc
258+toChecklistDoc :: Maybe Outcome -> ChecklistMessages -> D.Doc
261259toChecklistDoc status (ChecklistMessages waiting success failure) =
262260 let
263261 padded message =
@@ -265,13 +263,13 @@ toChecklistDoc status (ChecklistMessages waiting success failure) =
265263 in
266264 case status of
267265 Nothing ->
268− P.text " " <> waitingMark <+> P.text waiting
266+ " " <> waitingMark <+> D.fromString waiting
269267
270268 Just Good ->
271− P.text "\r " <> goodMark <+> P.text (padded success ++ "\n")
269+ "\r " <> goodMark <+> D.fromString (padded success ++ "\n")
272270
273271 Just Bad ->
274− P.text "\r " <> badMark <+> P.text (padded failure ++ "\n\n")
272+ "\r " <> badMark <+> D.fromString (padded failure ++ "\n\n")
275273
276274
277275data ChecklistMessages =
@@ -326,7 +324,7 @@ toChecklistMessages phase =
326324-- BUMP PHASE
327325
328326
329−bumpPhaseToChecklistDoc :: Pkg.Version -> BumpPhase -> P.Doc
327+bumpPhaseToChecklistDoc :: Pkg.Version -> BumpPhase -> D.Doc
330328bumpPhaseToChecklistDoc version bumpPhase =
331329 let
332330 mkMsgs success =
compiler/src/Json/Decode/Error.hs+13−14
@@ -11,11 +11,10 @@ import qualified Data.Char as Char
1111import qualified Data.List as List
1212import qualified Data.Map as Map
1313import qualified Data.Text as Text
14−import Text.PrettyPrint.ANSI.Leijen ((<+>), (<>))
15−import qualified Text.PrettyPrint.ANSI.Leijen as P
1614
1715import qualified Json.Decode.Internals as Json
1816import qualified Json.Encode as E
17+import Reporting.Doc ((<+>), (<>))
1918import qualified Reporting.Doc as D
2019import qualified Reporting.Error.Syntax as Syntax
2120import qualified Reporting.Render.Code as Code
@@ -57,7 +56,7 @@ toDoc rootName source userErrorToDocs err =
5756 flatErrors ->
5857 let
5958 toNumberedDoc index flatErr =
60− P.dullcyan ("(" <> P.int index <> ")") <+> flatErrorToDoc rootName [] userErrorToDocs flatErr
59+ D.dullcyan ("(" <> D.fromInt index <> ")") <+> flatErrorToDoc rootName [] userErrorToDocs flatErr
6160 in
6261 D.stack $
6362 [ D.reflow $
@@ -116,7 +115,7 @@ flatErrorToDoc rootName starter userErrorToDocs (FlatError accesses json theory
116115
117116accessToDoc :: String -> [String] -> D.Doc
118117accessToDoc rootName accesses =
119− P.dullyellow (P.text (rootName ++ concat accesses))
118+ D.dullyellow (D.fromString (rootName ++ concat accesses))
120119
121120
122121actualThing :: E.Value -> [D.Doc]
@@ -126,7 +125,7 @@ actualThing json =
126125 E.Object _ -> [D.red "object"]
127126 E.String _ -> [D.red "string"]
128127 E.Boolean b -> [D.red (if b then "true" else "false"),"value"]
129− E.Integer n -> ["number",D.red (D.fromString (show n))]
128+ E.Integer n -> ["number",D.red (D.fromInt n)]
130129 E.Number _ -> [D.red "number"]
131130 E.Null -> [D.red "null","value"]
132131
@@ -134,16 +133,16 @@ actualThing json =
134133anExpectedThing :: Json.Type -> [D.Doc]
135134anExpectedThing tipe =
136135 case tipe of
137− Json.TObject -> ["an", P.green "OBJECT" <> "."]
138− Json.TArray -> ["an", P.green "ARRAY" <> "."]
139− Json.TString -> ["a", P.green "STRING" <> "."]
140− Json.TBool -> ["a", P.green "BOOLEAN" <> "."]
141− Json.TInt -> ["an", P.green "INT" <> "."]
142− Json.TObjectWith field -> ["an",P.green "OBJECT","with","a",P.green ("\"" <> P.text (Text.unpack field) <> "\""),"field."]
136+ Json.TObject -> ["an", D.green "OBJECT" <> "."]
137+ Json.TArray -> ["an", D.green "ARRAY" <> "."]
138+ Json.TString -> ["a", D.green "STRING" <> "."]
139+ Json.TBool -> ["a", D.green "BOOLEAN" <> "."]
140+ Json.TInt -> ["an", D.green "INT" <> "."]
141+ Json.TObjectWith field -> ["an",D.green "OBJECT","with","a",D.green ("\"" <> D.fromString (Text.unpack field) <> "\""),"field."]
143142 Json.TArrayWith i len ->
144− ["a",D.green "longer",P.green "ARRAY" <> "."
145− ,"I","need","index",P.text (show i) <> ",","but","this","array"
146− ,"only","has",P.text (show len),"elements."
143+ ["a",D.green "longer",D.green "ARRAY" <> "."
144+ ,"I","need","index",D.fromInt i <> ",","but","this","array"
145+ ,"only","has",D.fromInt len,"elements."
147146 ]
148147
149148
compiler/src/Reporting/Doc.hs+52−45
@@ -3,10 +3,12 @@
33module Reporting.Doc
44 ( P.Doc
55 , (P.<+>), (<>)
6− , P.cat, P.empty, P.fillSep, P.hang, P.hcat, P.hsep, P.indent, P.sep, P.vcat
7− , P.black, P.blue, P.green, P.magenta, P.dullyellow, P.red, P.dullred
6+ , P.cat, P.empty, P.fill, P.fillSep, P.hang
7+ , P.hcat, P.hsep, P.indent, P.sep, P.vcat
8+ , P.red, P.magenta, P.green, P.blue, P.black
9+ , P.dullred, P.dullcyan, P.dullyellow
810
9− , fromString, fromText, fromName
11+ , fromString, fromText, fromName, fromInt
1012 , toAnsi, toString, toLine
1113 , encode
1214
@@ -54,6 +56,11 @@ fromName name =
5456 P.text (N.toString name)
5557
5658
59+fromInt :: Int -> P.Doc
60+fromInt n =
61+ P.text (show n)
62+
63+
5764
5865-- TO STRING
5966
@@ -65,12 +72,12 @@ toAnsi handle doc =
6572
6673toString :: P.Doc -> String
6774toString doc =
68− P.displayS (P.renderPretty 1 80 doc) ""
75+ P.displayS (P.renderPretty 1 80 (P.plain doc)) ""
6976
7077
7178toLine :: P.Doc -> String
7279toLine doc =
73− P.displayS (P.renderPretty 1 (div maxBound 2) doc) ""
80+ P.displayS (P.renderPretty 1 (div maxBound 2) (P.plain doc)) ""
7481
7582
7683
@@ -224,22 +231,22 @@ noStyle =
224231
225232
226233data Color
227− = D_Red
228− | V_Red
229− | D_Magenta
230− | V_Magenta
231− | D_Yellow
232− | V_Yellow
233− | D_Green
234− | V_Green
235− | D_Cyan
236− | V_Cyan
237− | D_Blue
238− | V_Blue
239− | D_Black
240− | V_Black
241− | D_White
242− | V_White
234+ = Red
235+ | RED
236+ | Magenta
237+ | MAGENTA
238+ | Yellow
239+ | YELLOW
240+ | Green
241+ | GREEN
242+ | Cyan
243+ | CYAN
244+ | Blue
245+ | BLUE
246+ | Black
247+ | BLACK
248+ | White
249+ | WHITE
243250
244251
245252toJsonHelp :: Style -> [TB.Builder] -> P.SimpleDoc -> [E.Value]
@@ -322,14 +329,14 @@ toColor layer intensity color =
322329 in
323330 Just $
324331 case color of
325− Ansi.Red -> pick D_Red V_Red
326− Ansi.Magenta -> pick D_Magenta V_Magenta
327− Ansi.Yellow -> pick D_Yellow V_Yellow
328− Ansi.Green -> pick D_Green V_Green
329− Ansi.Cyan -> pick D_Cyan V_Cyan
330− Ansi.Blue -> pick D_Blue V_Blue
331− Ansi.White -> pick D_White V_White
332− Ansi.Black -> pick D_Black V_Black
332+ Ansi.Red -> pick Red RED
333+ Ansi.Magenta -> pick Magenta MAGENTA
334+ Ansi.Yellow -> pick Yellow YELLOW
335+ Ansi.Green -> pick Green GREEN
336+ Ansi.Cyan -> pick Cyan CYAN
337+ Ansi.Blue -> pick Blue BLUE
338+ Ansi.White -> pick White WHITE
339+ Ansi.Black -> pick Black BLACK
333340
334341
335342encodeChunks :: Style -> [TB.Builder] -> E.Value
@@ -361,19 +368,19 @@ encodeColor :: Color -> E.Value
361368encodeColor color =
362369 E.text $
363370 case color of
364− D_Red -> "red"
365− V_Red -> "RED"
366− D_Magenta -> "magenta"
367− V_Magenta -> "MAGENTA"
368− D_Yellow -> "yellow"
369− V_Yellow -> "YELLOW"
370− D_Green -> "green"
371− V_Green -> "GREEN"
372− D_Cyan -> "cyan"
373− V_Cyan -> "CYAN"
374− D_Blue -> "blue"
375− V_Blue -> "BLUE"
376− D_Black -> "black"
377− V_Black -> "BLACK"
378− D_White -> "white"
379− V_White -> "WHITE"
371+ Red -> "red"
372+ RED -> "RED"
373+ Magenta -> "magenta"
374+ MAGENTA -> "MAGENTA"
375+ Yellow -> "yellow"
376+ YELLOW -> "YELLOW"
377+ Green -> "green"
378+ GREEN -> "GREEN"
379+ Cyan -> "cyan"
380+ CYAN -> "CYAN"
381+ Blue -> "blue"
382+ BLUE -> "BLUE"
383+ Black -> "black"
384+ BLACK -> "BLACK"
385+ White -> "white"
386+ WHITE -> "WHITE"
compiler/src/Reporting/Error/Pattern.hs+1−1
@@ -123,7 +123,7 @@ patternToDoc context pattern =
123123 D.fromText ("\"" <> str <> "\"")
124124
125125 P.Int int ->
126− D.fromString (show int)
126+ D.fromInt int
127127
128128 NonList (P.Ctor _ "#0" []) ->
129129 "()"
compiler/src/Reporting/Report.hs+34−31
@@ -8,8 +8,7 @@ module Reporting.Report
88 where
99
1010
11−import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), hardline, dullcyan, text)
12−
11+import qualified Reporting.Doc as D
1312import qualified Reporting.Region as R
1413import qualified Reporting.Render.Code as Code
1514
@@ -23,25 +22,27 @@ data Report =
2322 { _title :: String
2423 , _region :: R.Region
2524 , _sgstns :: [String]
26− , _message :: Doc
25+ , _message :: D.Doc
2726 }
2827
2928
30−toDoc :: FilePath -> Report -> Doc
29+toDoc :: FilePath -> Report -> D.Doc
3130toDoc filePath (Report title _ _ message) =
32− messageBar title filePath
33− <> hardline <> hardline <>
34− message
35− <> hardline <> hardline
31+ D.vcat
32+ [ messageBar title filePath
33+ , ""
34+ , message
35+ , ""
36+ ]
3637
3738
38−messageBar :: String -> FilePath -> Doc
39+messageBar :: String -> FilePath -> D.Doc
3940messageBar title filePath =
4041 let
4142 usedSpace =
4243 4 + length title + 1 + length filePath
4344 in
44− dullcyan $ text $
45+ D.dullcyan $ D.fromString $
4546 "-- " ++ title
4647 ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
4748 ++ " " ++ filePath
@@ -51,32 +52,34 @@ messageBar title filePath =
5152-- CODE FORMATTING
5253
5354
54−toCodeSnippet :: Code.Source -> R.Region -> Maybe R.Region -> (Doc, Doc) -> Doc
55+toCodeSnippet :: Code.Source -> R.Region -> Maybe R.Region -> (D.Doc, D.Doc) -> D.Doc
5556toCodeSnippet source region highlight (preHint, postHint) =
56− preHint
57− <> hardline <> hardline <>
58− Code.render source region highlight
59− <> hardline <>
60− postHint
57+ D.vcat
58+ [ preHint
59+ , ""
60+ , Code.render source region highlight
61+ , postHint
62+ ]
6163
6264
63−toCodePair :: Code.Source -> R.Region -> R.Region -> (Doc, Doc) -> (Doc, Doc, Doc) -> Doc
65+toCodePair :: Code.Source -> R.Region -> R.Region -> (D.Doc, D.Doc) -> (D.Doc, D.Doc, D.Doc) -> D.Doc
6466toCodePair source r1 r2 (oneStart, oneEnd) (twoStart, twoMiddle, twoEnd) =
6567 case Code.renderPair source r1 r2 of
6668 Code.OneLine codeDocs ->
67− oneStart
68− <> hardline <> hardline <>
69− codeDocs
70− <> hardline <>
71− oneEnd
69+ D.vcat
70+ [ oneStart
71+ , ""
72+ , codeDocs
73+ , oneEnd
74+ ]
7275
7376 Code.TwoChunks code1 code2 ->
74− twoStart
75− <> hardline <> hardline <>
76− code1
77− <> hardline <>
78− twoMiddle
79− <> hardline <> hardline <>
80− code2
81− <> hardline <>
82− twoEnd
77+ D.vcat
78+ [ twoStart
79+ , ""
80+ , code1
81+ , twoMiddle
82+ , ""
83+ , code2
84+ , twoEnd
85+ ]