@@ -178,7 +178,7 @@ import System.Info.Extra (isWindows)
178178import qualified Data.IntMap as IM
179179import GHC.Fingerprint
180180import qualified Data.Map.Strict as Map
181- import System.FilePath (takeExtension , takeFileName , normalise , dropExtension , splitDirectories )
181+ import System.FilePath (takeExtension , takeFileName , normalise , dropExtension , splitDirectories , equalFilePath )
182182import Data.Char (isUpper )
183183import System.Directory.Extra (listFilesInside )
184184
@@ -330,7 +330,7 @@ getLocatedImportsRule recorder =
330330 let dflags = hsc_dflags env
331331 opt <- getIdeOptions
332332
333- moduleMaps <- extendModuleMapWithKnownTargets file
333+ moduleMaps <- use_ GetModulesPaths file
334334
335335 (diags, imports') <- fmap unzip $ forM imports $ \ (isSource, (mbPkgName, modName)) -> do
336336
@@ -643,7 +643,7 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
643643 (unzip -> (a, b)) <- flip mapM import_dirs $ \ (u, dyn) -> do
644644 (unzip -> (a, b)) <- flip mapM (importPaths dyn) $ \ dir' -> do
645645 let dir = normalise dir'
646- let predicate path = pure (normalise path == dir || case takeFileName path of
646+ let predicate path = pure (equalFilePath path dir || case takeFileName path of
647647 [] -> False
648648 (x: _) -> isUpper x)
649649 let dir_number_directories = length (splitDirectories dir)
@@ -663,21 +663,21 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
663663 let res = (mconcat a, mconcat b)
664664 liftIO $ atomically $ modifyTVar' moduleToPathCache (Map. insert (envUnique env_eq) res)
665665
666- pure (mempty , ([] , Just res))
666+ -- Extend the current module map with all the known targets
667+ resExtended <- extendModuleMapWithKnownTargets file res
668+
669+ pure (mempty , ([] , Just resExtended))
670+
667671
668672-- | Extend the map from module name to filepath (exiting on the drive) with
669673-- the list of known targets provided by HLS
670674--
671675-- These known targets are files which were recently created and not yet saved
672676-- to the filesystem.
673- --
674- -- TODO: for now the implementation is O(number_of_known_files *
675- -- number_of_include_path) which is inacceptable and should be addressed.
676677extendModuleMapWithKnownTargets
677- :: NormalizedFilePath
678- -> Action (Map. Map ModuleName (UnitId , NormalizedFilePath ), Map. Map ModuleName (UnitId , NormalizedFilePath ))
679- extendModuleMapWithKnownTargets file = do
680- (notSourceModules, sourceModules) <- use_ GetModulesPaths file
678+ :: NormalizedFilePath -> (Map. Map ModuleName (UnitId , NormalizedFilePath ), Map. Map ModuleName (UnitId , NormalizedFilePath )) ->
679+ Action (Map. Map ModuleName (UnitId , NormalizedFilePath ), Map. Map ModuleName (UnitId , NormalizedFilePath ))
680+ extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
681681 KnownTargets targetsMap <- useNoFile_ GetKnownTargets
682682
683683 env_eq <- use_ GhcSession file
@@ -717,7 +717,6 @@ extendModuleMapWithKnownTargets file = do
717717 else
718718 pure (Just (modName, (u, path)), Nothing )
719719
720-
721720 pure $ (Map. fromList a <> notSourceModules, Map. fromList b <> sourceModules)
722721
723722
0 commit comments