Skip to content

Commit 6e04d28

Browse files
committed
refactor loadSessionWithOptions to improve error handling and clarify variable names
1 parent 9a2aaf1 commit 6e04d28

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,13 +630,13 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
630630
-- remove error files from pending files since error loading need to load one by one
631631
let pendingFiles = pendingFiles' `Set.difference` errorFiles
632632
-- if the file is in error loading files, we fall back to single loading mode
633-
let toLoads = if cfp `Set.member` errorFiles then Set.empty else pendingFiles
633+
let extraToLoads = if cfp `Set.member` errorFiles then Set.empty else pendingFiles
634634

635635
eopts <- mRunLspTCallback lspEnv (\act -> withIndefiniteProgress progMsg Nothing NotCancellable (const act)) $
636636
withTrace "Load cradle" $ \addTag -> do
637637
addTag "file" lfpLog
638638
old_files <- readIORef cradle_files
639-
res <- cradleToOptsAndLibDir recorder (sessionLoading clientConfig) cradle cfp (Set.toList $ Set.delete cfp $ toLoads <> old_files)
639+
res <- cradleToOptsAndLibDir recorder (sessionLoading clientConfig) cradle cfp (Set.toList $ Set.delete cfp $ extraToLoads <> old_files)
640640
addTag "result" (show res)
641641
return res
642642

@@ -660,16 +660,16 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
660660
logWith recorder Info $ LogSessionNewLoadedFiles $ Set.toList newLoadedT
661661
atomicModifyIORef' cradle_files (\xs -> (newLoadedT <> xs,()))
662662
-- remove the file from error loading files
663-
atomicModifyIORef' error_loading_files (\old -> (old `Set.difference` newLoadedT, ()))
663+
atomicModifyIORef' error_loading_files (\old -> (old `Set.difference` allNewLoaded, ()))
664664
return results
665665
| otherwise -> return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),[])
666666
-- Failure case, either a cradle error or the none cradle
667667
Left err -> do
668-
if (length toLoads > 1)
668+
if (not $ null extraToLoads)
669669
then do
670670
succLoaded_files <- readIORef cradle_files
671671
-- mark as less loaded files as failedLoadingFiles as possible
672-
let failedLoadingFiles = (Set.insert cfp toLoads) `Set.difference` succLoaded_files
672+
let failedLoadingFiles = (Set.insert cfp extraToLoads) `Set.difference` succLoaded_files
673673
atomicModifyIORef' error_loading_files (\xs -> (failedLoadingFiles <> xs,()))
674674
-- retry without other files
675675
atomically $ forM_ pendingFiles (writeTQueue pendingFilesTQueue)
@@ -681,6 +681,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
681681
void $ modifyVar' fileToFlags $
682682
Map.insertWith HM.union hieYaml (HM.singleton ncfp (res, dep_info))
683683
void $ modifyVar' filesMap $ HM.insert ncfp hieYaml
684+
atomicModifyIORef' error_loading_files (\xs -> (Set.insert cfp xs,()))
684685
return (res, maybe [] pure hieYaml ++ concatMap cradleErrorDependencies err)
685686

686687
let

0 commit comments

Comments
 (0)