@@ -1,5 +1,13 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2−module Reporting.Render.Code (render) where
2+module Reporting.Render.Code
4import Data.Text (Text)
12import Data.Text (Text)
5import qualified Data.Text as Text
13import qualified Data.Text as Text
@@ -10,6 +18,24 @@ import qualified Reporting.Region as R
10import qualified Reporting.Helpers as H
18import qualified Reporting.Helpers as H
26+ Source [(Int, Text.Text)]
29+toSource :: Text.Text -> Source
32+ Text.lines source ++ [Text.empty]
13(|>) :: a -> (a -> b) -> b
39(|>) :: a -> (a -> b) -> b
@@ -20,17 +46,16 @@ import qualified Reporting.Helpers as H
20 a <> hardline <> b
46 a <> hardline <> b
23−render :: Maybe R.Region -> R.Region -> Text -> Doc
49+render :: Source -> R.Region -> Maybe R.Region -> Doc
24−render maybeSubRegion region@(R.Region start end) source =
50+render (Source sourceLines) region@(R.Region start end) maybeSubRegion =
26 (R.Position startLine _) = start
52 (R.Position startLine _) = start
27 (R.Position endLine _) = end
53 (R.Position endLine _) = end
29 relevantLines =
55 relevantLines =
30− (Text.lines source ++ [Text.empty])
56+ sourceLines
32 |> drop (startLine - 1)
57 |> drop (startLine - 1)
33− |> zip [startLine .. endLine + 1]
58+ |> take (1 + endLine - startLine)
36 length (show (fst (last relevantLines)))
61 length (show (fst (last relevantLines)))
@@ -71,7 +96,7 @@ drawLines addZigZag width (R.Region start end) sourceLines finalLine =
72drawLine :: Bool -> Int -> Int -> Int -> (Int, Text) -> Doc
97drawLine :: Bool -> Int -> Int -> Int -> (Int, Text) -> Doc
73drawLine addZigZag width startLine endLine (n, line) =
98drawLine addZigZag width startLine endLine (n, line) =
74− addLineNumber addZigZag width startLine endLine n (H.text line)
99+ addLineNumber addZigZag width startLine endLine n (H.textToDoc line)
77addLineNumber :: Bool -> Int -> Int -> Int -> Int -> Doc -> Doc
102addLineNumber :: Bool -> Int -> Int -> Int -> Int -> Doc -> Doc
@@ -90,3 +115,17 @@ addLineNumber addZigZag width start end n line =
92 text lineNumber <> spacer <> line
117 text lineNumber <> spacer <> line
129+renderPair :: Source -> R.Region -> R.Region -> CodePair
130+renderPair source r1 r2 =
131+ error "TODO" source r1 r2