Skip to content

Commit ab4de0f

Browse files
committed
Only bring units actually depended on into scope on 9.4+
1 parent feb5965 commit ab4de0f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

ghcide/src/Development/IDE/Import/FindImports.hs

+15-1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import Data.Maybe
2929
import System.FilePath
3030
#if MIN_VERSION_ghc(9,3,0)
3131
import GHC.Types.PkgQual
32+
import GHC.Unit.State
3233
#endif
3334

3435
data Import
@@ -147,13 +148,26 @@ locateModule env comp_info exts targetFor modName mbPkgName isSource = do
147148
map snd import_paths
148149
#endif
149150

150-
mbFile <- locateModuleFile ((homeUnitId_ dflags, importPaths dflags) : import_paths') exts targetFor isSource $ unLoc modName
151+
mbFile <- locateModuleFile ((homeUnitId_ dflags, importPaths dflags) : other_imports) exts targetFor isSource $ unLoc modName
151152
case mbFile of
152153
Nothing -> lookupInPackageDB env
153154
Just (uid, file) -> toModLocation uid file
154155
where
155156
dflags = hsc_dflags env
156157
import_paths = mapMaybe (mkImportDirs env) comp_info
158+
other_imports =
159+
#if MIN_VERSION_ghc(9,4,0)
160+
-- On 9.4+ instead of bringing all the units into scope, only bring into scope the units
161+
-- this one depends on
162+
map (\uid -> (uid, importPaths (homeUnitEnv_dflags (ue_findHomeUnitEnv uid ue)))) hpt_deps
163+
ue = hsc_unit_env env
164+
units = homeUnitEnv_units $ ue_findHomeUnitEnv (homeUnitId_ dflags) ue
165+
hpt_deps :: [UnitId]
166+
hpt_deps = homeUnitDepends units
167+
#else
168+
import_paths'
169+
#endif
170+
157171
toModLocation uid file = liftIO $ do
158172
loc <- mkHomeModLocation dflags (unLoc modName) (fromNormalizedFilePath file)
159173
#if MIN_VERSION_ghc(9,0,0)

0 commit comments

Comments
 (0)