@@ -1,21 +1,17 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Report
3module Reporting.Report
4− ( Report
4+ ( Report(..)
8− , toJson
6+ , toCodeSnippet
12−import Data.Aeson ((.=))
13−import qualified Data.Aeson.Types as Json
14import qualified Data.Text as Text
11import qualified Data.Text as Text
15−import Data.Text (Text)
16−import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), displayS, dullcyan, hardline, plain, renderPretty, text)
12+import Text.PrettyPrint.ANSI.Leijen (Doc, (<>), hardline, dullcyan)
18−import qualified Reporting.Helpers as Help
14+import qualified Reporting.Helpers as H
19import qualified Reporting.Region as R
15import qualified Reporting.Region as R
20import qualified Reporting.Render.Code as Code
16import qualified Reporting.Render.Code as Code
@@ -26,67 +22,63 @@ import qualified Reporting.Render.Code as Code
27data Report =
23data Report =
29− { _title :: Text
25+ { _title :: String
30− , _highlight :: Maybe R.Region
26+ , _region :: R.Region
31− , _preHint :: Doc
27+ , _sgstns :: [Text.Text]
32− , _postHint :: Doc
28+ , _message :: Doc
36−report :: Text -> Maybe R.Region -> Text -> Doc -> Report
32+toDoc :: FilePath -> Report -> Doc
37−report title highlight pre post =
33+toDoc filePath (Report title _ _ message) =
38− Report title highlight (Help.reflowParagraph pre) post
34+ messageBar title filePath
35+ <> hardline <> hardline <>
41−reportDoc :: Text -> Maybe R.Region -> [Doc] -> Doc -> Report
39+messageBar :: String -> FilePath -> Doc
42−reportDoc title highlight pre post =
43− Report title highlight (Help.hsep pre) post
50−toJson :: [Json.Pair] -> Report -> (Maybe R.Region, [Json.Pair])
51−toJson extraFields (Report title subregion pre post) =
55− , "overview" .= nonAnsiRender pre
56− , "details" .= nonAnsiRender post
59− (subregion, fields ++ extraFields)
62−nonAnsiRender :: Doc -> String
64− displayS (renderPretty 1 80 (plain doc)) ""
71−toDoc :: String -> R.Region -> Report -> Text -> Doc
72−toDoc location region (Report title highlight preHint postHint) source =
73− messageBar title location
40+messageBar title filePath =
74− <> hardline <> hardline <>
76− <> hardline <> hardline <>
77− Code.render highlight region source
80− <> hardline <> hardline
83−messageBar :: Text -> String -> Doc
84−messageBar tag location =
86 usedSpace =
42 usedSpace =
87− 4 + Text.length tag + 1 + length location
43+ 4 + length title + 1 + length filePath
89− dullcyan $ text $
45+ dullcyan $ H.text $
90− "-- " ++ Text.unpack tag
46+ "-- " ++ title
91 ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
47 ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
92− ++ " " ++ location
48+ ++ " " ++ filePath
55+toCodeSnippet :: Code.Source -> R.Region -> Maybe R.Region -> (Doc, Doc) -> Doc
56+toCodeSnippet source region highlight (preHint, postHint) =
58+ <> hardline <> hardline <>
59+ Code.render source region highlight
62+ <> hardline <> hardline
65+toCodePair :: Code.Source -> R.Region -> R.Region -> (Doc, Doc) -> (Doc, Doc, Doc) -> Doc
66+toCodePair source r1 r2 (oneStart, oneEnd) (twoStart, twoMiddle, twoEnd) =
67+ case Code.renderPair source r1 r2 of
68+ Code.OneLine codeDocs ->
70+ <> hardline <> hardline <>
75+ Code.TwoChunks code1 code2 ->
77+ <> hardline <> hardline <>
81+ <> hardline <> hardline <>