@@ -122,7 +122,6 @@ import Control.Concurrent.STM (STM)
122
122
import qualified Control.Monad.STM as STM
123
123
import qualified Development.IDE.Session.OrderedSet as S
124
124
import qualified Focus
125
- import GHC.Data.Bag
126
125
import GHC.Driver.Env (hsc_all_home_unit_ids )
127
126
import GHC.Driver.Errors.Types
128
127
import GHC.Types.Error (errMsgDiagnostic ,
@@ -423,20 +422,37 @@ SessionState manages the state for batch loading files in the session loader.
423
422
424
423
- When a new file needs to be loaded, it is added to the pendingFiles set.
425
424
- The loader processes files from pendingFiles, attempting to load them in batches.
426
- - If a file is already in failedFiles, it is loaded individually (single-file mode).
427
- - Otherwise, the loader tries to load as many files as possible together (batch mode).
425
+ - (SBL1) If a file is already in failedFiles, it is loaded individually (single-file mode).
426
+ - (SBL2) Otherwise, the loader tries to load as many files as possible together (batch mode).
428
427
429
428
On success:
430
- - All successfully loaded files are removed from pendingFiles and failedFiles,
429
+ - (SBL3) All successfully loaded files are removed from pendingFiles and failedFiles,
431
430
and added to loadedFiles.
432
431
433
432
On failure:
434
- - If loading a single file fails, it is added to failedFiles and removed from loadedFiles and pendingFiles.
435
- - If batch loading fails, all files attempted are added to failedFiles.
433
+ - (SBL4) If loading a single file fails, it is added to failedFiles and removed from loadedFiles and pendingFiles.
434
+ - (SBL5) If batch loading fails, all files attempted are added to failedFiles.
436
435
437
436
This approach ensures efficient batch loading while isolating problematic files for individual handling.
438
437
-}
439
438
439
+ handleLoadingSucc :: SessionState -> HashSet FilePath -> IO ()
440
+ handleLoadingSucc sessionState files = do
441
+ atomically $ forM_ (Set. toList files) $ flip S. delete (pendingFiles sessionState)
442
+ mapM_ (removeErrorLoadingFile sessionState) (Set. toList files)
443
+ addCradleFiles sessionState files
444
+
445
+ handleLoadingFailureBatch :: SessionState -> [FilePath ] -> IO ()
446
+ handleLoadingFailureBatch sessionState files = do
447
+ addErrorLoadingFiles sessionState files
448
+
449
+ handleLoadingFailureSingle :: SessionState -> FilePath -> IO ()
450
+ handleLoadingFailureSingle sessionState file = do
451
+ addErrorLoadingFile sessionState file
452
+ removeErrorLoadingFile sessionState file
453
+ atomically $ S. delete file (pendingFiles sessionState)
454
+ removeCradleFile sessionState file
455
+
440
456
data SessionState = SessionState
441
457
{ loadedFiles :: ! (IORef (HashSet FilePath )),
442
458
failedFiles :: ! (IORef (HashSet FilePath )),
@@ -530,15 +546,13 @@ handleSessionError state hieYaml file e = do
530
546
-- | Common pattern: Insert file flags, insert file mapping, and remove from pending
531
547
handleFileProcessingError :: SessionState -> Maybe FilePath -> FilePath -> [FileDiagnostic ] -> [FilePath ] -> IO ()
532
548
handleFileProcessingError state hieYaml file diags extraDepFiles = do
533
- addErrorLoadingFile state file
534
- removeCradleFile state file
535
549
dep <- getDependencyInfo $ maybeToList hieYaml <> extraDepFiles
536
550
let ncfp = toNormalizedFilePath' file
537
551
let flags = ((diags, Nothing ), dep)
552
+ handleLoadingFailureSingle state file
538
553
atomically $ do
539
554
insertFileFlags state hieYaml ncfp flags
540
555
insertFileMapping state hieYaml ncfp
541
- removeFromPending state file
542
556
543
557
-- | Get the set of extra files to load based on the current file path
544
558
-- If the current file is in error loading files, we fallback to single loading mode (empty set)
@@ -738,12 +752,9 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
738
752
atomically $ do
739
753
STM. insert this_flags_map hieYaml (fileToFlags sessionState)
740
754
insertAllFileMappings sessionState $ map ((hieYaml,) . fst ) $ concatMap toFlagsMap all_targets
741
- forM_ newLoaded $ flip S. delete (pendingFiles sessionState)
742
755
743
756
logWith recorder Info $ LogSessionNewLoadedFiles $ Set. toList newLoaded
744
- -- remove all new loaded file from error loading files
745
- mapM_ (removeErrorLoadingFile sessionState) (Set. toList newLoaded)
746
- addCradleFiles sessionState newLoaded
757
+ handleLoadingSucc sessionState newLoaded
747
758
-- Typecheck all files in the project on startup
748
759
checkProject <- getCheckProject
749
760
@@ -814,7 +825,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
814
825
-- are changed, and old_files are not valid anymore.
815
826
-- but they will still be in the old_files, and will not move to failedFiles.
816
827
-- And make other files failed to load in batch mode.
817
- addErrorLoadingFiles sessionState errorToLoadNewFiles
828
+ handleLoadingFailureBatch sessionState errorToLoadNewFiles
818
829
-- retry without other files
819
830
logWith recorder Info $ LogSessionReloadOnError cfp (Set. toList attemptToLoadFiles)
820
831
consultCradle hieYaml cfp
0 commit comments