on 33efdcf help sign in
83 lines 1.7 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Exit.Compile
4 ( Exit(..)
5 , toJson
6 , toDoc
7 )
8 where
11import Data.List.NonEmpty (NonEmpty((:|)))
12import qualified Data.List.NonEmpty as NonEmpty
13import qualified Data.Text as Text
14import qualified Data.Time.Clock as Time
15import qualified Text.PrettyPrint.ANSI.Leijen as P
17import qualified Elm.Compiler as Compiler
18import qualified Elm.Compiler.Module as Module
19import qualified Json.Encode as Encode
23-- EXITS
26data Exit =
27 Exit
28 { _name :: Module.Raw
29 , _path :: FilePath
30 , _time :: Time.UTCTime
31 , _source :: Text.Text
32 , _errors :: [Compiler.Error]
33 }
37-- TO JSON
40toJson :: Exit -> Encode.Value
41toJson (Exit name path _ source errors) =
42 Compiler.errorsToJson name path source errors
46-- TO DOC
49toDoc :: Exit -> [Exit] -> P.Doc
50toDoc e es =
51 case NonEmpty.sortWith _time (e :| es) of
52 exit :| exits ->
53 P.vcat (toDocHelp exit exits)
56toDocHelp :: Exit -> [Exit] -> [P.Doc]
57toDocHelp e1 exits =
58 case exits of
59 [] ->
60 [exitToDoc e1]
62 e2 : otherErrors ->
63 exitToDoc e1 : separator (_name e1) (_name e2) : toDocHelp e2 otherErrors
66exitToDoc :: Exit -> P.Doc
67exitToDoc (Exit _name path _time source errors) =
68 Compiler.errorsToDoc path source errors
71separator :: Module.Raw -> Module.Raw -> P.Doc
72separator beforeName afterName =
73 let
74 before = Module.nameToString beforeName ++ " ↑ "
75 after = " ↓ " ++ Module.nameToString afterName
76 in
77 P.dullred $ P.vcat $
78 [ P.indent (80 - length before) (P.text before)
79 , "====o======================================================================o===="
80 , P.text after
81 , P.empty
82 , P.empty
83 ]