@@ -57,16 +57,13 @@ data Error
5757 | ExportNotFound R.Region VarKind N.Name [N.Name]
5858 | ExportOpenAlias R.Region N.Name
5959 | ImportCtorByName R.Region N.Name N.Name
60− | ImportNotFound R.Region N.Name [N.Name]
60+ | ImportNotFound R.Region N.Name [ModuleName.Canonical]
6161 | ImportOpenAlias R.Region N.Name
62− | ImportExposingNotFound R.Region N.Name N.Name [N.Name]
63− | NotFoundVar R.Region N.Name PossibleNames
64− | NotFoundType R.Region N.Name PossibleNames
65− | NotFoundCtor R.Region N.Name PossibleNames
62+ | ImportExposingNotFound R.Region ModuleName.Canonical N.Name [N.Name]
63+ | NotFoundVar R.Region (Maybe N.Name) N.Name PossibleNames
64+ | NotFoundType R.Region (Maybe N.Name) N.Name PossibleNames
65+ | NotFoundCtor R.Region (Maybe N.Name) N.Name PossibleNames
6666 | NotFoundBinop R.Region N.Name (Set.Set N.Name)
67− | NotFoundVarQual R.Region N.Name N.Name PossibleNames
68− | NotFoundTypeQual R.Region N.Name N.Name PossibleNames
69− | NotFoundCtorQual R.Region N.Name N.Name PossibleNames
7067 | PatternHasRecordCtor R.Region N.Name
7168 | PortPayloadInvalid R.Region N.Name Can.Type InvalidPayload
7269 | PortTypeInvalid R.Region N.Name PortProblem
@@ -311,7 +308,11 @@ toReport source localizer err =
311308 "Remove one of them and you should be all set!"
312309 )
313310
314− ExportNotFound region kind rawName suggestions ->
311+ ExportNotFound region kind rawName possibleNames ->
312+ let
313+ suggestions =
314+ take 4 (H.nearbyNames (N.toString rawName) (map N.toString possibleNames))
315+ in
315316 Report.Report "UNKNOWN EXPORT" region suggestions $
316317 let (a, thing, name) = toKindInfo kind rawName in
317318 H.stack
@@ -319,7 +320,19 @@ toReport source localizer err =
319320 ["You","are","trying","to","expose",a,thing,"named"
320321 ,name,"but","I","cannot","find","its","definition."
321322 ]
322− , H.maybeYouWant Nothing suggestions
323+ , case map H.text suggestions of
324+ [] ->
325+ H.reflow $
326+ "I do not see any super similar names in this file. Is the definition missing?"
327+
328+ [alt] ->
329+ H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
330+
331+ alts ->
332+ H.stack
333+ [ "These names seem close though:"
334+ , H.indent 4 $ H.vcat $ map H.dullyellow alts
335+ ]
323336 ]
324337
325338 ExportOpenAlias region name ->
@@ -350,14 +363,18 @@ toReport source localizer err =
350363 ]
351364 )
352365
353− ImportNotFound region name suggestions ->
354− Report.Report "UNKNOWN IMPORT" region suggestions $
366+ ImportNotFound region name _ ->
367+ --
368+ -- NOTE: this should always be detected by `builder`
369+ -- So this error should never actually get printed out.
370+ --
371+ Report.Report "UNKNOWN IMPORT" region [] $
355372 Report.toCodeSnippet source region Nothing
356373 (
357374 H.reflow $
358375 "I could not find a `" <> N.toString name <> "` module to import!"
359376 ,
360− H.maybeYouWant Nothing suggestions
377+ mempty
361378 )
362379
363380 ImportOpenAlias region name ->
@@ -376,38 +393,89 @@ toReport source localizer err =
376393 ]
377394 )
378395
379− ImportExposingNotFound region name value suggestions ->
396+ ImportExposingNotFound region (ModuleName.Canonical _ home) value possibleNames ->
397+ let
398+ suggestions =
399+ take 4 $ H.nearbyNames (N.toString home) (map N.toString possibleNames)
400+ in
380401 Report.Report "BAD IMPORT" region suggestions $
381402 Report.toCodeSnippet source region Nothing
382403 (
383404 H.reflow $
384− "The `" <> N.toString name
405+ "The `" <> N.toString home
385406 <> "` module does not expose `"
386407 <> N.toString value <> "`:"
387408 ,
388− H.maybeYouWant Nothing suggestions
409+ case map H.text suggestions of
410+ [] ->
411+ "I cannot find an super similar exposed names. Maybe it is private?"
412+
413+ [alt] ->
414+ H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
415+
416+ alts ->
417+ H.stack
418+ [ "These names seem close though:"
419+ , H.indent 4 $ H.vcat $ map H.dullyellow alts
420+ ]
389421 )
390422
391− NotFoundVar region name possibleNames ->
392− error "TODO" region name possibleNames
423+ NotFoundVar region prefix name possibleNames ->
424+ notFound source region prefix name "variable" possibleNames
393425
394− NotFoundType region name possibleNames ->
395− error "TODO" region name possibleNames
426+ NotFoundType region prefix name possibleNames ->
427+ notFound source region prefix name "type" possibleNames
396428
397− NotFoundCtor region name possibleNames ->
398− error "TODO" region name possibleNames
429+ NotFoundCtor region prefix name possibleNames ->
430+ notFound source region prefix name "constructor" possibleNames
399431
400− NotFoundBinop region name locals ->
401− error "TODO" region name locals
432+ NotFoundBinop region op locals ->
433+ if op == "===" then
434+ Report.Report "TRIPLE EQUALS" region ["=="] $
435+ Report.toCodeSnippet source region Nothing
436+ (
437+ "Elm does not have a (===) operator like JavaScript."
438+ ,
439+ "Switch to (==) instead."
440+ )
402441
403− NotFoundVarQual region prefix name possibleNames ->
404− error "TODO" region prefix name possibleNames
442+ else if op == "!=" || op == "!==" then
443+ Report.Report "NOT EQUALS" region ["/="] $
444+ Report.toCodeSnippet source region Nothing
445+ (
446+ H.reflow $
447+ "Elm uses a different name for the “not equal” operator:"
448+ ,
449+ H.stack
450+ [ H.reflow "Switch to (/=) instead."
451+ , H.toSimpleNote $
452+ "Our (/=) operator is supposed to look like a real “not equal” sign (≠). I hope that history will remember ("
453+ ++ N.toString op ++ ") as a werid and temporary choice."
454+ ]
455+ )
405456
406− NotFoundTypeQual region prefix name possibleNames ->
407− error "TODO" region prefix name possibleNames
457+ else
458+ let
459+ suggestions =
460+ take 2 $ H.nearbyNames (N.toString op) (map N.toString (Set.toList locals))
461+
462+ format altOp =
463+ H.dullyellow $ "(" <> altOp <> ")"
464+ in
465+ Report.Report "UNKNOWN OPERATOR" region suggestions $
466+ Report.toCodeSnippet source region Nothing
467+ (
468+ H.reflow $
469+ "I do not recognize this (" ++ N.toString op ++ ") operator."
470+ ,
471+ case map H.text suggestions of
472+ [] ->
473+ H.reflow "Is there an `import` and `exposing` entry for it?"
408474
409− NotFoundCtorQual region prefix name possibleNames ->
410− error "TODO" region prefix name possibleNames
475+ alts ->
476+ H.fillSep $
477+ ["Maybe","you","want"] ++ H.commaSep "or" format alts ++ ["instead?"]
478+ )
411479
412480 PatternHasRecordCtor region name ->
413481 Report.Report "BAD PATTERN" region [] $
@@ -738,6 +806,73 @@ nameClash source r1 r2 messageThatEndsWithPunctuation =
738806
739807
740808
809+-- NOT FOUND
810+
811+
812+notFound :: Code.Source -> R.Region -> Maybe N.Name -> N.Name -> String -> PossibleNames -> Report.Report
813+notFound source region maybePrefix name thing (PossibleNames locals quals) =
814+ let
815+ givenName =
816+ maybe N.toString toQualString maybePrefix name
817+
818+ possibleNames =
819+ let
820+ addQuals prefix localSet allNames =
821+ Set.foldr (\x xs -> toQualString prefix x : xs) allNames localSet
822+ in
823+ Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
824+
825+ nearbyNames =
826+ take 4 (H.nearbyNames givenName possibleNames)
827+
828+ toDetails noSuggestionDetails yesSuggestionDetails =
829+ case nearbyNames of
830+ [] ->
831+ H.stack
832+ [ H.reflow noSuggestionDetails
833+ , H.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
834+ ]
835+
836+ suggestions ->
837+ H.stack
838+ [ H.reflow yesSuggestionDetails
839+ , H.indent 4 $ H.vcat $ map H.dullyellow $ map H.text suggestions
840+ , H.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
841+ ]
842+
843+ in
844+ Report.Report "NAMING ERROR" region nearbyNames $
845+ Report.toCodeSnippet source region Nothing
846+ (
847+ H.reflow $
848+ "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
849+ ,
850+ case maybePrefix of
851+ Nothing ->
852+ toDetails
853+ "Is there an `import` or `exposing` missing up top?"
854+ "These names seem close though:"
855+
856+ Just prefix ->
857+ case Map.lookup prefix quals of
858+ Nothing ->
859+ toDetails
860+ ("I cannot find a `" ++ N.toString prefix ++ "` module. Is there an `import` for it?")
861+ ("I cannot find a `" ++ N.toString prefix ++ "` import. These names seem close though:")
862+
863+ Just _ ->
864+ toDetails
865+ ("The `" ++ N.toString prefix ++ "` module does not expose a `" ++ N.toString name ++ "` " ++ thing ++ ".")
866+ ("The `" ++ N.toString prefix ++ "` module does not expose a `" ++ N.toString name ++ "` " ++ thing ++ ". These names seem close though:")
867+ )
868+
869+
870+toQualString :: N.Name -> N.Name -> String
871+toQualString prefix name =
872+ N.toString prefix ++ "." ++ N.toString name
873+
874+
875+
741876{-- VAR ERROR
742877
743878