@@ -2284,12 +2284,12 @@ toRecordReport source context record startRow startCol =
22842284 )
22852285
22862286 RecordField row col ->
2287− let
2288− surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2289− region = toRegion row col
2290− in
22912287 case Code.whatIsNext source row col of
22922288 Code.Keyword keyword ->
2289+ let
2290+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2291+ region = toWiderRegion row col (fromIntegral (length keyword))
2292+ in
22932293 Report.Report "RESERVED WORD" region [] $
22942294 Code.toSnippet source surroundings (Just region)
22952295 (
@@ -2302,6 +2302,10 @@ toRecordReport source context record startRow startCol =
23022302 )
23032303
23042304 _ ->
2305+ let
2306+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
2307+ region = toRegion row col
2308+ in
23052309 Report.Report "UNFINISHED RECORD" region [] $
23062310 Code.toSnippet source surroundings (Just region)
23072311 (
@@ -2443,7 +2447,7 @@ addNoteForRecordError normalRecommendation =
24432447 , "}"
24442448 ]
24452449 , D.reflow $
2446− "Notice that nothing comes directly after a newline. Each line starts with some spaces. I\
2450+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
24472451 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
24482452 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
24492453 ]
@@ -2458,13 +2462,13 @@ addNoteForRecordIndentError normalRecommendation =
24582462 "I may be confused by indentation. For example, if you are trying to define\
24592463 \ a record across multiple lines, I recommend using this format:"
24602464 , D.indent 4 $ D.vcat $
2461− [ "[ \"Alice\""
2462− , ", \"Bob\""
2463− , ", \"Chuck\""
2464− , "]"
2465+ [ "{ name = \"Alice\""
2466+ , ", age = 42"
2467+ , ", height = 1.75"
2468+ , "}"
24652469 ]
24662470 , D.reflow $
2467− "Notice that nothing comes directly after a newline. Each line starts with some spaces. I\
2471+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
24682472 \ know this style can be jarring for people coming from C-like syntax, but folks generally\
24692473 \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
24702474 ]
@@ -3399,38 +3403,247 @@ toTRecordReport :: Code.Source -> TRecord -> Row -> Col -> Report.Report
33993403toTRecordReport source record startRow startCol =
34003404 case record of
34013405 TRecordOpen row col ->
3402− error "TODO TRecordOpen" row col startRow startCol
3406+ let
3407+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3408+ region = toRegion row col
3409+ in
3410+ case Code.whatIsNext source row col of
3411+ Code.Keyword keyword ->
3412+ Report.Report "RESERVED WORD" region [] $
3413+ Code.toSnippet source surroundings (Just region)
3414+ (
3415+ D.reflow $
3416+ "I just started parsing a record type, but I got stuck on this field name:"
3417+ ,
3418+ D.reflow $
3419+ "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3420+ \ that is a reserved word. Try using a different name!"
3421+ )
3422+
3423+ _ ->
3424+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3425+ Code.toSnippet source surroundings (Just region)
3426+ (
3427+ D.reflow $
3428+ "I just started parsing a record type, but I got stuck here:"
3429+ ,
3430+ D.fillSep
3431+ ["Record","types","look","like",D.dullyellow "{ name : String, age : Int },"
3432+ ,"so","I","was","expecting","to","see","a","field","name","next."
3433+ ]
3434+ )
34033435
34043436 TRecordEnd row col ->
3405− error "TODO TRecordEnd" row col
3437+ let
3438+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3439+ region = toRegion row col
3440+ in
3441+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3442+ Code.toSnippet source surroundings (Just region)
3443+ (
3444+ D.reflow $
3445+ "I am partway through parsing a record type, but I got stuck here:"
3446+ ,
3447+ D.stack
3448+ [ D.fillSep
3449+ ["I","was","expecting","to","see","a","closing","curly","brace","before","this,"
3450+ ,"so","try","adding","a",D.dullyellow "}","and","see","if","that","helps?"
3451+ ]
3452+ , D.toSimpleNote $
3453+ "When I get stuck like this, it usually means that there is a missing parenthesis\
3454+ \ or bracket somewhere earlier. It could also be a stray keyword or operator."
3455+ ]
3456+ )
34063457
34073458 TRecordField row col ->
3408− error "TODO TRecordField" row col
3459+ case Code.whatIsNext source row col of
3460+ Code.Keyword keyword ->
3461+ let
3462+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3463+ region = toWiderRegion row col (fromIntegral (length keyword))
3464+ in
3465+ Report.Report "RESERVED WORD" region [] $
3466+ Code.toSnippet source surroundings (Just region)
3467+ (
3468+ D.reflow $
3469+ "I am partway through parsing a record type, but I got stuck on this field name:"
3470+ ,
3471+ D.reflow $
3472+ "It looks like you are trying to use `" ++ keyword ++ "` as a field name, but \
3473+ \ that is a reserved word. Try using a different name!"
3474+ )
3475+
3476+ _ ->
3477+ let
3478+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3479+ region = toRegion row col
3480+ in
3481+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3482+ Code.toSnippet source surroundings (Just region)
3483+ (
3484+ D.reflow $
3485+ "I am partway through parsing a record type, but I got stuck after that last comma:"
3486+ ,
3487+ addNoteForRecordTypeError $
3488+ D.reflow $
3489+ "Trailing commas are not allowed in records, so I was expecting to see another\
3490+ \ record field defined next. If you are done defining the record, the fix may\
3491+ \ be to delete that last comma?"
3492+ )
34093493
34103494 TRecordColon row col ->
3411− error "TODO TRecordColon" row col
3495+ let
3496+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3497+ region = toRegion row col
3498+ in
3499+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3500+ Code.toSnippet source surroundings (Just region)
3501+ (
3502+ D.reflow $
3503+ "I am partway through parsing a record type, but I got stuck here:"
3504+ ,
3505+ addNoteForRecordTypeError $
3506+ D.fillSep $
3507+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
3508+ ,"a","colon","next.","So","try","putting","an",D.green ":","sign","here?"
3509+ ]
3510+ )
34123511
34133512 TRecordType tipe row col ->
3414− error "TODO TRecordType" tipe row col
3513+ toTypeReport source tipe row col
34153514
34163515 TRecordSpace space row col ->
34173516 toSpaceReport source space row col
34183517
34193518 TRecordIndentOpen row col ->
3420− error "TODO TRecordIndentOpen" row col
3519+ let
3520+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3521+ region = toRegion row col
3522+ in
3523+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3524+ Code.toSnippet source surroundings (Just region)
3525+ (
3526+ D.reflow $
3527+ "I just saw the opening curly brace of a record type, but then I got stuck here:"
3528+ ,
3529+ addNoteForRecordTypeIndentError $
3530+ D.fillSep $
3531+ ["I","am","expecting","a","record","like",D.dullyellow "{ name : String, age : Int }","here."
3532+ ,"Try","defining","some","fields","of","your","own?"
3533+ ]
3534+ )
3535+
3536+ TRecordIndentEnd row col ->
3537+ let
3538+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3539+ region = toRegion row col
3540+ in
3541+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3542+ Code.toSnippet source surroundings (Just region)
3543+ (
3544+ D.reflow $
3545+ "I was expecting to see a closing curly brace next:"
3546+ ,
3547+ addNoteForRecordTypeIndentError $
3548+ D.fillSep $
3549+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
3550+ ]
3551+ )
34213552
34223553 TRecordIndentField row col ->
3423− error "TODO TRecordIndentField" row col
3554+ let
3555+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3556+ region = toRegion row col
3557+ in
3558+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3559+ Code.toSnippet source surroundings (Just region)
3560+ (
3561+ D.reflow $
3562+ "I am partway through parsing a record type, but I got stuck after that last comma:"
3563+ ,
3564+ addNoteForRecordTypeIndentError $
3565+ D.reflow $
3566+ "Trailing commas are not allowed in record types, so the fix may be to\
3567+ \ delete that last comma? Or maybe you were in the middle of defining\
3568+ \ an additional field?"
3569+ )
34243570
34253571 TRecordIndentColon row col ->
3426− error "TODO TRecordIndentColon" row col
3572+ let
3573+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3574+ region = toRegion row col
3575+ in
3576+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3577+ Code.toSnippet source surroundings (Just region)
3578+ (
3579+ D.reflow $
3580+ "I am partway through parsing a record type. I just saw a record\
3581+ \ field, so I was expecting to see a colon next:"
3582+ ,
3583+ addNoteForRecordTypeIndentError $
3584+ D.fillSep $
3585+ ["Try","putting","an",D.green ":","followed","by","a","type?"
3586+ ]
3587+ )
34273588
34283589 TRecordIndentType row col ->
3429− error "TODO TRecordIndentType" row col
3590+ let
3591+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
3592+ region = toRegion row col
3593+ in
3594+ Report.Report "UNFINISHED RECORD TYPE" region [] $
3595+ Code.toSnippet source surroundings (Just region)
3596+ (
3597+ D.reflow $
3598+ "I am partway through parsing a record type, and I was expecting to run into a type next:"
3599+ ,
3600+ addNoteForRecordTypeIndentError $
3601+ D.fillSep $
3602+ ["Try","putting","something,","like"
3603+ ,D.dullyellow "Int","or",D.dullyellow "String","for","now?"
3604+ ]
3605+ )
34303606
3431− TRecordIndentEnd row col ->
3432− error "TODO TRecordIndentEnd" row col
34333607
3608+addNoteForRecordTypeError :: D.Doc -> D.Doc
3609+addNoteForRecordTypeError normalRecommendation =
3610+ D.stack $
3611+ normalRecommendation
3612+ :
3613+ [ D.toSimpleNote
3614+ "If you are trying to define a record type across multiple lines, I recommend using this format:"
3615+ , D.indent 4 $ D.vcat $
3616+ [ "{ name : String"
3617+ , ", age : Int"
3618+ , ", height : Float"
3619+ , "}"
3620+ ]
3621+ , D.reflow $
3622+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
3623+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3624+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
3625+ ]
3626+
3627+
3628+addNoteForRecordTypeIndentError :: D.Doc -> D.Doc
3629+addNoteForRecordTypeIndentError normalRecommendation =
3630+ D.stack $
3631+ normalRecommendation
3632+ :
3633+ [ D.toSimpleNote
3634+ "I may be confused by indentation. For example, if you are trying to define\
3635+ \ a record type across multiple lines, I recommend using this format:"
3636+ , D.indent 4 $ D.vcat $
3637+ [ "{ name : String"
3638+ , ", age : Int"
3639+ , ", height : Float"
3640+ , "}"
3641+ ]
3642+ , D.reflow $
3643+ "Notice that each line starts with some indentation. Usually two or four spaces. I\
3644+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
3645+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
3646+ ]
34343647
34353648
34363649toTTupleReport :: Code.Source -> TTuple -> Row -> Col -> Report.Report