@@ -57,16 +57,13 @@ data Error
57 | ExportNotFound R.Region VarKind N.Name [N.Name]
57 | ExportNotFound R.Region VarKind N.Name [N.Name]
58 | ExportOpenAlias R.Region N.Name
58 | ExportOpenAlias R.Region N.Name
59 | ImportCtorByName R.Region N.Name N.Name
59 | ImportCtorByName R.Region N.Name N.Name
60− | ImportNotFound R.Region N.Name [N.Name]
60+ | ImportNotFound R.Region N.Name [ModuleName.Canonical]
61 | ImportOpenAlias R.Region N.Name
61 | ImportOpenAlias R.Region N.Name
62− | ImportExposingNotFound R.Region N.Name N.Name [N.Name]
62+ | ImportExposingNotFound R.Region ModuleName.Canonical N.Name [N.Name]
63− | NotFoundVar R.Region N.Name PossibleNames
63+ | NotFoundVar R.Region (Maybe N.Name) N.Name PossibleNames
64− | NotFoundType R.Region N.Name PossibleNames
64+ | NotFoundType R.Region (Maybe N.Name) N.Name PossibleNames
65− | NotFoundCtor R.Region N.Name PossibleNames
65+ | NotFoundCtor R.Region (Maybe N.Name) N.Name PossibleNames
66 | NotFoundBinop R.Region N.Name (Set.Set N.Name)
66 | 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
70 | PatternHasRecordCtor R.Region N.Name
67 | PatternHasRecordCtor R.Region N.Name
71 | PortPayloadInvalid R.Region N.Name Can.Type InvalidPayload
68 | PortPayloadInvalid R.Region N.Name Can.Type InvalidPayload
72 | PortTypeInvalid R.Region N.Name PortProblem
69 | PortTypeInvalid R.Region N.Name PortProblem
@@ -311,7 +308,11 @@ toReport source localizer err =
311 "Remove one of them and you should be all set!"
308 "Remove one of them and you should be all set!"
314− ExportNotFound region kind rawName suggestions ->
311+ ExportNotFound region kind rawName possibleNames ->
314+ take 4 (H.nearbyNames (N.toString rawName) (map N.toString possibleNames))
315 Report.Report "UNKNOWN EXPORT" region suggestions $
316 Report.Report "UNKNOWN EXPORT" region suggestions $
316 let (a, thing, name) = toKindInfo kind rawName in
317 let (a, thing, name) = toKindInfo kind rawName in
@@ -319,7 +320,19 @@ toReport source localizer err =
319 ["You","are","trying","to","expose",a,thing,"named"
320 ["You","are","trying","to","expose",a,thing,"named"
320 ,name,"but","I","cannot","find","its","definition."
321 ,name,"but","I","cannot","find","its","definition."
322− , H.maybeYouWant Nothing suggestions
323+ , case map H.text suggestions of
326+ "I do not see any super similar names in this file. Is the definition missing?"
329+ H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
333+ [ "These names seem close though:"
334+ , H.indent 4 $ H.vcat $ map H.dullyellow alts
325 ExportOpenAlias region name ->
338 ExportOpenAlias region name ->
@@ -350,14 +363,18 @@ toReport source localizer err =
353− ImportNotFound region name suggestions ->
366+ ImportNotFound region name _ ->
368+ -- NOTE: this should always be detected by `builder`
369+ -- So this error should never actually get printed out.
354− Report.Report "UNKNOWN IMPORT" region suggestions $
371+ Report.Report "UNKNOWN IMPORT" region [] $
355 Report.toCodeSnippet source region Nothing
372 Report.toCodeSnippet source region Nothing
357 H.reflow $
374 H.reflow $
358 "I could not find a `" <> N.toString name <> "` module to import!"
375 "I could not find a `" <> N.toString name <> "` module to import!"
360− H.maybeYouWant Nothing suggestions
377+ mempty
363 ImportOpenAlias region name ->
380 ImportOpenAlias region name ->
@@ -376,38 +393,89 @@ toReport source localizer err =
379− ImportExposingNotFound region name value suggestions ->
396+ ImportExposingNotFound region (ModuleName.Canonical _ home) value possibleNames ->
399+ take 4 $ H.nearbyNames (N.toString home) (map N.toString possibleNames)
380 Report.Report "BAD IMPORT" region suggestions $
401 Report.Report "BAD IMPORT" region suggestions $
381 Report.toCodeSnippet source region Nothing
402 Report.toCodeSnippet source region Nothing
383 H.reflow $
404 H.reflow $
384− "The `" <> N.toString name
405+ "The `" <> N.toString home
385 <> "` module does not expose `"
406 <> "` module does not expose `"
386 <> N.toString value <> "`:"
407 <> N.toString value <> "`:"
388− H.maybeYouWant Nothing suggestions
409+ case map H.text suggestions of
411+ "I cannot find an super similar exposed names. Maybe it is private?"
414+ H.fillSep ["Maybe","you","want",H.dullyellow alt,"instead?"]
418+ [ "These names seem close though:"
419+ , H.indent 4 $ H.vcat $ map H.dullyellow alts
391− NotFoundVar region name possibleNames ->
423+ NotFoundVar region prefix name possibleNames ->
392− error "TODO" region name possibleNames
424+ notFound source region prefix name "variable" possibleNames
394− NotFoundType region name possibleNames ->
426+ NotFoundType region prefix name possibleNames ->
395− error "TODO" region name possibleNames
427+ notFound source region prefix name "type" possibleNames
397− NotFoundCtor region name possibleNames ->
429+ NotFoundCtor region prefix name possibleNames ->
398− error "TODO" region name possibleNames
430+ notFound source region prefix name "constructor" possibleNames
400− NotFoundBinop region name locals ->
432+ NotFoundBinop region op locals ->
401− error "TODO" region name locals
433+ if op == "===" then
434+ Report.Report "TRIPLE EQUALS" region ["=="] $
435+ Report.toCodeSnippet source region Nothing
437+ "Elm does not have a (===) operator like JavaScript."
439+ "Switch to (==) instead."
403− NotFoundVarQual region prefix name possibleNames ->
442+ else if op == "!=" || op == "!==" then
404− error "TODO" region prefix name possibleNames
443+ Report.Report "NOT EQUALS" region ["/="] $
444+ Report.toCodeSnippet source region Nothing
447+ "Elm uses a different name for the “not equal” operator:"
450+ [ H.reflow "Switch to (/=) instead."
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."
406− NotFoundTypeQual region prefix name possibleNames ->
457+ else
407− error "TODO" region prefix name possibleNames
458+ let
460+ take 2 $ H.nearbyNames (N.toString op) (map N.toString (Set.toList locals))
463+ H.dullyellow $ "(" <> altOp <> ")"
465+ Report.Report "UNKNOWN OPERATOR" region suggestions $
466+ Report.toCodeSnippet source region Nothing
469+ "I do not recognize this (" ++ N.toString op ++ ") operator."
471+ case map H.text suggestions of
473+ H.reflow "Is there an `import` and `exposing` entry for it?"
409− NotFoundCtorQual region prefix name possibleNames ->
475+ alts ->
410− error "TODO" region prefix name possibleNames
476+ H.fillSep $
477+ ["Maybe","you","want"] ++ H.commaSep "or" format alts ++ ["instead?"]
412 PatternHasRecordCtor region name ->
480 PatternHasRecordCtor region name ->
413 Report.Report "BAD PATTERN" region [] $
481 Report.Report "BAD PATTERN" region [] $
@@ -738,6 +806,73 @@ nameClash source r1 r2 messageThatEndsWithPunctuation =
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) =
816+ maybe N.toString toQualString maybePrefix name
820+ addQuals prefix localSet allNames =
821+ Set.foldr (\x xs -> toQualString prefix x : xs) allNames localSet
823+ Map.foldrWithKey addQuals (map N.toString (Set.toList locals)) quals
826+ take 4 (H.nearbyNames givenName possibleNames)
828+ toDetails noSuggestionDetails yesSuggestionDetails =
832+ [ H.reflow noSuggestionDetails
833+ , H.link "Hint" "Read" "imports" "to see how `import` declarations work in Elm."
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."
844+ Report.Report "NAMING ERROR" region nearbyNames $
845+ Report.toCodeSnippet source region Nothing
848+ "I cannot find a `" ++ givenName ++ "` " ++ thing ++ ":"
853+ "Is there an `import` or `exposing` missing up top?"
854+ "These names seem close though:"
857+ case Map.lookup prefix quals of
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:")
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:")
870+toQualString :: N.Name -> N.Name -> String
871+toQualString prefix name =
872+ N.toString prefix ++ "." ++ N.toString name
741{-- VAR ERROR
876{-- VAR ERROR