@@ -25,6 +25,7 @@ import qualified Elm.Name as N
2525import qualified Reporting.Annotation as A
2626import qualified Reporting.Region as R
2727import qualified Reporting.Render.Code as Code
28+import qualified Reporting.Render.Type as RT
2829import qualified Reporting.Report as Report
2930import qualified Reporting.Helpers as H
3031import Reporting.Helpers ( Doc, (<+>), (<>) )
@@ -310,7 +311,8 @@ toReport source err =
310311 ExportNotFound region kind rawName possibleNames ->
311312 let
312313 suggestions =
313− take 4 (H.nearbyNames (N.toString rawName) (map N.toString possibleNames))
314+ map N.toString $ take 4 $
315+ H.nearbyNames N.toString rawName possibleNames
314316 in
315317 Report.Report "UNKNOWN EXPORT" region suggestions $
316318 let (a, thing, name) = toKindInfo kind rawName in
@@ -395,7 +397,8 @@ toReport source err =
395397 ImportExposingNotFound region (ModuleName.Canonical _ home) value possibleNames ->
396398 let
397399 suggestions =
398− take 4 $ H.nearbyNames (N.toString home) (map N.toString possibleNames)
400+ map N.toString $ take 4 $
401+ H.nearbyNames N.toString home possibleNames
399402 in
400403 Report.Report "BAD IMPORT" region suggestions $
401404 Report.toCodeSnippet source region Nothing
@@ -467,7 +470,8 @@ toReport source err =
467470 else
468471 let
469472 suggestions =
470− take 2 $ H.nearbyNames (N.toString op) (map N.toString (Set.toList locals))
473+ map N.toString $ take 2 $
474+ H.nearbyNames N.toString op (Set.toList locals)
471475
472476 format altOp =
473477 H.dullyellow $ "(" <> altOp <> ")"
@@ -889,7 +893,7 @@ notFound source region maybePrefix name thing (PossibleNames locals quals) =
889893 Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
890894
891895 nearbyNames =
892− take 4 (H.nearbyNames givenName possibleNames)
896+ take 4 (H.nearbyNames id givenName possibleNames)
893897
894898 toDetails noSuggestionDetails yesSuggestionDetails =
895899 case nearbyNames of
@@ -1066,7 +1070,7 @@ aliasRecursionReport source region name args tipe others =
10661070 "When I expand a recursive type alias, it just keeps getting bigger and bigger.\
10671071 \ So dealiasing results in an infinitely large type! Try this instead:"
10681072 , H.indent 4 $
1069− error "TODO alias to doc" name args tipe
1073+ aliasToUnionDoc name args tipe
10701074 , H.link "Hint"
10711075 "This is kind of a subtle distinction. I suggested the naive fix, but I recommend reading"
10721076 "recursive-alias"
@@ -1089,3 +1093,68 @@ aliasRecursionReport source region name args tipe others =
10891093 "to learn why this `type` vs `type alias` distinction matters. It is subtle but important!"
10901094 ]
10911095 )
1096+
1097+
1098+aliasToUnionDoc :: N.Name -> [N.Name] -> Src.Type -> Doc
1099+aliasToUnionDoc name args tipe =
1100+ H.vcat
1101+ [ H.dullyellow $
1102+ "type" <+> H.nameToDoc name <+> (foldr (<+>) "=" (map H.nameToDoc args))
1103+ , H.green $
1104+ H.indent 4 (H.nameToDoc name)
1105+ , H.dullyellow $
1106+ H.indent 8 (typeToDoc RT.App tipe)
1107+ ]
1108+
1109+
1110+typeToDoc :: RT.Context -> Src.Type -> Doc
1111+typeToDoc context (A.At _ tipe) =
1112+ case tipe of
1113+ Src.TLambda a b ->
1114+ RT.lambda context
1115+ (typeToDoc RT.Func a)
1116+ (map (typeToDoc RT.Func) (collectArgs b))
1117+
1118+ Src.TVar name ->
1119+ H.nameToDoc name
1120+
1121+ Src.TType _ name args ->
1122+ RT.apply context
1123+ (H.nameToDoc name)
1124+ (map (typeToDoc RT.App) args)
1125+
1126+ Src.TTypeQual _ home name args ->
1127+ RT.apply context
1128+ (H.nameToDoc home <> "." <> H.nameToDoc name)
1129+ (map (typeToDoc RT.App) args)
1130+
1131+ Src.TRecord fields ext ->
1132+ RT.record
1133+ (map fieldToDocs fields)
1134+ (fmap (H.nameToDoc . A.toValue) ext)
1135+
1136+ Src.TUnit ->
1137+ "()"
1138+
1139+ Src.TTuple a b cs ->
1140+ RT.tuple
1141+ (typeToDoc RT.None a)
1142+ (typeToDoc RT.None b)
1143+ (map (typeToDoc RT.None) cs)
1144+
1145+
1146+collectArgs :: Src.Type -> [Src.Type]
1147+collectArgs tipe =
1148+ case tipe of
1149+ A.At _ (Src.TLambda a b) ->
1150+ a : collectArgs b
1151+
1152+ _ ->
1153+ [tipe]
1154+
1155+
1156+fieldToDocs :: (A.Located N.Name, Src.Type) -> (Doc, Doc)
1157+fieldToDocs (A.At _ fieldName, fieldType) =
1158+ ( H.nameToDoc fieldName
1159+ , typeToDoc RT.None fieldType
1160+ )