@@ -61,7 +61,7 @@ import qualified Development.IDE.GHC.Compat.Core as GHC
61
61
import Development.IDE.GHC.Compat.Env hiding (Logger )
62
62
import Development.IDE.GHC.Compat.Units (UnitId )
63
63
import Development.IDE.GHC.Util
64
- import Development.IDE.Graph (Action )
64
+ import Development.IDE.Graph (Action , alwaysRerun )
65
65
import qualified Development.IDE.Session.Implicit as GhcIde
66
66
import Development.IDE.Session.VersionCheck
67
67
import Development.IDE.Types.Diagnostics
@@ -134,6 +134,7 @@ import GHC.Unit.State
134
134
import Language.LSP.Protocol.Types (NormalizedUri (NormalizedUri ),
135
135
toNormalizedFilePath )
136
136
#endif
137
+ import Development.IDE (RuleResult )
137
138
import qualified Development.IDE.Core.Shake as SHake
138
139
139
140
data Log
@@ -448,6 +449,9 @@ getHieDbLoc dir = do
448
449
loadSession :: Recorder (WithPriority Log ) -> FilePath -> IO (Rules () , Action IdeGhcSession )
449
450
loadSession recorder = loadSessionWithOptions recorder def
450
451
452
+ type instance RuleResult HieYaml = (HashMap
453
+ NormalizedFilePath (IdeResult HscEnvEq , DependencyInfo ))
454
+
451
455
loadSessionWithOptions :: Recorder (WithPriority Log ) -> SessionLoadingOptions -> FilePath -> IO (Rules () , Action IdeGhcSession )
452
456
loadSessionWithOptions recorder SessionLoadingOptions {.. } rootDir = do
453
457
let toAbsolutePath = toAbsolute rootDir
@@ -461,13 +465,25 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
461
465
-- they are inconsistent. So, everywhere you modify 'fileToFlags',
462
466
-- you have to modify 'filesMap' as well.
463
467
filesMap <- newVar HM. empty :: IO (Var FilesMap )
468
+
469
+ let clearCache = do
470
+ modifyVar_ hscEnvs $ \ _ -> pure Map. empty
471
+ modifyVar_ fileToFlags $ \ _ -> pure Map. empty
472
+ modifyVar_ filesMap $ \ _ -> pure HM. empty
473
+
464
474
-- Version of the mappings above
465
475
version <- newVar 0
466
476
cradleLock <- newMVar ()
467
477
-- putMVar cradleLock ()
468
478
biosSessionLoadingVar <- newVar Nothing :: IO (Var (Maybe SessionLoadingPreferenceConfig ))
469
479
let returnWithVersion fun = IdeGhcSession fun <$> liftIO (readVar version)
470
480
481
+ let hieYamlRule :: Rules ()
482
+ hieYamlRule = defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \ HieYaml hieYaml -> do
483
+ alwaysRerun
484
+ v <- Map. findWithDefault HM. empty (Just $ fromNormalizedFilePath hieYaml) <$> (liftIO $ readVar fileToFlags)
485
+ return $ Just v
486
+
471
487
let cradleLocRule :: Rules ()
472
488
cradleLocRule = defineNoDiagnostics (cmapWithPrio LogShake recorder) $ \ CradleLoc file -> do
473
489
res <- liftIO $ HieBios. findCradle $ fromNormalizedFilePath file
@@ -477,19 +493,21 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
477
493
-- todo make it absolute
478
494
return $ Just (normalise . toAbsolutePath <$> res)
479
495
480
- return $ (cradleLocRule, do
481
- clientConfig <- getClientConfigAction
482
- extras@ ShakeExtras {restartShakeSession, ideNc, knownTargetsVar, lspEnv
483
- } <- getShakeExtras
484
- let invalidateShakeCache = do
496
+ let invalidateShakeCache = do
485
497
void $ modifyVar' version succ
486
498
return $ toNoFileKey GhcSessionIO
487
499
500
+ return $ (cradleLocRule <> hieYamlRule, do
501
+ clientConfig <- getClientConfigAction
502
+ ShakeExtras {restartShakeSession, ideNc, knownTargetsVar, lspEnv
503
+ } <- getShakeExtras
504
+
488
505
IdeOptions { optTesting = IdeTesting optTesting
489
506
, optCheckProject = getCheckProject
490
507
, optExtensions
491
508
} <- getIdeOptions
492
509
510
+ -- relatively stand alone
493
511
-- populate the knownTargetsVar with all the
494
512
-- files in the project so that `knownFiles` can learn about them and
495
513
-- we can generate a complete module graph
@@ -722,28 +740,21 @@ loadSessionWithOptions recorder SessionLoadingOptions{..} rootDir = do
722
740
let hieYaml = fromMaybe cachedHieYamlLocation (Just hieYamlOld)
723
741
-- this cased a recompilation of the whole project
724
742
-- this can be turned in to shake
725
- liftIO$ Extra. whenM didSessionLoadingPreferenceConfigChange $ do
743
+ liftIO $ Extra. whenM didSessionLoadingPreferenceConfigChange $ do
726
744
logWith recorder Info LogSessionLoadingChanged
727
745
-- If the dependencies are out of date then clear both caches and start
728
746
-- again.
729
- liftIO$ modifyVar_ fileToFlags (const (return Map. empty))
730
- liftIO$ modifyVar_ filesMap (const (return HM. empty))
731
- -- Don't even keep the name cache, we start from scratch here!
732
- liftIO$ modifyVar_ hscEnvs (const (return Map. empty))
733
-
747
+ clearCache
734
748
-- fileToFlags is caching
735
749
v <- Map. findWithDefault HM. empty hieYaml <$> (liftIO$ readVar fileToFlags)
736
750
case HM. lookup file v of
737
751
Just (opts, old_di) -> do
738
- deps_ok <- liftIO$ checkDependencyInfo old_di
752
+ deps_ok <- liftIO $ checkDependencyInfo old_di
739
753
if not deps_ok
740
754
then do
741
755
-- If the dependencies are out of date then clear both caches and start
742
756
-- again.
743
- liftIO$ modifyVar_ fileToFlags (const (return Map. empty))
744
- liftIO$ modifyVar_ filesMap (const (return HM. empty))
745
- -- Keep the same name cache
746
- liftIO$ modifyVar_ hscEnvs (return . Map. adjust (const [] ) hieYaml )
757
+ liftIO $ clearCache
747
758
consultCradle file
748
759
else return (opts, Map. keys old_di)
749
760
Nothing -> consultCradle file
0 commit comments