Skip to content

Commit 112bc95

Browse files
committed
add LogSessionReloadOnError to log errors during file reloads; cleanup error loading and cradle files
1 parent c4bb53a commit 112bc95

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,13 @@ data Log
147147
| LogHieBios HieBios.Log
148148
| LogSessionLoadingChanged
149149
| LogSessionNewLoadedFiles ![FilePath]
150+
| LogSessionReloadOnError FilePath ![FilePath]
150151
deriving instance Show Log
151152

152153
instance Pretty Log where
153154
pretty = \case
155+
LogSessionReloadOnError path files ->
156+
"Reloading file due to error in" <+> pretty path <+> "with files:" <+> pretty files
154157
LogSessionNewLoadedFiles files ->
155158
"New loaded files:" <+> pretty files
156159
LogNoneCradleFound path ->
@@ -649,14 +652,14 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
649652
| compileTime == runTime -> do
650653
(results, allNewLoaded) <- session (hieYaml, toNormalizedFilePath' cfp, opts, libDir)
651654
-- put back to pending que if not listed in the results
652-
-- delete cfp even if ew report No cradle target found for cfp
655+
-- delete cfp even if we report No cradle target found for the cfp
653656
let remainPendingFiles = Set.delete cfp $ pendingFiles `Set.difference` allNewLoaded
654657
let newLoadedT = pendingFiles `Set.intersection` allNewLoaded
655658
atomically $ forM_ remainPendingFiles (writeTQueue pendingFilesTQueue)
656659
-- log new loaded files
657660
logWith recorder Info $ LogSessionNewLoadedFiles $ Set.toList newLoadedT
658-
-- remove the file from error loading files
659661
atomicModifyIORef' cradle_files (\xs -> (newLoadedT <> xs,()))
662+
-- remove the file from error loading files
660663
atomicModifyIORef' error_loading_files (\old -> (old `Set.difference` newLoadedT, ()))
661664
return results
662665
| otherwise -> return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
@@ -711,6 +714,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
711714
modifyVar_ filesMap (const (return HM.empty))
712715
-- Don't even keep the name cache, we start from scratch here!
713716
modifyVar_ hscEnvs (const (return Map.empty))
717+
-- cleanup error loading files and cradle files
718+
atomicModifyIORef' error_loading_files (\_ -> (Set.empty,()))
719+
atomicModifyIORef' cradle_files (\_ -> (Set.empty,()))
714720

715721
v <- Map.findWithDefault HM.empty hieYaml <$> readVar fileToFlags
716722
let cfp = toAbsolutePath file

0 commit comments

Comments
 (0)