on 2ea433c help sign in
72 lines 1.6 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Compile
4 ( Error(..)
5 , toDoc
6 )
7 where
10import Data.List.NonEmpty (NonEmpty((:|)))
11import qualified Data.List.NonEmpty as NonEmpty
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
21-- ERRORS
24data Error =
25 Error
26 { _name :: Module.Raw
27 , _path :: FilePath
28 , _time :: Time.UTCTime
29 , _source :: Text.Text
30 , _errors :: [Compiler.Error]
31 }
35-- TO DOC
38toDoc :: Error -> [Error] -> P.Doc
39toDoc e es =
40 case NonEmpty.sortWith _time (e :| es) of
41 err :| errors ->
42 P.vcat (toDocHelp err errors)
45toDocHelp :: Error -> [Error] -> [P.Doc]
46toDocHelp e1 errs =
47 case errs of
48 [] ->
49 [errorToDoc e1]
51 e2 : otherErrors ->
52 errorToDoc e1 : separator (_name e1) (_name e2) : toDocHelp e2 otherErrors
55errorToDoc :: Error -> P.Doc
56errorToDoc (Error _name path _time source errors) =
57 Compiler.errorsToDoc path source errors
60separator :: Module.Raw -> Module.Raw -> P.Doc
61separator beforeName afterName =
62 let
63 before = Module.nameToString beforeName ++ " ↑ "
64 after = " ↓ " ++ Module.nameToString afterName
65 in
66 P.dullred $ P.vcat $
67 [ P.indent (80 - length before) (P.text before)
68 , "====o======================================================================o===="
69 , P.text after
70 , P.empty
71 , P.empty
72 ]