@@ -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
@@ -661,23 +661,29 @@ getModulesPathsRule recorder = defineEarlyCutoff (cmapWithPrio LogShake recorder
661661 pure (fmap (u,) $ mconcat a, fmap (u, ) $ mconcat b)
662662
663663 let res = (mconcat a, mconcat b)
664- liftIO $ atomically $ modifyTVar' moduleToPathCache (Map. insert (envUnique env_eq) res)
664+ -- Extend the current module map with all the known targets
665+ resExtended <- extendModuleMapWithKnownTargets file res
666+
667+ liftIO $ atomically $ modifyTVar' moduleToPathCache (Map. insert (envUnique env_eq) resExtended)
668+
669+ pure (mempty , ([] , Just resExtended))
665670
666- pure (mempty , ([] , Just res))
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.
673677--
674- -- TODO: for now the implementation is O(number_of_known_files *
675- -- number_of_include_path) which is inacceptable and should be addressed.
678+ -- This code is not really efficient (O(import_dirs * known_targets)), which
679+ -- can quickly represents millions of tests. It could be improved, but
680+ -- everything only happen once everytime known_targets is updated (which only
681+ -- happen when the project start or when a file is added) and the code is not
682+ -- doing any IO.
676683extendModuleMapWithKnownTargets
677- :: NormalizedFilePath
678- -> Action (Map. Map ModuleName (UnitId , NormalizedFilePath ), Map. Map ModuleName (UnitId , NormalizedFilePath ))
679- extendModuleMapWithKnownTargets file = do
680- (notSourceModules, sourceModules) <- use_ GetModulesPaths file
684+ :: NormalizedFilePath -> (Map. Map ModuleName (UnitId , NormalizedFilePath ), Map. Map ModuleName (UnitId , NormalizedFilePath )) ->
685+ Action (Map. Map ModuleName (UnitId , NormalizedFilePath ), Map. Map ModuleName (UnitId , NormalizedFilePath ))
686+ extendModuleMapWithKnownTargets file (notSourceModules, sourceModules) = do
681687 KnownTargets targetsMap <- useNoFile_ GetKnownTargets
682688
683689 env_eq <- use_ GhcSession file
@@ -717,7 +723,6 @@ extendModuleMapWithKnownTargets file = do
717723 else
718724 pure (Just (modName, (u, path)), Nothing )
719725
720-
721726 pure $ (Map. fromList a <> notSourceModules, Map. fromList b <> sourceModules)
722727
723728
0 commit comments