1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Error.Import
10import qualified Data.Map as Map
11import qualified Data.Set as Set
13import qualified Elm.ModuleName as ModuleName
14import qualified Elm.Package as Pkg
15import qualified Reporting.Doc as D
16import qualified Reporting.Render.Code as Code
17import qualified Reporting.Report as Report
18import qualified Reporting.Suggest as Suggest
19import qualified Reporting.Annotation as A
29 , _import :: ModuleName.Raw
30 , _unimported :: Set.Set ModuleName.Raw
37 | Ambiguous FilePath [FilePath] Pkg.Name [Pkg.Name]
38 | AmbiguousLocal FilePath FilePath [FilePath]
39 | AmbiguousForeign Pkg.Name Pkg.Name [Pkg.Name]
46toReport :: Code.Source -> Error -> Report.Report
47toReport source (Error region name unimportedModules problem) =
50 Report.Report "MODULE NOT FOUND" region [] $
51 Code.toSnippet source region Nothing
54 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
59 "I checked the \"dependencies\" and \"source-directories\" listend in your elm.json,\
60 \ but I cannot find it! Maybe it is a typo for one of these names?"
62 D.dullyellow $ D.indent 4 $ D.vcat $
63 map D.fromName (toSuggestions name unimportedModules)
65 case Map.lookup name Pkg.suggestions of
68 "If it is not a typo, check the \"dependencies\" and \"source-directories\"\
69 \ of your elm.json to make sure all the packages you need are listed there!"
73 ["Maybe","you","want","the"
74 ,"`" <> D.fromName name <> "`"
75 ,"module","defined","in","the"
76 ,D.fromChars (Pkg.toChars dependency)
78 ,D.green (D.fromChars ("elm install " ++ Pkg.toChars dependency))
79 ,"should","make","it","available!"
84 Ambiguous path _ pkg _ ->
85 Report.Report "AMBIGUOUS IMPORT" region [] $
86 Code.toSnippet source region Nothing
89 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
94 ["But","I","found","multiple","modules","with","that","name.","One","in","the"
95 ,D.dullyellow (D.fromChars (Pkg.toChars pkg))
96 ,"package,","and","another","defined","locally","in","the"
97 ,D.dullyellow (D.fromChars path)
98 ,"file.","I","do","not","have","a","way","to","choose","between","them."
102 "Try changing the name of the locally defined module to clear up the ambiguity?"
106 AmbiguousLocal path1 path2 paths ->
107 Report.Report "AMBIGUOUS IMPORT" region [] $
108 Code.toSnippet source region Nothing
111 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
116 "But I found multiple files in your \"source-directories\" with that name:"
118 D.dullyellow $ D.indent 4 $ D.vcat $
119 map D.fromChars (path1:path2:paths)
122 "Change the module names to be distinct!"
126 AmbiguousForeign pkg1 pkg2 pkgs ->
127 Report.Report "AMBIGUOUS IMPORT" region [] $
128 Code.toSnippet source region Nothing
131 "You are trying to import a `" ++ ModuleName.toChars name ++ "` module:"
136 "But multiple packages in your \"dependencies\" that expose a module that name:"
138 D.dullyellow $ D.indent 4 $ D.vcat $
139 map (D.fromChars . Pkg.toChars) (pkg1:pkg2:pkgs)
142 "There is no way to disambiguate in cases like this right now. Of the known name\
143 \ clashes, they are usually for packages with similar purposes, so the current\
144 \ recommendation is to pick just one of them."
146 "It seems possible to resolve this with new syntax in imports, but that is\
147 \ more complicated than it sounds. Right now, our module names are tied to GitHub\
148 \ repos, but we may want to get rid of that dependency for a variety of reasons.\
149 \ That would in turn have implications for our package infrastructure, hosting\
150 \ costs, and possibly on how package names are specified. The particular syntax\
151 \ chosen seems like it would interact with all these factors in ways that are\
152 \ difficult to predict, potentially leading to harder problems later on. So more\
153 \ design work and planning is needed on these topics."
159toSuggestions :: ModuleName.Raw -> Set.Set ModuleName.Raw -> [ModuleName.Raw]
160toSuggestions name unimportedModules =
162 Suggest.sort (ModuleName.toChars name) ModuleName.toChars (Set.toList unimportedModules)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list