Skip to content

Commit 1163220

Browse files
committed
fix: clean naming and hopefully handle -boot files from known targets
1 parent 89761a5 commit 1163220

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

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

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
652652
let dir_number_directories = length (splitDirectories dir)
653653
let toModule file = mkModuleName (intercalate "." $ drop dir_number_directories (splitDirectories (dropExtension file)))
654654

655-
-- TODO: we are taking/droping extension, this could be factorized to save a few cpu cycles ;)
655+
-- TODO: we are taking/dropping extension, this could be factorized to save a few cpu cycles ;)
656656
-- TODO: do acceptedextensions needs to be a set ? or a vector?
657657
-- If the directory is empty, we return an empty list of modules
658658
-- using 'catch' instead of an exception which would kill the LSP
@@ -688,7 +688,7 @@ extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
688688
let exts = (optExtensions opt)
689689
let acceptedExtensions = concatMap (\x -> ['.':x, '.':x <> "-boot"]) exts
690690

691-
let notSourceModuleP = Map.fromList $ do
691+
let (unzip -> (catMaybes -> a, catMaybes -> b)) = do
692692
(u, dyn) <- import_dirs
693693
-- TODO: avoid using so much `FilePath` logic AND please please,
694694
-- normalize earlier.
@@ -702,22 +702,29 @@ extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
702702
-- stored in paths. This need to be investigated.
703703
(_target, paths) <- HM.toList targetsMap
704704
-- TODO: I have no idea why there is multiple path here
705-
guard $ length paths > 0
706-
let path = head $ toList paths
707-
let pathString = fromNormalizedFilePath path
708-
let pathComponents = splitDirectories pathString
709-
710-
-- Ensure this file is in the directory
711-
guard $ dirComponents `isPrefixOf` pathComponents
712-
713-
-- Ensure that this extension is accepted
714-
guard $ takeExtension pathString `elem` acceptedExtensions
715-
let modName = mkModuleName (intercalate "." $ drop dir_number_directories (splitDirectories (dropExtension pathString)))
716-
pure (modName, (u, path))
717-
718-
let notSourceModules' = notSourceModules <> notSourceModuleP
719-
720-
pure $!! (notSourceModules', sourceModules)
705+
if length paths > 1
706+
then error "the pathlength is incorrect"
707+
else do
708+
guard $ length paths > 0
709+
let path = head $ toList paths
710+
let pathString = fromNormalizedFilePath path
711+
let pathComponents = splitDirectories pathString
712+
713+
-- Ensure this file is in the directory
714+
guard $ dirComponents `isPrefixOf` pathComponents
715+
716+
-- Ensure that this extension is accepted
717+
guard $ takeExtension pathString `elem` acceptedExtensions
718+
let modName = mkModuleName (intercalate "." $ drop dir_number_directories (splitDirectories (dropExtension pathString)))
719+
let isSourceModule = "-boot" `isSuffixOf` pathString
720+
if isSourceModule
721+
then
722+
pure (Nothing, Just (modName, (u, path)))
723+
else
724+
pure (Just (modName, (u, path)), Nothing)
725+
726+
727+
pure (Map.fromList a <> notSourceModules, Map.fromList b <> sourceModules)
721728

722729

723730
dependencyInfoForFiles :: [NormalizedFilePath] -> Action (BS.ByteString, DependencyInformation)

0 commit comments

Comments
 (0)