Skip to content

Don't suggest imports from deprecated modules #2949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ghcide/src/Development/IDE/GHC/Compat/Core.hs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ module Development.IDE.GHC.Compat.Core (
loadInterface,
SourceModified(..),
loadModuleInterface,
Warnings(..),
RecompileRequired(..),
#if MIN_VERSION_ghc(8,10,0)
mkPartialIface,
Expand Down Expand Up @@ -614,6 +615,7 @@ import GHC.Unit.Module.ModGuts
import GHC.Unit.Module.ModIface (IfaceExport, ModIface (..),
ModIface_ (..))
import GHC.Unit.Module.ModSummary (ModSummary (..))
import GHC.Unit.Module.Warnings (Warnings (..))
#endif
import GHC.Unit.State (ModuleOrigin (..))
import GHC.Utils.Error (Severity (..))
Expand Down
37 changes: 16 additions & 21 deletions ghcide/src/Development/IDE/Types/Exports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module Development.IDE.Types.Exports
ExportsMap(..),
createExportsMap,
createExportsMapMg,
createExportsMapTc,
buildModuleExportMapFrom,
createExportsMapHieDb,
size,
Expand Down Expand Up @@ -120,7 +119,7 @@ createExportsMap modIface = do
ExportsMap exportsMap $ buildModuleExportMap $ map (\(_,b,c) -> (b, c)) exportList
where
doOne modIFace = do
let getModDetails = unpackAvail $ moduleName $ mi_module modIFace
let getModDetails = unpackAvail (moduleName $ mi_module modIFace) (mi_warns modIFace)
concatMap (fmap (second Set.fromList) . getModDetails) (mi_exports modIFace)

createExportsMapMg :: [ModGuts] -> ExportsMap
Expand All @@ -130,8 +129,8 @@ createExportsMapMg modGuts = do
ExportsMap exportsMap $ buildModuleExportMap $ map (\(_,b,c) -> (b, c)) exportList
where
doOne mi = do
let getModuleName = moduleName $ mg_module mi
concatMap (fmap (second Set.fromList) . unpackAvail getModuleName) (mg_exports mi)
let getModDetails = unpackAvail (moduleName $ mg_module mi) (mg_warns mi)
concatMap (fmap (second Set.fromList) . getModDetails) (mg_exports mi)

updateExportsMapMg :: [ModGuts] -> ExportsMap -> ExportsMap
updateExportsMapMg modGuts old = old' <> new
Expand All @@ -140,25 +139,15 @@ updateExportsMapMg modGuts old = old' <> new
old' = deleteAll old (Map.keys $ getModuleExportsMap new)
deleteAll = foldl' (flip deleteEntriesForModule)

createExportsMapTc :: [TcGblEnv] -> ExportsMap
createExportsMapTc modIface = do
let exportList = concatMap doOne modIface
let exportsMap = Map.fromListWith (<>) $ map (\(a,_,c) -> (a, c)) exportList
ExportsMap exportsMap $ buildModuleExportMap $ map (\(_,b,c) -> (b, c)) exportList
where
doOne mi = do
let getModuleName = moduleName $ tcg_mod mi
concatMap (fmap (second Set.fromList) . unpackAvail getModuleName) (tcg_exports mi)

nonInternalModules :: ModuleName -> Bool
nonInternalModules = not . (".Internal" `isSuffixOf`) . moduleNameString
isInternalModule :: ModuleName -> Bool
isInternalModule = (".Internal" `isSuffixOf`) . moduleNameString

type WithHieDb = forall a. (HieDb -> IO a) -> IO a

createExportsMapHieDb :: WithHieDb -> IO ExportsMap
createExportsMapHieDb withHieDb = do
mods <- withHieDb getAllIndexedMods
idents <- forM (filter (nonInternalModules . modInfoName . hieModInfo) mods) $ \m -> do
idents <- forM (filter (not . isInternalModule . modInfoName . hieModInfo) mods) $ \m -> do
let mn = modInfoName $ hieModInfo m
mText = pack $ moduleNameString mn
fmap (wrap . unwrap mText) <$> withHieDb (\hieDb -> getExportsForModule hieDb mn)
Expand All @@ -172,10 +161,16 @@ createExportsMapHieDb withHieDb = do
n = pack (occNameString exportName)
p = pack . occNameString <$> exportParent

unpackAvail :: ModuleName -> IfaceExport -> [(Text, Text, [IdentInfo])]
unpackAvail mn
| nonInternalModules mn = map f . mkIdentInfos mod
| otherwise = const []
unpackAvail :: ModuleName -> Warnings -> IfaceExport -> [(Text, Text, [IdentInfo])]
unpackAvail mn warnings
| isInternalModule mn = const []
| otherwise = case warnings of
NoWarnings -> map f . mkIdentInfos mod
WarnAll {} -> const []
WarnSome deprThings -> do
let deprNames = Set.fromList $ fst <$> deprThings
notDeprecated = not . flip Set.member deprNames
map f . filter (notDeprecated . name) . mkIdentInfos mod
where
!mod = pack $ moduleNameString mn
f id@IdentInfo {..} = (printOutputable name, moduleNameText,[id])
Expand Down