on 42f3721 help sign in
85 lines 1.6 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Report
3 ( Report(..)
4 , toDoc
5 , toCodeSnippet
6 , toCodePair
7 )
8 where
11import qualified Reporting.Doc as D
12import qualified Reporting.Region as R
13import qualified Reporting.Render.Code as Code
17-- BUILD REPORTS
20data Report =
21 Report
22 { _title :: String
23 , _region :: R.Region
24 , _sgstns :: [String]
25 , _message :: D.Doc
26 }
29toDoc :: FilePath -> Report -> D.Doc
30toDoc filePath (Report title _ _ message) =
31 D.vcat
32 [ messageBar title filePath
33 , ""
34 , message
35 , ""
36 ]
39messageBar :: String -> FilePath -> D.Doc
40messageBar title filePath =
41 let
42 usedSpace =
43 4 + length title + 1 + length filePath
44 in
45 D.dullcyan $ D.fromString $
46 "-- " ++ title
47 ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
48 ++ " " ++ filePath
52-- CODE FORMATTING
55toCodeSnippet :: Code.Source -> R.Region -> Maybe R.Region -> (D.Doc, D.Doc) -> D.Doc
56toCodeSnippet source region highlight (preHint, postHint) =
57 D.vcat
58 [ preHint
59 , ""
60 , Code.render source region highlight
61 , postHint
62 ]
65toCodePair :: Code.Source -> R.Region -> R.Region -> (D.Doc, D.Doc) -> (D.Doc, D.Doc, D.Doc) -> D.Doc
66toCodePair source r1 r2 (oneStart, oneEnd) (twoStart, twoMiddle, twoEnd) =
67 case Code.renderPair source r1 r2 of
68 Code.OneLine codeDocs ->
69 D.vcat
70 [ oneStart
71 , ""
72 , codeDocs
73 , oneEnd
74 ]
76 Code.TwoChunks code1 code2 ->
77 D.vcat
78 [ twoStart
79 , ""
80 , code1
81 , twoMiddle
82 , ""
83 , code2
84 , twoEnd
85 ]