@@ -39,7 +39,7 @@ data Mismatch = MismatchInfo
40data Reason
40data Reason
41 = BadFields [(String, Maybe Reason)]
41 = BadFields [(String, Maybe Reason)]
42− | MessyFields [String] [String]
42+ | MessyFields [String] [String] [String]
43 | IntFloat
43 | IntFloat
44 | TooLongComparableTuple Int
44 | TooLongComparableTuple Int
45 | MissingArgs Int
45 | MissingArgs Int
@@ -591,8 +591,8 @@ flipReason reason =
591 BadFields fields ->
591 BadFields fields ->
592 BadFields (map (second (fmap flipReason)) fields)
592 BadFields (map (second (fmap flipReason)) fields)
594− MessyFields leftOnly rightOnly ->
594+ MessyFields both left right ->
595− MessyFields rightOnly leftOnly
595+ MessyFields both right left
597 IntFloat ->
597 IntFloat ->
@@ -667,10 +667,8 @@ reasonToStringHelp reason =
667 ++ Help.commaSep (map fst fields) ++ " fields. "
667 ++ Help.commaSep (map fst fields) ++ " fields. "
668 ++ badFieldElaboration
668 ++ badFieldElaboration
670− MessyFields leftOnly rightOnly ->
670+ MessyFields both leftOnly rightOnly ->
671− do let typos = Help.findPotentialTypos leftOnly rightOnly
671+ messyFieldsHelp both leftOnly rightOnly
672− _ <- Help.vetTypos typos
673− misspellingMessage typos
675 IntFloat ->
673 IntFloat ->
@@ -741,28 +739,104 @@ toHint str =
741 fillSep (hintDoc : map text (words str))
739 fillSep (hintDoc : map text (words str))
744−misspellingMessage :: [(String,String)] -> Maybe (String, [Doc])
742+messyFieldsHelp :: [String] -> [String] -> [String] -> Maybe (String, [Doc])
745−misspellingMessage typos =
743+messyFieldsHelp both leftOnly rightOnly =
744+ case (leftOnly, rightOnly) of
745+ ([], [missingField]) ->
746+ oneMissingField both missingField
748+ ([missingField], []) ->
749+ oneMissingField both missingField
751+ ([], missingFields) ->
752+ manyMissingFields both missingFields
754+ (missingFields, []) ->
755+ manyMissingFields both missingFields
760+ case Help.findTypoPairs leftOnly rightOnly of
762+ Help.findTypoPairs (both ++ leftOnly) (both ++ rightOnly)
746− if null typos then
767+ if null typoPairs then
769+ ( "The record fields do not match up. One has "
770+ ++ Help.commaSep leftOnly ++ ". The other has "
771+ ++ Help.commaSep rightOnly ++ "."
777+ ( "The record fields do not match up. Maybe you made one of these typos?"
778+ , typoDocs "<->" typoPairs
782+oneMissingField :: [String] -> String -> Maybe (String, [Doc])
783+oneMissingField knownFields missingField =
784+ case Help.findPotentialTypos knownFields missingField of
787+ ( "Looks like a record is missing the `" ++ missingField ++ "` field."
793+ ( "Looks like a record is missing the `" ++ missingField
794+ ++ "` field. Maybe it is a typo?"
795+ , typoDocs "->" [(missingField, typo)]
800+ ( "Looks like a record is missing the `" ++ missingField
801+ ++ "` field. It is close to names like "
802+ ++ Help.commaSep typos ++ " so maybe it is a typo?"
749− else
807+manyMissingFields :: [String] -> [String] -> Maybe (String, [Doc])
750− let
808+manyMissingFields knownFields missingFields =
751− maxLen =
809+ case Help.findTypoPairs missingFields knownFields of
752− maximum (map (length . fst) typos)
810+ [] ->
755− ( "I compared the record fields and found some potential typos."
812+ ( "Looks like a record is missing these fields: "
756− , text "" : map (pad maxLen) typos
813+ ++ Help.commaSep missingFields
819+ ( "Looks like a record is missing these fields: " ++ Help.commaSep missingFields
820+ ++ ". Potential typos include:"
821+ , typoDocs "->" typoPairs
825+typoDocs :: String -> [(String, String)] -> [Doc]
826+typoDocs arrow typoPairs =
829+ maximum (map (length . fst) typoPairs)
831+ text "" : map (padTypo arrow maxLen) typoPairs
760−pad :: Int -> (String, String) -> Doc
834+padTypo :: String -> Int -> (String, String) -> Doc
761−pad maxLen (leftField, rightField) =
835+padTypo arrow maxLen (missingField, knownField) =
762− text (replicate (maxLen - length leftField) ' ')
836+ text (replicate (maxLen - length missingField) ' ')
763− <> dullyellow (text leftField)
837+ <> dullyellow (text missingField)
764− <+> text "<->"
838+ <+> text arrow
765− <+> dullyellow (text rightField)
839+ <+> dullyellow (text knownField)