on master help sign in
Make canonicalization hint a bit friendlier
39de107Evan Czaplicki
src/Reporting/Error/Canonicalize.hs+12−8
@@ -19,7 +19,7 @@ import qualified Reporting.Render.Type as RenderType
19import qualified Reporting.Report as Report
19import qualified Reporting.Report as Report
20import qualified Reporting.Helpers as Help
20import qualified Reporting.Helpers as Help
21import Reporting.Helpers
21import Reporting.Helpers
22− ( Doc, (<>), dullyellow, fillSep, i2t, indent, maybeYouWant, reflowParagraph, text
22+ ( Doc, (<>), dullyellow, fillSep, i2t, indent, reflowParagraph, text
23 )
23 )
24
24
25
25
@@ -141,14 +141,18 @@ toReport localizer err =
141 variableName =
141 variableName =
142 kind <> " `" <> name <> "`"
142 kind <> " `" <> name <> "`"
143
143
144− learnMore =
144+ learnMore orMaybe =
145− Help.toHint $
145+ Help.reflowParagraph $
146− "New to Elm? Unsure exactly how `import` works? Learn all about it here: "
146+ orMaybe <> " `import` works different than you expect? Learn all about it here: "
147 <> Help.hintLink "imports"
147 <> Help.hintLink "imports"
148
148
149 namingError overview maybeStarter specializedSuggestions =
149 namingError overview maybeStarter specializedSuggestions =
150 Report.report "NAMING ERROR" Nothing overview $
150 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" ]
152 in
156 in
153 case problem of
157 case problem of
154 Ambiguous ->
158 Ambiguous ->
@@ -244,17 +248,17 @@ toReport localizer err =
244 ModuleNotFound suggestions ->
248 ModuleNotFound suggestions ->
245 Report.report "IMPORT ERROR" Nothing
249 Report.report "IMPORT ERROR" Nothing
246 ("Could not find a module named `" <> ModuleName.toText name <> "`")
250 ("Could not find a module named `" <> ModuleName.toText name <> "`")
247− (maybeYouWant Nothing suggestions Nothing)
251+ (Help.maybeYouWant Nothing suggestions)
248
252
249 ValueNotFound value suggestions ->
253 ValueNotFound value suggestions ->
250 Report.report "IMPORT ERROR" Nothing
254 Report.report "IMPORT ERROR" Nothing
251 ("Module `" <> ModuleName.toText name <> "` does not expose `" <> value <> "`")
255 ("Module `" <> ModuleName.toText name <> "` does not expose `" <> value <> "`")
252− (maybeYouWant Nothing suggestions Nothing)
256+ (Help.maybeYouWant Nothing suggestions)
253
257
254 Export name suggestions ->
258 Export name suggestions ->
255 Report.report "EXPOSING ERROR" Nothing
259 Report.report "EXPOSING ERROR" Nothing
256 ("Could not expose `" <> name <> "` which is not defined in this module.")
260 ("Could not expose `" <> name <> "` which is not defined in this module.")
257− (maybeYouWant Nothing suggestions Nothing)
261+ (Help.maybeYouWant Nothing suggestions)
258
262
259 DuplicateExport name ->
263 DuplicateExport name ->
260 Report.report "EXPOSING ERROR" Nothing
264 Report.report "EXPOSING ERROR" Nothing
src/Reporting/Error/Docs.hs+1−1
@@ -42,7 +42,7 @@ toReport err =
42 Nothing
42 Nothing
43 ("Your module documentation includes `" <> name <> "` which is not exported."
43 ("Your module documentation includes `" <> name <> "` which is not exported."
44 )
44 )
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
46 )
46 )
47
47
48 OnlyInExports names ->
48 OnlyInExports names ->
src/Reporting/Helpers.hs+11−19
@@ -11,7 +11,7 @@ module Reporting.Helpers
11 , toHint, hintLink, stack, reflowParagraph
11 , toHint, hintLink, stack, reflowParagraph
12 , commaSep, capitalize, ordinalize, drawCycle
12 , commaSep, capitalize, ordinalize, drawCycle
13 , findPotentialTypos, findTypoPairs, vetTypos
13 , findPotentialTypos, findTypoPairs, vetTypos
14− , nearbyNames, distance, maybeYouWant
14+ , nearbyNames, distance, maybeYouWant, maybeYouWant'
15 )
15 )
16 where
16 where
17
17
@@ -234,27 +234,19 @@ distance x y =
234 (Text.unpack y)
234 (Text.unpack y)
235
235
236
236
237−maybeYouWant :: Maybe Doc -> [Text] -> Maybe Doc -> Doc
237+maybeYouWant :: Maybe Doc -> [Text] -> Doc
238−maybeYouWant maybeStarter suggestions maybeEnder =
238+maybeYouWant maybeStarter suggestions =
239− case suggestions of
239+ maybe P.empty id (maybeYouWant' maybeStarter suggestions)
240− [] ->
241− case (maybeStarter, maybeEnder) of
242− (Nothing, Nothing) ->
243− P.empty
244−
245− (Just starter, Nothing) ->
246− starter
247
240
248− (Nothing, Just ender) ->
249− ender
250
241
251− (Just starter, Just ender) ->
242+maybeYouWant' :: Maybe Doc -> [Text] -> Maybe Doc
252− stack [ starter, ender ]
243+maybeYouWant' maybeStarter suggestions =
244+ case suggestions of
245+ [] ->
246+ maybeStarter
253
247
254 _:_ ->
248 _:_ ->
255− stack $
249+ Just $ stack $
256 [ maybe id (<+>) maybeStarter "Maybe you want one of the following?"
250 [ 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)
258 ]
252 ]
259− ++ maybe [] pure maybeEnder
260−