Skip to content

Commit

Permalink
add LogSessionReloadOnError to log errors during file reloads; cleanu…
Browse files Browse the repository at this point in the history
…p error loading and cradle files
  • Loading branch information
soulomoon committed Nov 4, 2024
1 parent c4bb53a commit 112bc95
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,13 @@ data Log
| LogHieBios HieBios.Log
| LogSessionLoadingChanged
| LogSessionNewLoadedFiles ![FilePath]
| LogSessionReloadOnError FilePath ![FilePath]
deriving instance Show Log

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

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

0 comments on commit 112bc95

Please sign in to comment.