on 2ecbee3 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
15import qualified Elm.Compiler as Compiler
16import qualified Elm.Compiler.Module as Module
17import qualified Json.Encode as Encode
18import qualified Reporting.Doc as D
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] -> D.Doc
49toDoc e es =
50 let
51 (exit, exits) = sortByTime e es
52 in
53 D.vcat (toDocHelp exit exits)
56toDocHelp :: Exit -> [Exit] -> [D.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 -> D.Doc
67exitToDoc (Exit _name path _time source errors) =
68 Compiler.errorsToDoc path source errors
71separator :: Module.Raw -> Module.Raw -> D.Doc
72separator beforeName afterName =
73 let
74 before = Module.nameToString beforeName ++ " ↑ "
75 after = " ↓ " ++ Module.nameToString afterName
76 in
77 D.dullred $ D.vcat $
78 [ D.indent (80 - length before) (D.fromString before)
79 , "====o======================================================================o===="
80 , D.fromString after
81 , D.empty
82 , D.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)