@@ -87,8 +87,6 @@ import Data.IORef
87
87
import Data.IntMap.Strict (IntMap )
88
88
import qualified Data.IntMap.Strict as IntMap
89
89
import Data.List
90
- import Data.List.Extra (nubOrdOn )
91
- import Data.Map (Map )
92
90
import qualified Data.Map as M
93
91
import Data.Maybe
94
92
import qualified Data.Rope.UTF16 as Rope
@@ -135,7 +133,6 @@ import Development.IDE.Types.Options
135
133
import GHC.Generics (Generic )
136
134
import GHC.IO.Encoding
137
135
import qualified GHC.LanguageExtensions as LangExt
138
- import GhcPlugins (FinderCache , mgModSummaries )
139
136
import qualified HieDb
140
137
import Ide.Plugin.Config
141
138
import qualified Language.LSP.Server as LSP
@@ -151,7 +148,6 @@ import Ide.Plugin.Properties (HasProperty,
151
148
import Ide.PluginUtils (configForPlugin )
152
149
import Ide.Types (DynFlagsModifications (dynFlagsModifyGlobal , dynFlagsModifyParser ),
153
150
PluginId )
154
- import Unsafe.Coerce (unsafeCoerce )
155
151
156
152
-- | This is useful for rules to convert rules that can only produce errors or
157
153
-- a result into the more general IdeResult type that supports producing
@@ -703,48 +699,21 @@ ghcSessionDepsDefinition file = do
703
699
deps <- mapMaybe (fmap artifactFilePath . snd ) <$> use_ GetLocatedImports file
704
700
mss <- map msrModSummary <$> uses_ GetModSummaryWithoutTimestamps deps
705
701
706
- depSessions <- uses_ GhcSessionDeps deps
707
- session' <- liftIO $ mergeEnvs hsc mss $ map hscEnv depSessions
702
+ depSessions <- map hscEnv <$> uses_ GhcSessionDeps deps
708
703
let uses_th_qq =
709
704
xopt LangExt. TemplateHaskell dflags || xopt LangExt. QuasiQuotes dflags
710
705
dflags = ms_hspp_opts ms
711
706
ifaces <- if uses_th_qq
712
707
then uses_ GetModIface deps
713
708
else uses_ GetModIfaceWithoutLinkable deps
714
709
715
- let session'' = loadModulesHome inLoadOrder $ session'{
716
- hsc_HPT = foldMap (hsc_HPT . hscEnv) depSessions
717
- }
710
+ let inLoadOrder = reverse $ map hirHomeMod ifaces
711
+ session' <- liftIO $ mergeEnvs hsc mss inLoadOrder depSessions
718
712
-- Currently GetDependencies returns things in topological order so A comes before B if A imports B.
719
713
-- We need to reverse this as GHC gets very unhappy otherwise and complains about broken interfaces.
720
714
-- Long-term we might just want to change the order returned by GetDependencies
721
- inLoadOrder = reverse $ map hirHomeMod ifaces
722
-
723
- liftIO $ newHscEnvEqWithImportPaths (envImportPaths env) session'' []
724
-
725
- -- Merge the HPTs, module graphs and FinderCaches
726
- mergeEnvs :: HscEnv -> [ModSummary ] -> [HscEnv ] -> IO HscEnv
727
- mergeEnvs env mss envs = do
728
- prevFinderCache <- concatFC <$> mapM (readIORef . hsc_FC) envs
729
- let ims = map (Compat. installedModule (homeUnitId_ $ hsc_dflags env) . moduleName . ms_mod) mss
730
- ifrs = zipWith (\ ms -> InstalledFound (ms_location ms)) mss ims
731
- newFinderCache <- newIORef $
732
- foldl'
733
- (\ fc (im, ifr) -> Compat. extendInstalledModuleEnv fc im ifr) prevFinderCache
734
- $ zip ims ifrs
735
- return env{
736
- hsc_HPT = foldMap hsc_HPT envs,
737
- hsc_FC = newFinderCache,
738
- hsc_mod_graph = mkModuleGraph $ mss ++ nubOrdOn ms_mod (concatMap (mgModSummaries . hsc_mod_graph) envs)
739
- }
740
- where
741
- -- required because 'FinderCache':
742
- -- 1) doesn't have a 'Monoid' instance,
743
- -- 2) is abstract and doesn't export constructors
744
- -- To work around this, we coerce to the underlying type
745
- -- To remove this, I plan to upstream the missing Monoid instance
746
- concatFC :: [FinderCache ] -> FinderCache
747
- concatFC = unsafeCoerce (mconcat @ (Map InstalledModule InstalledFindResult ))
715
+
716
+ liftIO $ newHscEnvEqWithImportPaths (envImportPaths env) session' []
748
717
749
718
-- | Load a iface from disk, or generate it if there isn't one or it is out of date
750
719
-- This rule also ensures that the `.hie` and `.o` (if needed) files are written out.
0 commit comments