@@ -30,7 +30,7 @@ module Development.IDE.GHC.Util(
30
30
setHieDir ,
31
31
dontWriteHieFiles ,
32
32
disableWarningsAsErrors ,
33
- ) where
33
+ newHscEnvEqPreserveImportPaths ) where
34
34
35
35
import Control.Concurrent
36
36
import Data.List.Extra
@@ -178,24 +178,35 @@ data HscEnvEq = HscEnvEq
178
178
-- ^ In memory components for this HscEnv
179
179
-- This is only used at the moment for the import dirs in
180
180
-- the DynFlags
181
- , envImportPaths :: [String ]
182
- -- ^ Import dirs originally configured in this env
183
- -- We remove them to prevent GHC from loading modules on its own
181
+ , envImportPaths :: Maybe [String ]
182
+ -- ^ If Just, import dirs originally configured in this env
183
+ -- If Nothing, the env import dirs are unaltered
184
184
}
185
185
186
186
-- | Wrap an 'HscEnv' into an 'HscEnvEq'.
187
187
newHscEnvEq :: HscEnv -> [(InstalledUnitId , DynFlags )] -> IO HscEnvEq
188
188
newHscEnvEq hscEnv0 deps = do
189
189
envUnique <- newUnique
190
- let envImportPaths = importPaths $ hsc_dflags hscEnv0
190
+ let envImportPaths = Just $ importPaths $ hsc_dflags hscEnv0
191
191
hscEnv = removeImportPaths hscEnv0
192
192
return HscEnvEq {.. }
193
193
194
+ -- | Wrap an 'HscEnv' into an 'HscEnvEq'.
195
+ newHscEnvEqPreserveImportPaths
196
+ :: HscEnv -> [(InstalledUnitId , DynFlags )] -> IO HscEnvEq
197
+ newHscEnvEqPreserveImportPaths hscEnv deps = do
198
+ let envImportPaths = Nothing
199
+ envUnique <- newUnique
200
+ return HscEnvEq {.. }
201
+
194
202
-- | Unwrap the 'HscEnv' with the original import paths.
195
203
-- Used only for locating imports
196
204
hscEnvWithImportPaths :: HscEnvEq -> HscEnv
197
- hscEnvWithImportPaths HscEnvEq {.. } =
198
- hscEnv{hsc_dflags = (hsc_dflags hscEnv){importPaths = envImportPaths}}
205
+ hscEnvWithImportPaths HscEnvEq {.. }
206
+ | Just imps <- envImportPaths
207
+ = hscEnv{hsc_dflags = (hsc_dflags hscEnv){importPaths = imps}}
208
+ | otherwise
209
+ = hscEnv
199
210
200
211
removeImportPaths :: HscEnv -> HscEnv
201
212
removeImportPaths hsc = hsc{hsc_dflags = (hsc_dflags hsc){importPaths = [] }}
0 commit comments