Skip to content

Commit e870cf4

Browse files
committed
Customize the unitId used for the internal component
1 parent 7817a10 commit e870cf4

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

ghcide/session-loader/Development/IDE/Session.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
222222
, optCheckProject = getCheckProject
223223
, optCustomDynFlags
224224
, optExtensions
225+
, optFakeUid
225226
} <- getIdeOptions
226227

227228
-- populate the knownTargetsVar with all the
@@ -274,7 +275,7 @@ loadSessionWithOptions SessionLoadingOptions{..} dir = do
274275
new_deps' <- forM new_deps $ \RawComponentInfo{..} -> do
275276
-- Remove all inplace dependencies from package flags for
276277
-- components in this HscEnv
277-
let (df2, uids) = removeInplacePackages inplace rawComponentDynFlags
278+
let (df2, uids) = removeInplacePackages optFakeUid inplace rawComponentDynFlags
278279
let prefix = show rawComponentUnitId
279280
-- See Note [Avoiding bad interface files]
280281
let hscComponents = sort $ map show uids
@@ -713,12 +714,15 @@ getDependencyInfo fs = Map.fromList <$> mapM do_one fs
713714
-- There are several places in GHC (for example the call to hptInstances in
714715
-- tcRnImports) which assume that all modules in the HPT have the same unit
715716
-- ID. Therefore we create a fake one and give them all the same unit id.
716-
removeInplacePackages :: [InstalledUnitId] -> DynFlags -> (DynFlags, [InstalledUnitId])
717-
removeInplacePackages us df = (df { packageFlags = ps
717+
removeInplacePackages
718+
:: InstalledUnitId -- ^ fake uid to use for our internal component
719+
-> [InstalledUnitId]
720+
-> DynFlags
721+
-> (DynFlags, [InstalledUnitId])
722+
removeInplacePackages fake_uid us df = (df { packageFlags = ps
718723
, thisInstalledUnitId = fake_uid }, uids)
719724
where
720725
(uids, ps) = partitionEithers (map go (packageFlags df))
721-
fake_uid = toInstalledUnitId (stringToUnitId "fake_uid")
722726
go p@(ExposePackage _ (UnitIdArg u) _) = if toInstalledUnitId u `elem` us
723727
then Left (toInstalledUnitId u)
724728
else Right p

ghcide/src/Development/IDE/Types/Options.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ data IdeOptions = IdeOptions
8484
-- ^ Will be called right after setting up a new cradle,
8585
-- allowing to customize the Ghc options used
8686
, optShakeOptions :: ShakeOptions
87+
, optFakeUid :: InstalledUnitId
8788
}
8889

8990
optShakeFiles :: IdeOptions -> Maybe FilePath
@@ -136,6 +137,7 @@ defaultIdeOptions session = IdeOptions
136137
,optCheckParents = pure CheckOnSaveAndClose
137138
,optHaddockParse = HaddockParse
138139
,optCustomDynFlags = id
140+
,optFakeUid = toInstalledUnitId (stringToUnitId "fake_uid")
139141
}
140142

141143

0 commit comments

Comments
 (0)