@@ -729,8 +729,17 @@ emptyHscEnv :: IORef NameCache -> FilePath -> IO HscEnv
729
729
#endif
730
730
emptyHscEnv nc libDir = do
731
731
-- We call setSessionDynFlags so that the loader is initialised
732
- env <- runGhc (Just libDir) $ getSessionDynFlags >>= setSessionDynFlags >> getSession
732
+ -- We need to do this before we call initUnits.
733
+ env <- runGhc (Just libDir) $
734
+ getSessionDynFlags >>= setSessionDynFlags >> getSession
735
+ -- On GHC 9.2 calling setSessionDynFlags caches the unit databases
736
+ -- for an empty environment. This prevents us from reading the
737
+ -- package database subsequently. So clear the unit db cache in
738
+ -- hsc_unit_dbs
733
739
pure $ setNameCache nc (hscSetFlags ((hsc_dflags env){useUnicode = True }) env)
740
+ #if !MIN_VERSION_ghc(9,3,0)
741
+ {hsc_unit_dbs = Nothing }
742
+ #endif
734
743
735
744
data TargetDetails = TargetDetails
736
745
{
@@ -832,6 +841,8 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
832
841
-- some code. If the binary is dynamically linked, then this will have
833
842
-- no effect.
834
843
-- See https://github.com/haskell/haskell-language-server/issues/221
844
+ -- We need to do this after the call to setSessionDynFlags initialises
845
+ -- the loader
835
846
when (os == " linux" ) $ do
836
847
initObjLinker hscEnv'
837
848
res <- loadDLL hscEnv' " libm.so.6"
@@ -856,7 +867,7 @@ newComponentCache recorder exts cradlePath _cfp hsc_env old_cis new_cis = do
856
867
-- which we need for any changes to the package flags in the dynflags
857
868
-- to be visible.
858
869
-- See #2693
859
- evalGhcEnv hsc_env $ do
870
+ evalGhcEnv hscEnv' $ do
860
871
_ <- setSessionDynFlags df
861
872
getSession
862
873
#endif
0 commit comments