- | null found = return (NotFound [] Nothing)
- -- found in just one exposed package:
- | [(pkg_conf, _)] <- found_exposed
- = let pkgid = mkPackageId (package pkg_conf) in
- findPackageModule_ hsc_env (mkModule pkgid mod_name) pkg_conf
- -- not found in any exposed package, report how it was hidden:
- | null found_exposed, ((pkg_conf, exposed_mod):_) <- found
- = let pkgid = mkPackageId (package pkg_conf) in
- if not (exposed_mod)
- then return (ModuleHidden pkgid)
- else return (PackageHidden pkgid)
- | otherwise
- = return (FoundMultiple (map (mkPackageId.package.fst) found_exposed))
- where
- dflags = hsc_dflags hsc_env
- found = lookupModuleInAllPackages dflags mod_name
-
- found_exposed = [ (pkg_conf,exposed_mod)
- | x@(pkg_conf,exposed_mod) <- found,
- is_exposed x,
- pkg_conf `matches` mb_pkg ]
-
- is_exposed (pkg_conf,exposed_mod) = exposed pkg_conf && exposed_mod
-
- _pkg_conf `matches` Nothing = True
- pkg_conf `matches` Just pkg =
- case packageName pkg_conf of
- PackageName n -> pkg == mkFastString n
-
+ = case lookupModuleWithSuggestions (hsc_dflags hsc_env) mod_name of
+ Left suggest -> return (NotFound { fr_paths = [], fr_pkg = Nothing
+ , fr_pkgs_hidden = [], fr_mods_hidden = []
+ , fr_suggestions = suggest })
+ Right found
+ | null found_exposed -- Found, but with no exposed copies
+ -> return (NotFound { fr_paths = [], fr_pkg = Nothing
+ , fr_pkgs_hidden = mod_hiddens, fr_mods_hidden = pkg_hiddens
+ , fr_suggestions = [] })
+
+ | [(pkg_conf,_)] <- found_exposed -- Found uniquely
+ -> let pkgid = packageConfigId pkg_conf in
+ findPackageModule_ hsc_env (mkModule pkgid mod_name) pkg_conf
+
+ | otherwise -- Found in more than one place
+ -> return (FoundMultiple (map (packageConfigId.fst) found_exposed))
+ where
+ for_this_pkg = case mb_pkg of
+ Nothing -> found
+ Just p -> filter ((`matches` p) . fst) found
+ found_exposed = filter is_exposed for_this_pkg
+ is_exposed (pkg_conf,exposed_mod) = exposed pkg_conf && exposed_mod
+
+ mod_hiddens = [ packageConfigId pkg_conf
+ | (pkg_conf,False) <- found ]
+
+ pkg_hiddens = [ packageConfigId pkg_conf
+ | (pkg_conf,_) <- found, not (exposed pkg_conf) ]
+
+ pkg_conf `matches` pkg
+ = case packageName pkg_conf of
+ PackageName n -> pkg == mkFastString n