@@ -437,16 +437,26 @@ On failure:
437
437
This approach ensures efficient batch loading while isolating problematic files for individual handling.
438
438
-}
439
439
440
- handleLoadingSucc :: SessionState -> HashSet FilePath -> IO ()
441
- handleLoadingSucc sessionState files = do
442
- atomically $ forM_ (Set. toList files) $ flip S. delete (pendingFiles sessionState)
443
- mapM_ (removeErrorLoadingFile sessionState) (Set. toList files)
444
- addCradleFiles sessionState files
440
+ -- SBL3
441
+ handleLoadingSuccBatch :: Foldable t => Recorder (WithPriority Log ) -> SessionState -> Maybe FilePath -> HashMap NormalizedFilePath (IdeResult HscEnvEq , DependencyInfo ) -> t TargetDetails -> IO ()
442
+ handleLoadingSuccBatch recorder sessionState hieYaml this_flags_map all_targets = do
443
+ pendings <- getPendingFiles sessionState
444
+ -- this_flags_map might contains files not in pendingFiles, take the intersection
445
+ let newLoaded = pendings `Set.intersection` Set. fromList (fromNormalizedFilePath <$> HM. keys this_flags_map)
446
+ atomically $ do
447
+ STM. insert this_flags_map hieYaml (fileToFlags sessionState)
448
+ insertAllFileMappings sessionState $ map ((hieYaml,) . fst ) $ concatMap toFlagsMap all_targets
449
+ logWith recorder Info $ LogSessionNewLoadedFiles $ Set. toList newLoaded
450
+ atomically $ forM_ (Set. toList newLoaded) $ flip S. delete (pendingFiles sessionState)
451
+ mapM_ (removeErrorLoadingFile sessionState) (Set. toList newLoaded)
452
+ addCradleFiles sessionState newLoaded
445
453
454
+ -- SBL5
446
455
handleLoadingFailureBatch :: SessionState -> [FilePath ] -> IO ()
447
456
handleLoadingFailureBatch sessionState files = do
448
- addErrorLoadingFiles sessionState files
457
+ mapM_ (addErrorLoadingFile sessionState) files
449
458
459
+ -- SBL4
450
460
handleLoadingFailureSingle :: SessionState -> FilePath -> IO ()
451
461
handleLoadingFailureSingle sessionState file = do
452
462
addErrorLoadingFile sessionState file
@@ -473,9 +483,6 @@ addErrorLoadingFile :: SessionState -> FilePath -> IO ()
473
483
addErrorLoadingFile state file =
474
484
modifyVar_' (failedFiles state) (\ xs -> return $ Set. insert file xs)
475
485
476
- addErrorLoadingFiles :: SessionState -> [FilePath ] -> IO ()
477
- addErrorLoadingFiles = mapM_ . addErrorLoadingFile
478
-
479
486
-- | Remove a file from the set of files with errors during loading
480
487
removeErrorLoadingFile :: SessionState -> FilePath -> IO ()
481
488
removeErrorLoadingFile state file =
@@ -526,7 +533,6 @@ addToPending :: SessionState -> FilePath -> STM ()
526
533
addToPending state file =
527
534
S. insert file (pendingFiles state)
528
535
529
-
530
536
-- | Insert multiple file mappings at once
531
537
insertAllFileMappings :: SessionState -> [(Maybe FilePath , NormalizedFilePath )] -> STM ()
532
538
insertAllFileMappings state mappings =
@@ -541,13 +547,13 @@ getPendingFiles :: SessionState -> IO (HashSet FilePath)
541
547
getPendingFiles state = atomically $ Set. fromList <$> S. toUnOrderedList (pendingFiles state)
542
548
543
549
-- | Handle errors during session loading by recording file as having error and removing from pending
544
- handleSessionError :: SessionState -> Maybe FilePath -> FilePath -> PackageSetupException -> IO ()
545
- handleSessionError state hieYaml file e = do
546
- handleFileProcessingError state hieYaml file [renderPackageSetupException file e] mempty
550
+ handleSingleFileProcessingError' :: SessionState -> Maybe FilePath -> FilePath -> PackageSetupException -> IO ()
551
+ handleSingleFileProcessingError' state hieYaml file e = do
552
+ handleSingleFileProcessingError state hieYaml file [renderPackageSetupException file e] mempty
547
553
548
554
-- | Common pattern: Insert file flags, insert file mapping, and remove from pending
549
- handleFileProcessingError :: SessionState -> Maybe FilePath -> FilePath -> [FileDiagnostic ] -> [FilePath ] -> IO ()
550
- handleFileProcessingError state hieYaml file diags extraDepFiles = do
555
+ handleSingleFileProcessingError :: SessionState -> Maybe FilePath -> FilePath -> [FileDiagnostic ] -> [FilePath ] -> IO ()
556
+ handleSingleFileProcessingError state hieYaml file diags extraDepFiles = do
551
557
dep <- getDependencyInfo $ maybeToList hieYaml <> extraDepFiles
552
558
let ncfp = toNormalizedFilePath' file
553
559
let flags = ((diags, Nothing ), dep)
@@ -766,15 +772,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
766
772
])
767
773
Nothing
768
774
769
- pendings <- getPendingFiles sessionState
770
- -- this_flags_map might contains files not in pendingFiles, take the intersection
771
- let newLoaded = pendings `Set.intersection` Set. fromList (fromNormalizedFilePath <$> HM. keys this_flags_map)
772
- atomically $ do
773
- STM. insert this_flags_map hieYaml (fileToFlags sessionState)
774
- insertAllFileMappings sessionState $ map ((hieYaml,) . fst ) $ concatMap toFlagsMap all_targets
775
-
776
- logWith recorder Info $ LogSessionNewLoadedFiles $ Set. toList newLoaded
777
- handleLoadingSucc sessionState newLoaded
775
+ handleLoadingSuccBatch recorder sessionState hieYaml this_flags_map all_targets
778
776
-- Typecheck all files in the project on startup
779
777
checkProject <- getCheckProject
780
778
@@ -828,9 +826,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
828
826
[] -> error $ " GHC version could not be parsed: " <> version
829
827
((runTime, _): _)
830
828
| compileTime == runTime -> session (hieYaml, ncfp, opts, libDir)
831
- | otherwise -> do
832
- -- Use the common pattern here: updateFileState
833
- handleFileProcessingError sessionState hieYaml cfp [renderPackageSetupException cfp GhcVersionMismatch {.. }] mempty
829
+ | otherwise -> handleSingleFileProcessingError' sessionState hieYaml cfp (GhcVersionMismatch {.. })
834
830
-- Failure case, either a cradle error or the none cradle
835
831
Left err -> do
836
832
-- what if the error to load file is one of old_files ?
@@ -852,7 +848,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
852
848
else do
853
849
-- we are only loading this file and it failed
854
850
let res = map (\ err' -> renderCradleError err' cradle ncfp) err
855
- handleFileProcessingError sessionState hieYaml cfp res $ concatMap cradleErrorDependencies err
851
+ handleSingleFileProcessingError sessionState hieYaml cfp res $ concatMap cradleErrorDependencies err
856
852
-- This caches the mapping from hie.yaml + Mod.hs -> [String]
857
853
-- Returns the Ghc session and the cradle dependencies
858
854
let sessionOpts :: (Maybe FilePath , FilePath )
@@ -909,7 +905,7 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
909
905
cachedHieYamlLocation <- join <$> atomically (STM. lookup ncfp (filesMap sessionState))
910
906
hieYaml <- cradleLoc file
911
907
let hieLoc = cachedHieYamlLocation <|> hieYaml
912
- sessionOpts (hieLoc, file) `Safe.catch` handleSessionError sessionState hieLoc file
908
+ sessionOpts (hieLoc, file) `Safe.catch` handleSingleFileProcessingError' sessionState hieLoc file
913
909
getOptionsLoop
914
910
915
911
-- | Given a file, this function will return the HscEnv and the dependencies
0 commit comments