on master help sign in
Make canonicalization hint a bit friendlier

Any level of programmer can be surprised by how `import` works in Elm. This stuff is always slightly different and it’s always a pain to find docs on it because it is “so common” to know. So the new message has the compiler take more responsibility for any confusion around this. This change also makes the suggestions yellow.

commit39de107e53cbbff9af26f48b125fc95519f43f7b authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 11 Jul 2017, 00:51 (9 years ago) parent61e7508
3 files changed+24−28
src/Reporting/Error/Canonicalize.hs+12−8 src/Reporting/Error/Docs.hs+1−1 src/Reporting/Helpers.hs+11−19
src/Reporting/Error/Canonicalize.hs+12−8
@@ -19,7 +19,7 @@ import qualified Reporting.Render.Type as RenderType
1919import qualified Reporting.Report as Report
2020import qualified Reporting.Helpers as Help
2121import Reporting.Helpers
22− ( Doc, (<>), dullyellow, fillSep, i2t, indent, maybeYouWant, reflowParagraph, text
22+ ( Doc, (<>), dullyellow, fillSep, i2t, indent, reflowParagraph, text
2323 )
2424
2525
@@ -141,14 +141,18 @@ toReport localizer err =
141141 variableName =
142142 kind <> " `" <> name <> "`"
143143
144− learnMore =
145− Help.toHint $
146− "New to Elm? Unsure exactly how `import` works? Learn all about it here: "
144+ learnMore orMaybe =
145+ Help.reflowParagraph $
146+ orMaybe <> " `import` works different than you expect? Learn all about it here: "
147147 <> Help.hintLink "imports"
148148
149149 namingError overview maybeStarter specializedSuggestions =
150150 Report.report "NAMING ERROR" Nothing overview $
151− maybeYouWant maybeStarter specializedSuggestions (Just learnMore)
151+ case Help.maybeYouWant' maybeStarter specializedSuggestions of
152+ Nothing ->
153+ learnMore "Maybe"
154+ Just doc ->
155+ Help.stack [ doc, learnMore "Or maybe" ]
152156 in
153157 case problem of
154158 Ambiguous ->
@@ -244,17 +248,17 @@ toReport localizer err =
244248 ModuleNotFound suggestions ->
245249 Report.report "IMPORT ERROR" Nothing
246250 ("Could not find a module named `" <> ModuleName.toText name <> "`")
247− (maybeYouWant Nothing suggestions Nothing)
251+ (Help.maybeYouWant Nothing suggestions)
248252
249253 ValueNotFound value suggestions ->
250254 Report.report "IMPORT ERROR" Nothing
251255 ("Module `" <> ModuleName.toText name <> "` does not expose `" <> value <> "`")
252− (maybeYouWant Nothing suggestions Nothing)
256+ (Help.maybeYouWant Nothing suggestions)
253257
254258 Export name suggestions ->
255259 Report.report "EXPOSING ERROR" Nothing
256260 ("Could not expose `" <> name <> "` which is not defined in this module.")
257− (maybeYouWant Nothing suggestions Nothing)
261+ (Help.maybeYouWant Nothing suggestions)
258262
259263 DuplicateExport name ->
260264 Report.report "EXPOSING ERROR" Nothing
src/Reporting/Error/Docs.hs+1−1
@@ -42,7 +42,7 @@ toReport err =
4242 Nothing
4343 ("Your module documentation includes `" <> name <> "` which is not exported."
4444 )
45− ( Help.maybeYouWant (Just "Is it misspelled? Should it be exported?") suggestions Nothing
45+ ( Help.maybeYouWant (Just "Is it misspelled? Should it be exported?") suggestions
4646 )
4747
4848 OnlyInExports names ->
src/Reporting/Helpers.hs+11−19
@@ -11,7 +11,7 @@ module Reporting.Helpers
1111 , toHint, hintLink, stack, reflowParagraph
1212 , commaSep, capitalize, ordinalize, drawCycle
1313 , findPotentialTypos, findTypoPairs, vetTypos
14− , nearbyNames, distance, maybeYouWant
14+ , nearbyNames, distance, maybeYouWant, maybeYouWant'
1515 )
1616 where
1717
@@ -234,27 +234,19 @@ distance x y =
234234 (Text.unpack y)
235235
236236
237−maybeYouWant :: Maybe Doc -> [Text] -> Maybe Doc -> Doc
238−maybeYouWant maybeStarter suggestions maybeEnder =
239− case suggestions of
240− [] ->
241− case (maybeStarter, maybeEnder) of
242− (Nothing, Nothing) ->
243− P.empty
244−
245− (Just starter, Nothing) ->
246− starter
237+maybeYouWant :: Maybe Doc -> [Text] -> Doc
238+maybeYouWant maybeStarter suggestions =
239+ maybe P.empty id (maybeYouWant' maybeStarter suggestions)
247240
248− (Nothing, Just ender) ->
249− ender
250241
251− (Just starter, Just ender) ->
252− stack [ starter, ender ]
242+maybeYouWant' :: Maybe Doc -> [Text] -> Maybe Doc
243+maybeYouWant' maybeStarter suggestions =
244+ case suggestions of
245+ [] ->
246+ maybeStarter
253247
254248 _:_ ->
255− stack $
249+ Just $ stack $
256250 [ maybe id (<+>) maybeStarter "Maybe you want one of the following?"
257− , P.indent 4 (P.vcat (map text (take 4 suggestions)))
251+ , P.indent 4 $ P.vcat $ map (P.dullyellow . text) (take 4 suggestions)
258252 ]
259− ++ maybe [] pure maybeEnder
260−