Skip to content

Commit

Permalink
extract attempt to load files from errors
Browse files Browse the repository at this point in the history
  • Loading branch information
soulomoon committed Nov 9, 2024
1 parent 58f9f3b commit ba7379b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ constraints:
if impl(ghc >= 9.9)
-- https://github.com/haskell/haskell-language-server/issues/4324
benchmarks: False

source-repository-package
type: git
location: https://github.com/soulomoon/hie-bios.git
tag: 93582c21372af573e5103bad198777a3317a2df2
8 changes: 5 additions & 3 deletions ghcide/session-loader/Development/IDE/Session.hs
Original file line number Diff line number Diff line change
Expand Up @@ -680,17 +680,19 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir que = do
return (([renderPackageSetupException cfp GhcVersionMismatch{..}], Nothing),Map.empty)
-- Failure case, either a cradle error or the none cradle
Left err -> do
if (not $ null extraToLoads)
let attemptToLoadFiles = (Set.delete cfp $ Set.fromList $ concatMap cradleErrorLoadingFiles err)
`Set.difference` old_files
if (not $ null attemptToLoadFiles)

Check warning on line 685 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in loadSessionWithOptions in module Development.IDE.Session: Redundant bracket ▫︎ Found: "if (not $ null attemptToLoadFiles) then\n do let failedLoadingFiles = (Set.insert cfp attemptToLoadFiles)\n atomicModifyIORef'\n error_loading_files (\\ xs -> (failedLoadingFiles <> xs, ()))\n logWith recorder Info\n $ LogSessionReloadOnError cfp (Set.toList attemptToLoadFiles)\n consultCradle hieYaml cfp\nelse\n do dep_info <- getDependencyInfo\n ((maybeToList hieYaml) ++ concatMap cradleErrorDependencies err)\n let ncfp = toNormalizedFilePath' cfp\n let res\n = (map (\\ err' -> renderCradleError err' cradle ncfp) err, Nothing)\n atomically $ S.delete cfp pendingFileSet\n atomically\n $ do STM.focus\n (Focus.insertOrMerge HM.union (HM.singleton ncfp (res, dep_info)))\n hieYaml fileToFlags\n STM.insert hieYaml ncfp filesMap\n atomicModifyIORef'\n error_loading_files (\\ xs -> (Set.insert cfp xs, ()))\n return (res, dep_info)" ▫︎ Perhaps: "if not $ null attemptToLoadFiles then\n do let failedLoadingFiles = (Set.insert cfp attemptToLoadFiles)\n atomicModifyIORef'\n error_loading_files (\\ xs -> (failedLoadingFiles <> xs, ()))\n logWith recorder Info\n $ LogSessionReloadOnError cfp (Set.toList attemptToLoadFiles)\n consultCradle hieYaml cfp\nelse\n do dep_info <- getDependencyInfo\n ((maybeToList hieYaml) ++ concatMap cradleErrorDependencies err)\n let ncfp = toNormalizedFilePath' cfp\n let res\n = (map (\\ err' -> renderCradleError err' cradle ncfp) err, Nothing)\n atomically $ S.delete cfp pendingFileSet\n atomically\n $ do STM.focus\n (Focus.insertOrMerge HM.union (HM.singleton ncfp (res, dep_info)))\n hieYaml fileToFlags\n STM.insert hieYaml ncfp filesMap\n atomicModifyIORef'\n error_loading_files (\\ xs -> (Set.insert cfp xs, ()))\n return (res, dep_info)"
then do
-- mark as less loaded files as failedLoadingFiles as possible
-- limitation is that when we are loading files, and the dependencies of old_files
-- are changed, and old_files are not valid anymore.
-- but they will still be in the old_files, and will not move to error_loading_files.
-- And make other files failed to load in batch mode.
let failedLoadingFiles = (Set.insert cfp extraToLoads) `Set.difference` old_files
let failedLoadingFiles = (Set.insert cfp attemptToLoadFiles)

Check warning on line 692 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in loadSessionWithOptions in module Development.IDE.Session: Redundant bracket ▫︎ Found: "do let failedLoadingFiles = (Set.insert cfp attemptToLoadFiles)\n atomicModifyIORef'\n error_loading_files (\\ xs -> (failedLoadingFiles <> xs, ()))\n logWith recorder Info\n $ LogSessionReloadOnError cfp (Set.toList attemptToLoadFiles)\n consultCradle hieYaml cfp" ▫︎ Perhaps: "do let failedLoadingFiles = Set.insert cfp attemptToLoadFiles\n atomicModifyIORef'\n error_loading_files (\\ xs -> (failedLoadingFiles <> xs, ()))\n logWith recorder Info\n $ LogSessionReloadOnError cfp (Set.toList attemptToLoadFiles)\n consultCradle hieYaml cfp"
atomicModifyIORef' error_loading_files (\xs -> (failedLoadingFiles <> xs,()))

Check warning on line 693 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Warning in loadSessionWithOptions in module Development.IDE.Session: Use atomicModifyIORef'_ ▫︎ Found: "atomicModifyIORef'\n error_loading_files (\\ xs -> (failedLoadingFiles <> xs, ()))" ▫︎ Perhaps: "atomicModifyIORef'_ error_loading_files ((<>) failedLoadingFiles)"
-- retry without other files
logWith recorder Info $ LogSessionReloadOnError cfp (Set.toList pendingFiles)
logWith recorder Info $ LogSessionReloadOnError cfp (Set.toList attemptToLoadFiles)
consultCradle hieYaml cfp
else do
dep_info <- getDependencyInfo ((maybeToList hieYaml) ++ concatMap cradleErrorDependencies err)

Check warning on line 698 in ghcide/session-loader/Development/IDE/Session.hs

View workflow job for this annotation

GitHub Actions / Hlint check run

Suggestion in loadSessionWithOptions in module Development.IDE.Session: Redundant bracket ▫︎ Found: "(maybeToList hieYaml) ++ concatMap cradleErrorDependencies err" ▫︎ Perhaps: "maybeToList hieYaml ++ concatMap cradleErrorDependencies err"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ data CradleErrorDetails =
Depicts the cradle error in a user-friendly way.
-}
renderCradleError :: CradleError -> Cradle a -> NormalizedFilePath -> FileDiagnostic
renderCradleError (CradleError deps _ec ms) cradle nfp
renderCradleError (CradleError deps _ec ms _attemptToLoadFiles) cradle nfp
| HieBios.isCabalCradle cradle =
let (fp, showDiag, diag) = ideErrorWithSource (Just "cradle") (Just DiagnosticSeverity_Error) nfp $ T.unlines $ map T.pack userFriendlyMessage in
(fp, showDiag, diag{_data_ = Just $ Aeson.toJSON CradleErrorDetails{cabalProjectFiles=absDeps}})
Expand Down

0 comments on commit ba7379b

Please sign in to comment.