@@ -8,7 +8,6 @@ The logic for setting up a ghcide session by tapping into hie-bios.
88module Development.IDE.Session
99 (SessionLoadingOptions (.. )
1010 ,CacheDirs (.. )
11- ,defaultLoadingOptions
1211 ,loadSession
1312 ,loadSessionWithOptions
1413 ,setInitialDynFlags
@@ -34,6 +33,7 @@ import qualified Data.Text as T
3433import Data.Aeson
3534import Data.Bifunctor
3635import qualified Data.ByteString.Base16 as B16
36+ import Data.Default
3737import Data.Either.Extra
3838import Data.Function
3939import Data.Hashable
@@ -98,31 +98,38 @@ data SessionLoadingOptions = SessionLoadingOptions
9898 -- return the path for storing generated GHC artifacts,
9999 -- or 'Nothing' to respect the cradle setting
100100 , getCacheDirs :: String -> [String ] -> IO CacheDirs
101+ -- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
102+ , getInitialGhcLibDir :: IO (Maybe LibDir )
101103 }
102104
103- defaultLoadingOptions :: SessionLoadingOptions
104- defaultLoadingOptions = SessionLoadingOptions
105- {findCradle = HieBios. findCradle
106- ,loadCradle = HieBios. loadCradle
107- ,getCacheDirs = getCacheDirsDefault
108- }
105+ instance Default SessionLoadingOptions where
106+ def = SessionLoadingOptions
107+ {findCradle = HieBios. findCradle
108+ ,loadCradle = HieBios. loadCradle
109+ ,getCacheDirs = getCacheDirsDefault
110+ ,getInitialGhcLibDir = getInitialGhcLibDirDefault
111+ }
109112
110- -- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
111- setInitialDynFlags :: IO (Maybe LibDir )
112- setInitialDynFlags = do
113+ getInitialGhcLibDirDefault :: IO (Maybe LibDir )
114+ getInitialGhcLibDirDefault = do
113115 dir <- IO. getCurrentDirectory
114116 hieYaml <- runMaybeT $ yamlConfig dir
115117 cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios. loadCradle hieYaml
116118 hPutStrLn stderr $ " setInitialDynFlags cradle: " ++ show cradle
117119 libDirRes <- getRuntimeGhcLibDir cradle
118- libdir <- case libDirRes of
120+ case libDirRes of
119121 CradleSuccess libdir -> pure $ Just $ LibDir libdir
120122 CradleFail err -> do
121123 hPutStrLn stderr $ " Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle)
122124 pure Nothing
123125 CradleNone -> do
124126 hPutStrLn stderr $ " Couldn't load cradle (CradleNone)"
125127 pure Nothing
128+
129+ -- | Sets `unsafeGlobalDynFlags` on using the hie-bios cradle and returns the GHC libdir
130+ setInitialDynFlags :: SessionLoadingOptions -> IO (Maybe LibDir )
131+ setInitialDynFlags SessionLoadingOptions {.. } = do
132+ libdir <- getInitialGhcLibDir
126133 dynFlags <- mapM dynFlagsForPrinting libdir
127134 mapM_ setUnsafeGlobalDynFlags dynFlags
128135 pure libdir
@@ -177,7 +184,7 @@ getHieDbLoc dir = do
177184-- components mapping to the same hie.yaml file are mapped to the same
178185-- HscEnv which is updated as new components are discovered.
179186loadSession :: FilePath -> IO (Action IdeGhcSession )
180- loadSession = loadSessionWithOptions defaultLoadingOptions
187+ loadSession = loadSessionWithOptions def
181188
182189loadSessionWithOptions :: SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession )
183190loadSessionWithOptions SessionLoadingOptions {.. } dir = do
@@ -614,7 +621,7 @@ should be filtered out, such that we dont have to re-compile everything.
614621-- For the exact reason, see Note [Avoiding bad interface files].
615622setCacheDirs :: MonadIO m => Logger -> CacheDirs -> DynFlags -> m DynFlags
616623setCacheDirs logger CacheDirs {.. } dflags = do
617- liftIO $ logInfo logger $ " Using interface files cache dir: " <> T. pack cacheDir
624+ liftIO $ logInfo logger $ " Using interface files cache dir: " <> T. pack (fromMaybe cacheDir hiCacheDir)
618625 pure $ dflags
619626 & maybe id setHiDir hiCacheDir
620627 & maybe id setHieDir hieCacheDir
0 commit comments