1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Region where
4import Data.Aeson ((.=))
5import qualified Data.Aeson as Json
6import qualified Text.Parsec.Pos as Parsec
18data Position = Position
25fromSourcePos :: Parsec.SourcePos -> Position
26fromSourcePos sourcePos =
28 (Parsec.sourceLine sourcePos)
29 (Parsec.sourceColumn sourcePos)
32merge :: Region -> Region -> Region
33merge (Region start _) (Region _ end) =
39toString :: Region -> String
40toString (Region start end) =
41 case line start == line end of
43 "between lines " ++ show (line start)
44 ++ " and " ++ show (line end)
47 "on line " ++ show (line end) ++ ", column "
48 ++ show (column start) ++ " to " ++ show (column end)
51-- EXTRACT REGION from SOURCE with LINE NUMBERS
53select :: Region -> String -> String
54select (Region start end) source =
59 |> take (line end - line start)
63 error "something has gone badly wrong with reporting source locations"
67 lineNumber = show (line start) ++ "|"
72 ++ replicate (column start + length lineNumber) ' '
73 ++ replicate (column end - column start) '^'
79 replicate (column start) ' ' ++ drop (column start) firstLine
82 take (column end) (last rest)
84 focusedRelevantLines =
85 filteredFirstLine : init rest ++ [filteredLastLine]
88 length (show (line end))
92 (addLineNumber lineNumbersWidth)
93 [line start .. line end]
99addLineNumber :: Int -> Int -> String -> String
100addLineNumber width n line =
104 replicate (width - length number) ' ' ++ number ++ "|" ++ line
109instance Json.ToJSON Region where
110 toJSON (Region start end) =
117instance Json.ToJSON Position where
118 toJSON (Position line column) =
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list