@@ -1,15 +1,12 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Error.Canonicalize where
2module Reporting.Error.Canonicalize where
4−import Data.Function (on)
5−import qualified Data.List as List
6−import qualified Text.EditDistance as Dist
7import qualified Text.PrettyPrint as P
4import qualified Text.PrettyPrint as P
9import qualified AST.Module as Module
6import qualified AST.Module as Module
10import qualified AST.Type as Type
7import qualified AST.Type as Type
11import qualified AST.Variable as Var
8import qualified AST.Variable as Var
12−import Elm.Utils ((|>))
9+import qualified Reporting.Error.Helpers as Help
13import qualified Reporting.PrettyPrint as P
10import qualified Reporting.PrettyPrint as P
14import qualified Reporting.Region as Region
11import qualified Reporting.Region as Region
15import qualified Reporting.Report as Report
12import qualified Reporting.Report as Report
@@ -109,25 +106,6 @@ port name isInbound rootType localType maybeMessage =
109 Port (PortError name isInbound rootType localType maybeMessage)
106 Port (PortError name isInbound rootType localType maybeMessage)
114−nearbyNames :: (a -> String) -> a -> [a] -> [a]
115−nearbyNames format name names =
117− if length (format name) < 3 then 1 else 2
120− |> map (\x -> (distance (format name) (format x), x))
121− |> List.sortBy (compare `on` fst)
122− |> filter ( (<= editDistance) . abs . fst )
126−distance :: String -> String -> Int
128− Dist.restrictedDamerauLevenshteinDistance Dist.defaultEditCosts x y
131-- TO REPORT
109-- TO REPORT
133namingError :: String -> String -> Report.Report
111namingError :: String -> String -> Report.Report
@@ -145,26 +123,26 @@ toReport dealiaser err =
145 Ambiguous ->
123 Ambiguous ->
146 namingError
124 namingError
147 ("This usage of " ++ var ++ " is ambiguous.")
125 ("This usage of " ++ var ++ " is ambiguous.")
148− (maybeYouWant suggestions)
126+ (Help.maybeYouWant suggestions)
150 UnknownQualifier qualifier localName ->
128 UnknownQualifier qualifier localName ->
151 namingError
129 namingError
152 ("Cannot find " ++ var ++ ".")
130 ("Cannot find " ++ var ++ ".")
153 ( "The qualifier `" ++ qualifier ++ "` is not in scope. "
131 ( "The qualifier `" ++ qualifier ++ "` is not in scope. "
154− ++ maybeYouWant (map (\modul -> modul ++ "." ++ localName) suggestions)
132+ ++ Help.maybeYouWant (map (\modul -> modul ++ "." ++ localName) suggestions)
157 QualifiedUnknown qualifier localName ->
135 QualifiedUnknown qualifier localName ->
158 namingError
136 namingError
159 ("Cannot find " ++ var ++ ".")
137 ("Cannot find " ++ var ++ ".")
160 ( "`" ++ qualifier ++ "` does not expose `" ++ localName ++ "`. "
138 ( "`" ++ qualifier ++ "` does not expose `" ++ localName ++ "`. "
161− ++ maybeYouWant (map (\v -> qualifier ++ "." ++ v) suggestions)
139+ ++ Help.maybeYouWant (map (\v -> qualifier ++ "." ++ v) suggestions)
164 ExposedUnknown ->
142 ExposedUnknown ->
165 namingError
143 namingError
166 ("Cannot find " ++ var)
144 ("Cannot find " ++ var)
167− (maybeYouWant suggestions)
145+ (Help.maybeYouWant suggestions)
169 Pattern patternError ->
147 Pattern patternError ->
170 case patternError of
148 case patternError of
@@ -205,17 +183,17 @@ toReport dealiaser err =
205 ModuleNotFound suggestions ->
183 ModuleNotFound suggestions ->
206 namingError
184 namingError
207 ("Could not find a module named `" ++ moduleName ++ "`")
185 ("Could not find a module named `" ++ moduleName ++ "`")
208− (maybeYouWant (map Module.nameToString suggestions))
186+ (Help.maybeYouWant (map Module.nameToString suggestions))
210 ValueNotFound value suggestions ->
188 ValueNotFound value suggestions ->
211 namingError
189 namingError
212 ("Module `" ++ moduleName ++ "` does not expose `" ++ value ++ "`")
190 ("Module `" ++ moduleName ++ "` does not expose `" ++ value ++ "`")
213− (maybeYouWant suggestions)
191+ (Help.maybeYouWant suggestions)
215 Export name suggestions ->
193 Export name suggestions ->
216 namingError
194 namingError
217 ("Could not export `" ++ name ++ "` which is not defined in this module.")
195 ("Could not export `" ++ name ++ "` which is not defined in this module.")
218− (maybeYouWant suggestions)
196+ (Help.maybeYouWant suggestions)
220 Port (PortError name isInbound _rootType localType maybeMessage) ->
198 Port (PortError name isInbound _rootType localType maybeMessage) ->
@@ -250,17 +228,6 @@ argMismatchReport kind var expected actual =
250 Report.simple "ARGUMENT" preHint postHint
228 Report.simple "ARGUMENT" preHint postHint
253−maybeYouWant :: [String] -> String
254−maybeYouWant suggestions =
260− "Maybe you want one of the following?\n"
261− ++ concatMap ("\n "++) (take 4 suggestions)
264extractSuggestions :: Error -> Maybe [String]
231extractSuggestions :: Error -> Maybe [String]
265extractSuggestions err =
232extractSuggestions err =
266 case err of
233 case err of