@@ -25,6 +25,7 @@ import qualified Elm.Name as N
25import qualified Reporting.Annotation as A
25import qualified Reporting.Annotation as A
26import qualified Reporting.Region as R
26import qualified Reporting.Region as R
27import qualified Reporting.Render.Code as Code
27import qualified Reporting.Render.Code as Code
28+import qualified Reporting.Render.Type as RT
28import qualified Reporting.Report as Report
29import qualified Reporting.Report as Report
29import qualified Reporting.Helpers as H
30import qualified Reporting.Helpers as H
30import Reporting.Helpers ( Doc, (<+>), (<>) )
31import Reporting.Helpers ( Doc, (<+>), (<>) )
@@ -310,7 +311,8 @@ toReport source err =
310 ExportNotFound region kind rawName possibleNames ->
311 ExportNotFound region kind rawName possibleNames ->
312 suggestions =
313 suggestions =
314+ map N.toString $ take 4 $
313− take 4 (H.nearbyNames (N.toString rawName) (map N.toString possibleNames))
315+ H.nearbyNames N.toString rawName possibleNames
315 Report.Report "UNKNOWN EXPORT" region suggestions $
317 Report.Report "UNKNOWN EXPORT" region suggestions $
316 let (a, thing, name) = toKindInfo kind rawName in
318 let (a, thing, name) = toKindInfo kind rawName in
@@ -395,7 +397,8 @@ toReport source err =
395 ImportExposingNotFound region (ModuleName.Canonical _ home) value possibleNames ->
397 ImportExposingNotFound region (ModuleName.Canonical _ home) value possibleNames ->
397 suggestions =
399 suggestions =
400+ map N.toString $ take 4 $
398− take 4 $ H.nearbyNames (N.toString home) (map N.toString possibleNames)
401+ H.nearbyNames N.toString home possibleNames
400 Report.Report "BAD IMPORT" region suggestions $
403 Report.Report "BAD IMPORT" region suggestions $
401 Report.toCodeSnippet source region Nothing
404 Report.toCodeSnippet source region Nothing
@@ -467,7 +470,8 @@ toReport source err =
469 suggestions =
472 suggestions =
473+ map N.toString $ take 2 $
470− take 2 $ H.nearbyNames (N.toString op) (map N.toString (Set.toList locals))
474+ H.nearbyNames N.toString op (Set.toList locals)
472 format altOp =
476 format altOp =
473 H.dullyellow $ "(" <> altOp <> ")"
477 H.dullyellow $ "(" <> altOp <> ")"
@@ -889,7 +893,7 @@ notFound source region maybePrefix name thing (PossibleNames locals quals) =
889 Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
893 Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
891 nearbyNames =
895 nearbyNames =
892− take 4 (H.nearbyNames givenName possibleNames)
896+ take 4 (H.nearbyNames id givenName possibleNames)
894 toDetails noSuggestionDetails yesSuggestionDetails =
898 toDetails noSuggestionDetails yesSuggestionDetails =
895 case nearbyNames of
899 case nearbyNames of
@@ -1066,7 +1070,7 @@ aliasRecursionReport source region name args tipe others =
1066 "When I expand a recursive type alias, it just keeps getting bigger and bigger.\
1070 "When I expand a recursive type alias, it just keeps getting bigger and bigger.\
1067 \ So dealiasing results in an infinitely large type! Try this instead:"
1071 \ So dealiasing results in an infinitely large type! Try this instead:"
1068 , H.indent 4 $
1072 , H.indent 4 $
1069− error "TODO alias to doc" name args tipe
1073+ aliasToUnionDoc name args tipe
1070 , H.link "Hint"
1074 , H.link "Hint"
1071 "This is kind of a subtle distinction. I suggested the naive fix, but I recommend reading"
1075 "This is kind of a subtle distinction. I suggested the naive fix, but I recommend reading"
1072 "recursive-alias"
1076 "recursive-alias"
@@ -1089,3 +1093,68 @@ aliasRecursionReport source region name args tipe others =
1089 "to learn why this `type` vs `type alias` distinction matters. It is subtle but important!"
1093 "to learn why this `type` vs `type alias` distinction matters. It is subtle but important!"
1098+aliasToUnionDoc :: N.Name -> [N.Name] -> Src.Type -> Doc
1099+aliasToUnionDoc name args tipe =
1102+ "type" <+> H.nameToDoc name <+> (foldr (<+>) "=" (map H.nameToDoc args))
1104+ H.indent 4 (H.nameToDoc name)
1106+ H.indent 8 (typeToDoc RT.App tipe)
1110+typeToDoc :: RT.Context -> Src.Type -> Doc
1111+typeToDoc context (A.At _ tipe) =
1115+ (typeToDoc RT.Func a)
1116+ (map (typeToDoc RT.Func) (collectArgs b))
1121+ Src.TType _ name args ->
1124+ (map (typeToDoc RT.App) args)
1126+ Src.TTypeQual _ home name args ->
1128+ (H.nameToDoc home <> "." <> H.nameToDoc name)
1129+ (map (typeToDoc RT.App) args)
1131+ Src.TRecord fields ext ->
1133+ (map fieldToDocs fields)
1134+ (fmap (H.nameToDoc . A.toValue) ext)
1139+ Src.TTuple a b cs ->
1141+ (typeToDoc RT.None a)
1142+ (typeToDoc RT.None b)
1143+ (map (typeToDoc RT.None) cs)
1146+collectArgs :: Src.Type -> [Src.Type]
1149+ A.At _ (Src.TLambda a b) ->
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