Skip to content

Commit aa3a5cf

Browse files
committed
multiples robustness cleanup when there are multiples target for one
module 8 failures
1 parent 1163220 commit aa3a5cf

File tree

2 files changed

+24
-30
lines changed

2 files changed

+24
-30
lines changed

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

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ getLocatedImportsRule recorder =
331331
let dflags = hsc_dflags env
332332
opt <- getIdeOptions
333333

334-
moduleMaps' <- use_ GetModulesPaths file
335-
336-
moduleMaps <- extendModuleMapWithKnownTargets file moduleMaps'
334+
moduleMaps <- extendModuleMapWithKnownTargets file
337335

338336
(diags, imports') <- fmap unzip $ forM imports $ \(isSource, (mbPkgName, modName)) -> do
339337

@@ -677,10 +675,12 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
677675
-- TODO: for now the implementation is O(number_of_known_files *
678676
-- number_of_include_path) which is inacceptable and should be addressed.
679677
extendModuleMapWithKnownTargets
680-
:: NormalizedFilePath -> (Map.Map ModuleName (UnitId, NormalizedFilePath), Map.Map ModuleName (UnitId, NormalizedFilePath))
678+
:: NormalizedFilePath
681679
-> Action (Map.Map ModuleName (UnitId, NormalizedFilePath), Map.Map ModuleName (UnitId, NormalizedFilePath))
682-
extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
680+
extendModuleMapWithKnownTargets file = do
681+
(notSourceModules, sourceModules) <- use_ GetModulesPaths file
683682
KnownTargets targetsMap <- useNoFile_ GetKnownTargets
683+
684684
env_eq <- use_ GhcSession file
685685
let env = hscEnv env_eq
686686
let import_dirs = map (second homeUnitEnv_dflags) $ hugElts $ hsc_HUG env
@@ -701,30 +701,25 @@ extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
701701
-- TODO: the _target may represents something different than the path
702702
-- stored in paths. This need to be investigated.
703703
(_target, paths) <- HM.toList targetsMap
704-
-- TODO: I have no idea why there is multiple path here
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)
704+
path <- HashSet.toList paths
705+
let pathString = fromNormalizedFilePath path
706+
let pathComponents = splitDirectories pathString
707+
708+
-- Ensure this file is in the directory
709+
guard $ dirComponents `isPrefixOf` pathComponents
710+
711+
-- Ensure that this extension is accepted
712+
guard $ takeExtension pathString `elem` acceptedExtensions
713+
let modName = mkModuleName (intercalate "." $ drop dir_number_directories (splitDirectories (dropExtension pathString)))
714+
let isSourceModule = "-boot" `isSuffixOf` pathString
715+
if isSourceModule
716+
then
717+
pure (Nothing, Just (modName, (u, path)))
718+
else
719+
pure (Just (modName, (u, path)), Nothing)
720+
721+
722+
pure $ (Map.fromList a <> notSourceModules, Map.fromList b <> sourceModules)
728723

729724

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

ghcide/src/Development/IDE/Import/FindImports.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ locateModule moduleMaps@(moduleMap, moduleMapSource) env comp_info exts modName
109109
-- Reexports for current unit have to be empty because they only apply to other units depending on the
110110
-- current unit. If we set the reexports to be the actual reexports then we risk looping forever trying
111111
-- to find the module from the perspective of the current unit.
112-
---- locateModuleFile ((homeUnitId_ dflags, importPaths dflags, S.empty) : other_imports) exts targetFor isSource $ unLoc modName
113112
--
114113
-- TODO: handle the other imports, the unit id, ..., reexport.
115114
-- - TODO: should we look for file existence now? If the file was

0 commit comments

Comments
 (0)