on master help sign in
Make Render.Code exports explicit / add dummy renderPair function
3f3ff8dEvan Czaplicki
src/Reporting/Render/Code.hs+46−7
@@ -1,5 +1,13 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2−module Reporting.Render.Code (render) where
2+module Reporting.Render.Code
3+ ( Source
4+ , toSource
5+ , render
6+ , CodePair(..)
7+ , renderPair
8+ )
9+ where
10+
3
11
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
11
19
12
20
21+
22+-- CODE
23+
24+
25+newtype Source =
26+ Source [(Int, Text.Text)]
27+
28+
29+toSource :: Text.Text -> Source
30+toSource source =
31+ Source $ zip [1..] $
32+ Text.lines source ++ [Text.empty]
33+
34+
35+
36+-- RENDER
37+
38+
13(|>) :: a -> (a -> b) -> b
39(|>) :: a -> (a -> b) -> b
14(|>) a f =
40(|>) a f =
15 f a
41 f a
@@ -20,17 +46,16 @@ import qualified Reporting.Helpers as H
20 a <> hardline <> b
46 a <> hardline <> b
21
47
22
48
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 =
25 let
51 let
26 (R.Position startLine _) = start
52 (R.Position startLine _) = start
27 (R.Position endLine _) = end
53 (R.Position endLine _) = end
28
54
29 relevantLines =
55 relevantLines =
30− (Text.lines source ++ [Text.empty])
56+ sourceLines
31− |> take endLine
32 |> drop (startLine - 1)
57 |> drop (startLine - 1)
33− |> zip [startLine .. endLine + 1]
58+ |> take (1 + endLine - startLine)
34
59
35 width =
60 width =
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 =
71
96
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)
75
100
76
101
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 =
90 text " "
115 text " "
91 in
116 in
92 text lineNumber <> spacer <> line
117 text lineNumber <> spacer <> line
118+
119+
120+
121+-- RENDER PAIR
122+
123+
124+data CodePair
125+ = OneLine Doc
126+ | TwoChunks Doc Doc
127+
128+
129+renderPair :: Source -> R.Region -> R.Region -> CodePair
130+renderPair source r1 r2 =
131+ error "TODO" source r1 r2