on master help sign in
handle docs errors / update JSON encoding
commitf4401aca884e6d8eb80e15c413a32f4ce62bf05f authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 24 Jun 2019, 19:07 (7 years ago) parent1b49afe
1 file changed+13−11
compiler/src/Reporting/Error.hs+13−11
compiler/src/Reporting/Error.hs+13−11
@@ -10,10 +10,8 @@ module Reporting.Error
1010
1111
1212import qualified Data.ByteString as B
13−import qualified Data.Name as Name
1413import qualified Data.NonEmptyList as NE
1514import qualified Data.OneOrMore as OneOrMore
16−import qualified Data.Utf8 as Utf8
1715
1816import qualified Elm.ModuleName as ModuleName
1917import qualified File
@@ -22,6 +20,7 @@ import Json.Encode ((==>))
2220import qualified Reporting.Annotation as A
2321import qualified Reporting.Doc as D
2422import qualified Reporting.Error.Canonicalize as Canonicalize
23+import qualified Reporting.Error.Docs as Docs
2524import qualified Reporting.Error.Import as Import
2625import qualified Reporting.Error.Main as Main
2726import qualified Reporting.Error.Pattern as Pattern
@@ -57,6 +56,7 @@ data Error
5756 | BadTypes L.Localizer (NE.List Type.Error)
5857 | BadMains L.Localizer (OneOrMore.OneOrMore Main.Error)
5958 | BadPatterns (NE.List Pattern.Error)
59+ | BadDocs Docs.Error
6060
6161
6262
@@ -84,6 +84,9 @@ toReports source err =
8484 BadPatterns errs ->
8585 fmap (Pattern.toReport source) errs
8686
87+ BadDocs docsErr ->
88+ Docs.toReports source docsErr
89+
8790
8891
8992-- TO DOC
@@ -92,8 +95,7 @@ toReports source err =
9295toDoc :: Module -> [Module] -> D.Doc
9396toDoc err errs =
9497 let
95− timeCompare m1 m2 = compare (_time m1) (_time m2)
96− (NE.List m ms) = NE.sortBy timeCompare (NE.List err errs)
98+ (NE.List m ms) = NE.sortBy _time (NE.List err errs)
9799 in
98100 D.vcat (toDocHelp m ms)
99101
@@ -173,8 +175,8 @@ toJson (Module name path _ source err) =
173175 toReports (Code.toSource source) err
174176 in
175177 E.object
176− [ "path" ==> E.string (Utf8.fromChars path)
177− , "name" ==> E.string (Name.toUtf8 name)
178+ [ "path" ==> E.chars path
179+ , "name" ==> E.name name
178180 , "problems" ==> E.array (map reportToJson (NE.toList reports))
179181 ]
180182
@@ -182,7 +184,7 @@ toJson (Module name path _ source err) =
182184reportToJson :: Report.Report -> E.Value
183185reportToJson (Report.Report title region _sgstns message) =
184186 E.object
185− [ "title" ==> E.string (Utf8.fromChars title)
187+ [ "title" ==> E.chars title
186188 , "region" ==> encodeRegion region
187189 , "message" ==> D.encode message
188190 ]
@@ -193,12 +195,12 @@ encodeRegion (A.Region (A.Position sr sc) (A.Position er ec)) =
193195 E.object
194196 [ "start" ==>
195197 E.object
196− [ ("line", E.int (fromIntegral sr))
197− , ("column", E.int (fromIntegral sc))
198+ [ "line" ==> E.int (fromIntegral sr)
199+ , "column" ==> E.int (fromIntegral sc)
198200 ]
199201 , "end" ==>
200202 E.object
201− [ ("line", E.int (fromIntegral er))
202− , ("column", E.int (fromIntegral ec))
203+ [ "line" ==> E.int (fromIntegral er)
204+ , "column" ==> E.int (fromIntegral ec)
203205 ]
204206 ]