Skip to content

Commit fdf3085

Browse files
committed
fix: do not crash when some include path does not exists
1 parent 81d3c29 commit fdf3085

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

ghcide/src/Development/IDE/Core/Rules.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,7 @@ getModuleGraphRule recorder = defineEarlyCutOffNoFile (cmapWithPrio LogShake rec
631631
dependencyInfoForFiles (HashSet.toList fs)
632632

633633
{-# NOINLINE cacheVar #-}
634+
-- TODO: this should not use unsaferPerformIO
634635
cacheVar = unsafePerformIO (newTVarIO mempty)
635636

636637
getModulesPathsRule :: Recorder (WithPriority Log) -> Rules ()
@@ -656,7 +657,10 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
656657

657658
-- TODO: we are taking/droping extension, this could be factorized to save a few cpu cycles ;)
658659
-- TODO: do acceptedextensions needs to be a set ? or a vector?
659-
modules <- fmap (\path -> (toModule path, toNormalizedFilePath' path)) . filter (\y -> takeExtension y `elem` acceptedExtensions) <$> liftIO (listFilesInside predicate dir)
660+
-- If the directory is empty, we return an empty list of modules
661+
-- using 'catch' instead of an exception which would kill the LSP
662+
modules <- (fmap (\path -> (toModule path, toNormalizedFilePath' path)) . filter (\y -> takeExtension y `elem` acceptedExtensions) <$> liftIO (listFilesInside predicate dir))
663+
`catch` (\(_ :: IOException) -> pure [])
660664
let isSourceModule (_, path) = "-boot" `isSuffixOf` fromNormalizedFilePath path
661665
let (sourceModules, notSourceModules) = partition isSourceModule modules
662666
pure $ (Map.fromList notSourceModules, Map.fromList sourceModules)

0 commit comments

Comments
 (0)