Skip to content

Commit 63db0a1

Browse files
committed
always show three lines of JSON in syntax error messages
Some specific errors benefit from having the line above, like in elm/error-message-catalog#264 Since the JSON syntax errors are always for a single position (no context stack!) I figured I did a fix that just includes two extra lines for all JSON syntax errors. This should not be too disruptive and should give more of a feeling of place within the JSON file, especially when it's a single line with something weird on it!
1 parent adfbebf commit 63db0a1

File tree

1 file changed

+6
-2
lines changed
  • compiler/src/Reporting/Error

1 file changed

+6
-2
lines changed

compiler/src/Reporting/Error/Json.hs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,13 @@ parseErrorToReport :: FilePath -> Code.Source -> ParseError -> Reason -> Help.Re
5151
parseErrorToReport path source parseError reason =
5252
let
5353
toSnippet title row col (problem, details) =
54-
let pos = A.Position row col in
54+
let
55+
pos = A.Position row col
56+
surroundings = A.Region (A.Position (max 1 (row - 2)) 1) pos
57+
region = A.Region pos pos
58+
in
5559
Help.jsonReport title (Just path) $
56-
Code.toSnippet source (A.Region pos pos) Nothing
60+
Code.toSnippet source surroundings (Just region)
5761
( D.reflow (because reason problem)
5862
, details
5963
)

0 commit comments

Comments
 (0)