@@ -8,7 +8,6 @@ The logic for setting up a ghcide session by tapping into hie-bios.
8
8
module Development.IDE.Session
9
9
(SessionLoadingOptions (.. )
10
10
,CacheDirs (.. )
11
- ,defaultLoadingOptions
12
11
,loadSession
13
12
,loadSessionWithOptions
14
13
,setInitialDynFlags
@@ -34,6 +33,7 @@ import qualified Data.Text as T
34
33
import Data.Aeson
35
34
import Data.Bifunctor
36
35
import qualified Data.ByteString.Base16 as B16
36
+ import Data.Default
37
37
import Data.Either.Extra
38
38
import Data.Function
39
39
import Data.Hashable
@@ -98,31 +98,38 @@ data SessionLoadingOptions = SessionLoadingOptions
98
98
-- return the path for storing generated GHC artifacts,
99
99
-- or 'Nothing' to respect the cradle setting
100
100
, getCacheDirs :: String -> [String ] -> IO CacheDirs
101
+ -- | Return the GHC lib dir to use for the 'unsafeGlobalDynFlags'
102
+ , getInitialGhcLibDir :: IO (Maybe LibDir )
101
103
}
102
104
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
+ }
109
112
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
113
115
dir <- IO. getCurrentDirectory
114
116
hieYaml <- runMaybeT $ yamlConfig dir
115
117
cradle <- maybe (loadImplicitHieCradle $ addTrailingPathSeparator dir) HieBios. loadCradle hieYaml
116
118
hPutStrLn stderr $ " setInitialDynFlags cradle: " ++ show cradle
117
119
libDirRes <- getRuntimeGhcLibDir cradle
118
- libdir <- case libDirRes of
120
+ case libDirRes of
119
121
CradleSuccess libdir -> pure $ Just $ LibDir libdir
120
122
CradleFail err -> do
121
123
hPutStrLn stderr $ " Couldn't load cradle for libdir: " ++ show (err,dir,hieYaml,cradle)
122
124
pure Nothing
123
125
CradleNone -> do
124
126
hPutStrLn stderr $ " Couldn't load cradle (CradleNone)"
125
127
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
126
133
dynFlags <- mapM dynFlagsForPrinting libdir
127
134
mapM_ setUnsafeGlobalDynFlags dynFlags
128
135
pure libdir
@@ -177,7 +184,7 @@ getHieDbLoc dir = do
177
184
-- components mapping to the same hie.yaml file are mapped to the same
178
185
-- HscEnv which is updated as new components are discovered.
179
186
loadSession :: FilePath -> IO (Action IdeGhcSession )
180
- loadSession = loadSessionWithOptions defaultLoadingOptions
187
+ loadSession = loadSessionWithOptions def
181
188
182
189
loadSessionWithOptions :: SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession )
183
190
loadSessionWithOptions SessionLoadingOptions {.. } dir = do
@@ -614,7 +621,7 @@ should be filtered out, such that we dont have to re-compile everything.
614
621
-- For the exact reason, see Note [Avoiding bad interface files].
615
622
setCacheDirs :: MonadIO m => Logger -> CacheDirs -> DynFlags -> m DynFlags
616
623
setCacheDirs 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)
618
625
pure $ dflags
619
626
& maybe id setHiDir hiCacheDir
620
627
& maybe id setHieDir hieCacheDir
0 commit comments