1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
12import qualified Data.ByteString as B
13import qualified Data.NonEmptyList as NE
14import qualified Data.OneOrMore as OneOrMore
15import qualified System.FilePath as FP
17import qualified Elm.ModuleName as ModuleName
19import qualified Json.Encode as E
20import Json.Encode ((==>))
21import qualified Reporting.Annotation as A
22import qualified Reporting.Doc as D
23import qualified Reporting.Error.Canonicalize as Canonicalize
24import qualified Reporting.Error.Docs as Docs
25import qualified Reporting.Error.Import as Import
26import qualified Reporting.Error.Main as Main
27import qualified Reporting.Error.Pattern as Pattern
28import qualified Reporting.Error.Syntax as Syntax
29import qualified Reporting.Error.Type as Type
30import qualified Reporting.Render.Code as Code
31import qualified Reporting.Render.Type.Localizer as L
32import qualified Reporting.Report as Report
41 { _name :: ModuleName.Raw
42 , _absolutePath :: FilePath
43 , _modificationTime :: File.Time
44 , _source :: B.ByteString
54 = BadSyntax Syntax.Error
55 | BadImports (NE.List Import.Error)
56 | BadNames (OneOrMore.OneOrMore Canonicalize.Error)
57 | BadTypes L.Localizer (NE.List Type.Error)
58 | BadMains L.Localizer (OneOrMore.OneOrMore Main.Error)
59 | BadPatterns (NE.List Pattern.Error)
67toReports :: Code.Source -> Error -> NE.List Report.Report
70 BadSyntax syntaxError ->
71 NE.List (Syntax.toReport source syntaxError) []
74 fmap (Import.toReport source) errs
77 fmap (Canonicalize.toReport source) (OneOrMore.destruct NE.List errs)
79 BadTypes localizer errs ->
80 fmap (Type.toReport source localizer) errs
82 BadMains localizer errs ->
83 fmap (Main.toReport localizer source) (OneOrMore.destruct NE.List errs)
86 fmap (Pattern.toReport source) errs
89 Docs.toReports source docsErr
96toDoc :: FilePath -> Module -> [Module] -> D.Doc
99 (NE.List m ms) = NE.sortBy _modificationTime (NE.List err errs)
101 D.vcat (toDocHelp root m ms)
104toDocHelp :: FilePath -> Module -> [Module] -> [D.Doc]
105toDocHelp root module1 modules =
108 [moduleToDoc root module1
112 module2 : otherModules ->
113 moduleToDoc root module1
114 : toSeparator module1 module2
115 : toDocHelp root module2 otherModules
118toSeparator :: Module -> Module -> D.Doc
119toSeparator beforeModule afterModule =
121 before = ModuleName.toChars (_name beforeModule) ++ " ↑ "
122 after = " ↓ " ++ ModuleName.toChars (_name afterModule)
125 [ D.indent (80 - length before) (D.fromChars before)
126 , "====o======================================================================o===="
137moduleToDoc :: FilePath -> Module -> D.Doc
138moduleToDoc root (Module _ absolutePath _ source err) =
141 toReports (Code.toSource source) err
144 FP.makeRelative root absolutePath
146 D.vcat $ map (reportToDoc relativePath) (NE.toList reports)
149reportToDoc :: FilePath -> Report.Report -> D.Doc
150reportToDoc relativePath (Report.Report title _ _ message) =
152 [ toMessageBar title relativePath
159toMessageBar :: String -> FilePath -> D.Doc
160toMessageBar title filePath =
163 4 + length title + 1 + length filePath
165 D.dullcyan $ D.fromChars $
167 ++ " " ++ replicate (max 1 (80 - usedSpace)) '-'
175toJson :: Module -> E.Value
176toJson (Module name path _ source err) =
179 toReports (Code.toSource source) err
182 [ "path" ==> E.chars path
183 , "name" ==> E.name name
184 , "problems" ==> E.array (map reportToJson (NE.toList reports))
188reportToJson :: Report.Report -> E.Value
189reportToJson (Report.Report title region _sgstns message) =
191 [ "title" ==> E.chars title
192 , "region" ==> encodeRegion region
193 , "message" ==> D.encode message
197encodeRegion :: A.Region -> E.Value
198encodeRegion (A.Region (A.Position sr sc) (A.Position er ec)) =
202 [ "line" ==> E.int (fromIntegral sr)
203 , "column" ==> E.int (fromIntegral sc)
207 [ "line" ==> E.int (fromIntegral er)
208 , "column" ==> E.int (fromIntegral ec)
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