Skip to content

Commit 897cd59

Browse files
committed
getInitialGhcLibDir
1 parent 132193e commit 897cd59

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

103105
defaultLoadingOptions :: SessionLoadingOptions
104106
defaultLoadingOptions = SessionLoadingOptions
105107
{findCradle = HieBios.findCradle
106108
,loadCradle = HieBios.loadCradle
107109
,getCacheDirs = getCacheDirsDefault
110+
,getInitialGhcLibDir = getInitialGhcLibDirDefault
108111
}
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

ghcide/src/Development/IDE/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ defaultMain Arguments{..} = do
127127
-- We do it here since haskell-lsp changes our working directory to the correct place ('rootPath')
128128
-- before calling this function
129129
_mlibdir <-
130-
setInitialDynFlags
130+
setInitialDynFlags argsSessionLoadingOptions
131131
`catchAny` (\e -> (hPutStrLn stderr $ "setInitialDynFlags: " ++ displayException e) >> pure Nothing)
132132

133133
sessionLoader <- loadSessionWithOptions argsSessionLoadingOptions $ fromMaybe dir rootPath

0 commit comments

Comments
 (0)