on 6a96e21 help sign in
105 lines 2.0 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Exit.Compile
4 ( Exit(..)
5 , toJson
6 , toDoc
7 )
8 where
11import qualified Data.List as List
12import qualified Data.Text as Text
13import qualified Data.Time.Clock as Time
14import qualified Text.PrettyPrint.ANSI.Leijen as P
16import qualified Elm.Compiler as Compiler
17import qualified Elm.Compiler.Module as Module
18import qualified Json.Encode as Encode
22-- EXITS
25data Exit =
26 Exit
27 { _name :: Module.Raw
28 , _path :: FilePath
29 , _time :: Time.UTCTime
30 , _source :: Text.Text
31 , _errors :: [Compiler.Error]
32 }
36-- TO JSON
39toJson :: Exit -> Encode.Value
40toJson (Exit name path _ source errors) =
41 Compiler.errorsToJson name path source errors
45-- TO DOC
48toDoc :: Exit -> [Exit] -> P.Doc
49toDoc e es =
50 let
51 (exit, exits) = sortByTime e es
52 in
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 ]
87-- SORT BY TIME
90sortByTime :: Exit -> [Exit] -> (Exit, [Exit])
91sortByTime exit exits =
92 case List.sortBy timeCompare exits of
93 [] ->
94 (exit, [])
96 e:es ->
97 if _time exit < _time e then
98 (exit, e:es)
99 else
100 (e, List.insertBy timeCompare exit es)
103timeCompare :: Exit -> Exit -> Ordering
104timeCompare e1 e2 =
105 compare (_time e1) (_time e2)