Skip to content

Commit c3d56ec

Browse files
committed
session-loader: remember which files caused old components to be loaded, and
also pass them on to hie-bios so it can in turn pass them to `cabal repl` when loading newer components. This allows us to create valid set of build flags encompassing both the old and new components, and the closure of all components in between. The observation is that if you want to load some components X, Y, Z and so on, cabal repl X Y Z ... will be more likely to give you a valid multi component build plan/flags than cabal repl all, or any way of combining the results of cabal repl X, cabal repl Y ...
1 parent ca6f601 commit c3d56ec

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,7 @@ loadSession recorder = loadSessionWithOptions recorder def
437437

438438
loadSessionWithOptions :: Recorder (WithPriority Log) -> SessionLoadingOptions -> FilePath -> IO (Action IdeGhcSession)
439439
loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
440+
cradle_files <- newIORef []
440441
-- Mapping from hie.yaml file to HscEnv, one per hie.yaml file
441442
hscEnvs <- newVar Map.empty :: IO (Var HieMap)
442443
-- Mapping from a Filepath to HscEnv
@@ -625,7 +626,8 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
625626
eopts <- mRunLspTCallback lspEnv (withIndefiniteProgress progMsg NotCancellable) $
626627
withTrace "Load cradle" $ \addTag -> do
627628
addTag "file" lfp
628-
res <- cradleToOptsAndLibDir recorder cradle cfp
629+
old_files <- readIORef cradle_files
630+
res <- cradleToOptsAndLibDir recorder cradle cfp old_files
629631
addTag "result" (show res)
630632
return res
631633

@@ -640,7 +642,8 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
640642
error $ "GHC installation not found in libdir: " <> libdir
641643
InstallationMismatch{..} ->
642644
return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
643-
InstallationChecked _compileTime _ghcLibCheck ->
645+
InstallationChecked _compileTime _ghcLibCheck -> do
646+
atomicModifyIORef' cradle_files (\xs -> (cfp:xs,()))
644647
session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
645648
-- Failure case, either a cradle error or the none cradle
646649
Left err -> do
@@ -698,15 +701,15 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} dir = do
698701
-- | Run the specific cradle on a specific FilePath via hie-bios.
699702
-- This then builds dependencies or whatever based on the cradle, gets the
700703
-- GHC options/dynflags needed for the session and the GHC library directory
701-
cradleToOptsAndLibDir :: Recorder (WithPriority Log) -> Cradle Void -> FilePath
704+
cradleToOptsAndLibDir :: Recorder (WithPriority Log) -> Cradle Void -> FilePath -> [FilePath]
702705
-> IO (Either [CradleError] (ComponentOptions, FilePath))
703-
cradleToOptsAndLibDir recorder cradle file = do
706+
cradleToOptsAndLibDir recorder cradle file old_files = do
704707
-- let noneCradleFoundMessage :: FilePath -> T.Text
705708
-- noneCradleFoundMessage f = T.pack $ "none cradle found for " <> f <> ", ignoring the file"
706709
-- Start off by getting the session options
707710
logWith recorder Debug $ LogCradle cradle
708711
let logger = toCologActionWithPrio $ cmapWithPrio LogHieBios recorder
709-
cradleRes <- HieBios.getCompilerOptions logger file cradle
712+
cradleRes <- HieBios.getCompilerOptions logger (file:old_files) cradle
710713
case cradleRes of
711714
CradleSuccess r -> do
712715
-- Now get the GHC lib dir

0 commit comments

Comments
 (0)