@@ -751,7 +751,7 @@ toDeclarationsReport source decl =
753toDeclDefReport :: Code.Source -> Name.Name -> DeclDef -> Row -> Col -> Report.Report
753toDeclDefReport :: Code.Source -> Name.Name -> DeclDef -> Row -> Col -> Report.Report
754−toDeclDefReport source name declDef _ _ =
754+toDeclDefReport source name declDef startRow startCol =
755 case declDef of
755 case declDef of
756 DeclDefSpace space row col ->
756 DeclDefSpace space row col ->
757 toSpaceReport source space row col
757 toSpaceReport source space row col
@@ -766,7 +766,7 @@ toDeclDefReport source name declDef _ _ =
766 error "TODO DeclDefArg" pattern row col
766 error "TODO DeclDefArg" pattern row col
768 DeclDefBody expr row col ->
768 DeclDefBody expr row col ->
769− toExprReport source name expr row col
769+ toExprReport source (InDef name startRow startCol) expr row col
771 DeclDefNameRepeat row col ->
771 DeclDefNameRepeat row col ->
772 error "TODO DeclDefNameRepeat" name row col
772 error "TODO DeclDefNameRepeat" name row col
@@ -788,8 +788,34 @@ toDeclDefReport source name declDef _ _ =
795+ = InNode Node Row Col Context
796+ | InDef Name.Name Row Col
806+getDefName :: Context -> Name.Name
809+ InDef name _ _ -> name
810+ InNode _ _ _ c -> getDefName c
791−toExprReport :: Code.Source -> Name.Name -> Expr -> Row -> Col -> Report.Report
817+toExprReport :: Code.Source -> Context -> Expr -> Row -> Col -> Report.Report
792−toExprReport source name expr _ _ =
818+toExprReport source context expr startRow startCol =
793 case expr of
819 case expr of
794 Let _ _ _ ->
820 Let _ _ _ ->
795 error "TODO Let"
821 error "TODO Let"
@@ -801,16 +827,16 @@ toExprReport source name expr _ _ =
801 error "TODO If"
827 error "TODO If"
803 List list row col ->
829 List list row col ->
804− toListReport source name list row col
830+ toListReport source context list row col
806− Record _ _ _ ->
832+ Record record row col ->
807− error "TODO Record"
833+ toRecordReport source context record row col
809 Tuple tuple row col ->
835 Tuple tuple row col ->
810− toTupleReport source name tuple row col
836+ toTupleReport source context tuple row col
812 Func func row col ->
838 Func func row col ->
813− toFuncReport source name func row col
839+ toFuncReport source context func row col
815 Dot row col ->
841 Dot row col ->
816 let region = toRegion row col in
842 let region = toRegion row col in
@@ -858,36 +884,49 @@ toExprReport source name expr _ _ =
858 [ D.fillSep $
884 [ D.fillSep $
859 ["You","can","just","put","anything","for","now,","like"
885 ["You","can","just","put","anything","for","now,","like"
860 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
886 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
861− ,"Once","there","is","something","there,","I","can","give","more"
887+ ,"Once","there","is","something","there,","I","can","probably"
862− ,"specific","hints","about","what","type","of","value","is","needed!"
888+ ,"give","a","more","specific","hint!"
864 , D.toSimpleNote $
890 , D.toSimpleNote $
865− "This can happen if see reserved words like `let` or `as` unexpectedly.\
891+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
866− \ I can get confused and not understand what is going on very well!"
892+ \ Or if I run into operators in unexpected spots. Point is, there are a\
893+ \ couple ways I can get confused and give sort of weird advice!"
870 OperatorReserved operator row col ->
897 OperatorReserved operator row col ->
871− toOperatorReport source name operator row col
898+ toOperatorReport source context operator row col
873 Start row col ->
900 Start row col ->
902+ (contextRow, contextCol, aThing) =
904+ InDef name r c -> (r, c, "the `" ++ Name.toChars name ++ "` definition")
905+ InNode NRecord r c _ -> (r, c, "a record")
906+ InNode NParens r c _ -> (r, c, "some parentheses")
907+ InNode NList r c _ -> (r, c, "a list")
908+ InNode NFunc r c _ -> (r, c, "an anonymous function")
910+ surroundings = A.Region (A.Position contextRow contextCol) (A.Position row col)
874− let region = toRegion row col in
911+ region = toRegion row col
875 Report.Report "MISSING EXPRESSION" region [] $
913 Report.Report "MISSING EXPRESSION" region [] $
876− Report.toCodeSnippet source region Nothing
914+ Report.toCodeSnippet source surroundings (Just region)
878 D.reflow $
916 D.reflow $
879− "I was expecting to see an expression next:"
917+ "I am partway through parsing " ++ aThing ++ ", but I got stuck here:"
882 [ D.fillSep $
920 [ D.fillSep $
883− ["You","can","just","put","anything","for","now,","like"
921+ ["I","was","expecting","to","see","an","expression","like"
884 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
922 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
885− ,"Once","there","is","something","there,","I","can","give","more"
923+ ,"Once","there","is","something","there,","I","can","probably"
886− ,"specific","hints","about","what","type","of","value","is","needed!"
924+ ,"give","a","more","specific","hint!"
888 , D.toSimpleNote $
926 , D.toSimpleNote $
889− "This can happen if see reserved words like `let` or `as` unexpectedly.\
927+ "This can also happen if run into reserved words like `let` or `as` unexpectedly.\
890− \ I can get confused and not understand what is going on very well!"
928+ \ Or if I run into operators in unexpected spots. Point is, there are a\
929+ \ couple ways I can get confused and give sort of weird advice!"
@@ -934,20 +973,23 @@ toExprReport source name expr _ _ =
936 IndentOperatorRight op row col ->
975 IndentOperatorRight op row col ->
977+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
937− let region = toRegion row col in
978+ region = toRegion row col
938 Report.Report "MISSING EXPRESSION" region [] $
980 Report.Report "MISSING EXPRESSION" region [] $
939− Report.toCodeSnippet source region Nothing
981+ Report.toCodeSnippet source surroundings (Just region)
941 D.reflow $
983 D.reflow $
942− "I need to see an expression after this " ++ Name.toChars op ++ " operator:"
984+ "I was expecting to see an expression after this " ++ Name.toChars op ++ " operator:"
946 D.fillSep $
988 D.fillSep $
947 ["You","can","just","put","anything","for","now,","like"
989 ["You","can","just","put","anything","for","now,","like"
948 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
990 ,D.dullyellow "42","or",D.dullyellow"\"hello\"" <> "."
949− ,"Once","there","is","something","there,","I","can","give","more"
991+ ,"Once","there","is","something","there,","I","can","probably"
950− ,"specific","hints","about","what","type","of","value","is","needed!"
992+ ,"give","a","more","specific","hint!"
953 D.toSimpleNote $
995 D.toSimpleNote $
@@ -1222,8 +1264,8 @@ toNumberReport source number row col =
1225−toOperatorReport :: Code.Source -> Name.Name -> Operator -> Row -> Col -> Report.Report
1267+toOperatorReport :: Code.Source -> Context -> Operator -> Row -> Col -> Report.Report
1226−toOperatorReport source name operator row col =
1268+toOperatorReport source context operator row col =
1227 case operator of
1269 case operator of
1228 OpDot ->
1270 OpDot ->
@@ -1292,6 +1334,7 @@ toOperatorReport source name operator row col =
1292 OpEquals ->
1334 OpEquals ->
1294 region = toRegion row col
1336 region = toRegion row col
1337+ name = getDefName context
1296 Report.Report "UNEXPECTED EQUALS" region [] $
1339 Report.Report "UNEXPECTED EQUALS" region [] $
1297 Report.toCodeSnippet source region Nothing
1340 Report.toCodeSnippet source region Nothing
@@ -1319,6 +1362,7 @@ toOperatorReport source name operator row col =
1319 OpHasType ->
1362 OpHasType ->
1321 region = toRegion row col
1364 region = toRegion row col
1365+ name = getDefName context
1323 Report.Report "UNEXPECTED SYMBOL" region [] $
1367 Report.Report "UNEXPECTED SYMBOL" region [] $
1324 Report.toCodeSnippet source region Nothing $
1368 Report.toCodeSnippet source region Nothing $
@@ -1346,11 +1390,235 @@ toOperatorReport source name operator row col =
1397+toRecordReport :: Code.Source -> Context -> Record -> Row -> Col -> Report.Report
1398+toRecordReport source context record startRow startCol =
1400+ RecordOpen row col ->
1402+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1403+ region = toRegion row col
1405+ Report.Report "UNFINISHED PARENTHESES" region [] $
1406+ Report.toCodeSnippet source surroundings (Just region)
1409+ "I was expecting to see a closing curly brace next, but I got stuck here:"
1412+ [ D.fillSep ["Try","adding","a",D.dullyellow "}","to","see","if","that","helps?"]
1414+ "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1415+ \ unexpectedly. So there may be some other syntax trouble (like an extra\
1416+ \ parenthesis?) that is confusing me."
1420+ RecordEnd row col ->
1422+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1423+ region = toRegion row col
1425+ Report.Report "UNFINISHED PARENTHESES" region [] $
1426+ Report.toCodeSnippet source surroundings (Just region)
1429+ "I was expecting to see a closing curly brace next, but I got stuck here:"
1432+ [ D.fillSep ["Try","adding","a",D.dullyellow "}","to","see","if","that","helps?"]
1434+ "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1435+ \ unexpectedly. So there may be some other syntax trouble (like an extra\
1436+ \ parenthesis?) that is confusing me."
1440+ RecordField row col ->
1442+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1443+ region = toRegion row col
1445+ Report.Report "UNFINISHED RECORD" region [] $
1446+ Report.toCodeSnippet source surroundings (Just region)
1449+ "I am partway through parsing a record, but I got stuck after that last comma:"
1451+ addNoteForRecordError $
1453+ "Trailing commas are not allowed in records, so I was expecting to see another\
1454+ \ record field defined next. If you are done defining the record, the fix may\
1455+ \ be to delete that last comma?"
1458+ RecordEquals row col ->
1460+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1461+ region = toRegion row col
1463+ Report.Report "UNFINISHED RECORD" region [] $
1464+ Report.toCodeSnippet source surroundings (Just region)
1467+ "I am partway through parsing a record, but I got stuck here:"
1469+ addNoteForRecordError $
1471+ ["I","just","saw","a","field","name,","so","I","was","expecting","to","see"
1472+ ,"an","equals","sign","next.","So","try","putting","an",D.green "=","sign?"
1476+ RecordExpr expr row col ->
1477+ toExprReport source (InNode NRecord startRow startCol context) expr row col
1479+ RecordSpace space row col ->
1480+ toSpaceReport source space row col
1482+ RecordIndentOpen row col ->
1484+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1485+ region = toRegion row col
1487+ Report.Report "UNFINISHED RECORD" region [] $
1488+ Report.toCodeSnippet source surroundings (Just region)
1491+ "I just saw the opening curly brace of a record, but then I got stuck here:"
1493+ addNoteForRecordIndentError $
1495+ ["I","am","expecting","a","record","like",D.dullyellow "{ x = 3, y = 4 }","here."
1496+ ,"Try","defining","some","fields","of","your","own?"
1500+ RecordIndentEnd row col ->
1502+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1503+ region = toRegion row col
1505+ Report.Report "UNFINISHED RECORD" region [] $
1506+ Report.toCodeSnippet source surroundings (Just region)
1509+ "I was expecting to see a closing curly brace next:"
1511+ addNoteForRecordIndentError $
1513+ ["Try","putting","an",D.green "}","and","see","if","that","helps?"
1517+ RecordIndentField row col ->
1519+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1520+ region = toRegion row col
1522+ Report.Report "UNFINISHED RECORD" region [] $
1523+ Report.toCodeSnippet source surroundings (Just region)
1526+ "I am partway through parsing a record, but I got stuck after that last comma:"
1528+ addNoteForRecordError $
1530+ "Trailing commas are not allowed in records, so the fix may be to\
1531+ \ delete that last comma? Or maybe you were in the middle of defining\
1532+ \ an additional field?"
1535+ RecordIndentEquals row col ->
1537+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1538+ region = toRegion row col
1540+ Report.Report "UNFINISHED RECORD" region [] $
1541+ Report.toCodeSnippet source surroundings (Just region)
1544+ "I am partway through parsing a record. I just saw a record\
1545+ \ field, so I was expecting to see an equals sign next:"
1547+ addNoteForRecordIndentError $
1549+ ["Try","putting","an",D.green "=","followed","by","an","expression?"
1553+ RecordIndentExpr row col ->
1555+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1556+ region = toRegion row col
1558+ Report.Report "UNFINISHED RECORD" region [] $
1559+ Report.toCodeSnippet source surroundings (Just region)
1562+ "I am partway through parsing a record, and I was expecting to run into an expression next:"
1564+ addNoteForRecordIndentError $
1566+ ["Try","putting","something,","like"
1567+ ,D.dullyellow "42","or",D.dullyellow"\"hello\"","for","now?"
1572+addNoteForRecordError :: D.Doc -> D.Doc
1573+addNoteForRecordError normalRecommendation =
1575+ normalRecommendation
1578+ "If you are trying to define a record across multiple lines, I recommend using this format:"
1579+ , D.indent 4 $ D.vcat $
1580+ [ "{ name = \"Alice\""
1582+ , ", height = 1.75"
1586+ "Notice that nothing comes directly after a newline. Each line starts with some spaces. I\
1587+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
1588+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
1592+addNoteForRecordIndentError :: D.Doc -> D.Doc
1593+addNoteForRecordIndentError normalRecommendation =
1595+ normalRecommendation
1598+ "I may be confused by indentation. For example, if you are trying to define\
1599+ \ a record across multiple lines, I recommend using this format:"
1600+ , D.indent 4 $ D.vcat $
1607+ "Notice that nothing comes directly after a newline. Each line starts with some spaces. I\
1608+ \ know this style can be jarring for people coming from C-like syntax, but folks generally\
1609+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
1349−toTupleReport :: Code.Source -> Name.Name -> Tuple -> Row -> Col -> Report.Report
1617+toTupleReport :: Code.Source -> Context -> Tuple -> Row -> Col -> Report.Report
1350−toTupleReport source name tuple startRow startCol =
1618+toTupleReport source context tuple startRow startCol =
1351 case tuple of
1619 case tuple of
1352 TupleExpr expr row col ->
1620 TupleExpr expr row col ->
1353− toExprReport source name expr row col
1621+ toExprReport source (InNode NParens startRow startCol context) expr row col
1355 TupleSpace space row col ->
1623 TupleSpace space row col ->
1356 toSpaceReport source space row col
1624 toSpaceReport source space row col
@@ -1364,14 +1632,14 @@ toTupleReport source name tuple startRow startCol =
1364 Report.toCodeSnippet source surroundings (Just region)
1632 Report.toCodeSnippet source surroundings (Just region)
1366 D.reflow $
1634 D.reflow $
1367− "I was expecting to see a closing parenthesis next:"
1635+ "I was expecting to see a closing parentheses next, but I got stuck here:"
1370 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
1638 [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps?"]
1371 , D.toSimpleNote $
1639 , D.toSimpleNote $
1372− "This can happen if I see reserved words like `let` or `as` unexpectedly.\
1640+ "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1373− \ So I could be stuck on some other problem, which is not letting me get to\
1641+ \ unexpectedly. So there may be some other syntax trouble (like an extra\
1374− \ the closing parenthesis I am expecting to see."
1642+ \ square bracket?) that is confusing me."
@@ -1385,7 +1653,13 @@ toTupleReport source name tuple startRow startCol =
1386 D.reflow "I was expecting a closing parenthesis here:"
1654 D.reflow "I was expecting a closing parenthesis here:"
1388− D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
1657+ [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
1659+ "I think I am parsing an operator function right now, so I am expecting to see\
1660+ \ something like (+) or (&&) where an operator is surrounded by parentheses with\
1661+ \ no extra spaces."
1391 TupleOperatorReserved operator row col ->
1665 TupleOperatorReserved operator row col ->
@@ -1425,10 +1699,9 @@ toTupleReport source name tuple startRow startCol =
1425 ,D.dullyellow "(String.reverse \"desserts\")" <> "."
1699 ,D.dullyellow "(String.reverse \"desserts\")" <> "."
1426 ,"Anything","where","you","are","putting","parentheses","around","normal","expressions."
1700 ,"Anything","where","you","are","putting","parentheses","around","normal","expressions."
1428− , D.toSimpleNote
1702+ , D.toSimpleNote $
1429− "If you are trying to use the (+) syntax for referring to operators as functions (or\
1703+ "I can get confused by indentation in cases like this, so\
1430− \ the () syntax for the unit value) the issue may be that no spaces are allowed between\
1704+ \ maybe you have an expression but it is not indented enough?"
1431− \ the parentheses."
@@ -1441,12 +1714,17 @@ toTupleReport source name tuple startRow startCol =
1441 Report.toCodeSnippet source surroundings (Just region)
1714 Report.toCodeSnippet source surroundings (Just region)
1443 D.reflow $
1716 D.reflow $
1444− "I just saw a comma, so I was expecting to see another expression in this tuple."
1717+ "I think I am in the middle of parsing a tuple. I just saw a comma, so I was expecting to see expression next."
1446− D.fillSep $
1720+ [ D.fillSep $
1447− ["A","tuple","looks","like",D.dullyellow "(3,4)","or"
1721+ ["A","tuple","looks","like",D.dullyellow "(3,4)","or"
1448− ,D.dullyellow "(\"Tom\",42)" <> ","
1722+ ,D.dullyellow "(\"Tom\",42)" <> ","
1449− ,"so","I","think","there","is","an","expression","missing","here?"
1723+ ,"so","I","think","there","is","an","expression","missing","here?"
1726+ "I can get confused by indentation in cases like this, so\
1727+ \ maybe you have an expression but it is not indented enough?"
@@ -1461,24 +1739,94 @@ toTupleReport source name tuple startRow startCol =
1461 D.reflow $
1739 D.reflow $
1462 "I was expecting to see a closing parenthesis next:"
1740 "I was expecting to see a closing parenthesis next:"
1464− D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
1743+ [ D.fillSep ["Try","adding","a",D.dullyellow ")","to","see","if","that","helps!"]
1745+ "I can get confused by indentation in cases like this, so\
1746+ \ maybe you have a closing parenthesis but it is not indented enough?"
1468−toListReport :: Code.Source -> Name.Name -> List -> Row -> Col -> Report.Report
1751+toListReport :: Code.Source -> Context -> List -> Row -> Col -> Report.Report
1469−toListReport source name list startRow startCol =
1752+toListReport source context list startRow startCol =
1470 case list of
1753 case list of
1471 ListSpace space row col ->
1754 ListSpace space row col ->
1472 toSpaceReport source space row col
1755 toSpaceReport source space row col
1474 ListOpen row col ->
1757 ListOpen row col ->
1475− error "TODO ListOpen" row col
1758+ let
1759+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1760+ region = toRegion row col
1762+ Report.Report "UNFINISHED LIST" region [] $
1763+ Report.toCodeSnippet source surroundings (Just region)
1766+ "I was expecting to see a closing square bracket next, but I got stuck here:"
1769+ [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
1771+ "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1772+ \ unexpectedly. So there may be some other syntax trouble (like an extra\
1773+ \ parenthesis?) that is confusing me."
1477 ListExpr expr row col ->
1777 ListExpr expr row col ->
1781+ surroundings = A.Region (A.Position startRow startCol) (A.Position r c)
1782+ region = toRegion r c
1784+ Report.Report "UNFINISHED LIST" region [] $
1785+ Report.toCodeSnippet source surroundings (Just region)
1788+ "I was expecting to see another list entry after that last comma:"
1792+ "Trailing commas are not allowed in lists, so the fix may be to delete the comma?"
1794+ "I recommend using the following format for lists that span multiple lines:"
1795+ , D.indent 4 $ D.vcat $
1802+ "Notice that nothing comes directly after a newline. Each line starts with some spaces.\
1803+ \ This style can be jarring for people coming from C-like syntax, but folks generally\
1804+ \ report that they are used to it (and often prefer it!) after a week or two of using Elm."
1478− toExprReport source name expr row col
1809+ toExprReport source (InNode NList startRow startCol context) expr row col
1480 ListEnd row col ->
1811 ListEnd row col ->
1481− error "TODO ListEnd" row col
1812+ let
1813+ surroundings = A.Region (A.Position startRow startCol) (A.Position row col)
1814+ region = toRegion row col
1816+ Report.Report "UNFINISHED LIST" region [] $
1817+ Report.toCodeSnippet source surroundings (Just region)
1820+ "I was expecting to see a closing square bracket next, but I got stuck here:"
1823+ [ D.fillSep ["Try","adding","a",D.dullyellow "]","to","see","if","that","helps?"]
1825+ "I can get stuck when I run into keywords, operators, parentheses, or brackets\
1826+ \ unexpectedly. So there may be some other syntax trouble (like an extra\
1827+ \ parenthesis?) that is confusing me."
1483 ListIndentOpen row col ->
1831 ListIndentOpen row col ->
@@ -1578,8 +1926,8 @@ toListReport source name list startRow startCol =
1581−toFuncReport :: Code.Source -> Name.Name -> Func -> Row -> Col -> Report.Report
1929+toFuncReport :: Code.Source -> Context -> Func -> Row -> Col -> Report.Report
1582−toFuncReport source name func startRow startCol =
1930+toFuncReport source context func startRow startCol =
1583 case func of
1931 case func of
1584 FuncSpace space row col ->
1932 FuncSpace space row col ->
1585 toSpaceReport source space row col
1933 toSpaceReport source space row col
@@ -1588,7 +1936,7 @@ toFuncReport source name func startRow startCol =
1588 error "TODO FuncArg" pattern row col
1936 error "TODO FuncArg" pattern row col
1590 FuncBody expr row col ->
1938 FuncBody expr row col ->
1591− toExprReport source name expr row col
1939+ toExprReport source (InNode NFunc startRow startCol context) expr row col
1593 FuncArrow row col ->
1941 FuncArrow row col ->