@@ -57,7 +57,7 @@ module Development.IDE.Core.Shake(
5757 FileVersion (.. ),
5858 updatePositionMapping ,
5959 updatePositionMappingHelper ,
60- deleteValue , recordDirtyKeys ,
60+ deleteValue , recordDirtyKeys , recordDirtyKeySet ,
6161 WithProgressFunc , WithIndefiniteProgressFunc ,
6262 ProgressEvent (.. ),
6363 DelayedAction , mkDelayedAction ,
@@ -137,6 +137,7 @@ import Development.IDE.Graph.Database (ShakeDatabase,
137137 shakeNewDatabase ,
138138 shakeProfileDatabase ,
139139 shakeRunDatabaseForKeys )
140+ import Development.IDE.Graph.Internal.Key (deleteKeySet )
140141import Development.IDE.Graph.Rule
141142import Development.IDE.Types.Action
142143import Development.IDE.Types.Diagnostics
@@ -328,6 +329,8 @@ data ShakeExtras = ShakeExtras
328329 -- ^ Default HLS config, only relevant if the client does not provide any Config
329330 , dirtyKeys :: TVar KeySet
330331 -- ^ Set of dirty rule keys since the last Shake run
332+ , runningKeys :: TVar KeySet
333+ -- ^ Set of running rule keys since the last Shake run
331334 }
332335
333336type WithProgressFunc = forall a .
@@ -573,11 +576,22 @@ recordDirtyKeys
573576 -> k
574577 -> [NormalizedFilePath ]
575578 -> STM (IO () )
576- recordDirtyKeys ShakeExtras {dirtyKeys} key file = do
579+ recordDirtyKeys ShakeExtras {dirtyKeys, runningKeys} key file = do
580+ modifyTVar' runningKeys $ \ x -> foldl' (flip deleteKeySet) x (toKey key <$> file)
577581 modifyTVar' dirtyKeys $ \ x -> foldl' (flip insertKeySet) x (toKey key <$> file)
578582 return $ withEventTrace " recordDirtyKeys" $ \ addEvent -> do
579583 addEvent (fromString $ unlines $ " dirty " <> show key : map fromNormalizedFilePath file)
580584
585+ recordDirtyKeySet
586+ :: ShakeExtras
587+ -> [Key ]
588+ -> STM (IO () )
589+ recordDirtyKeySet ShakeExtras {dirtyKeys, runningKeys} keys = do
590+ modifyTVar' runningKeys $ \ x -> foldl' (flip deleteKeySet) x keys
591+ modifyTVar' dirtyKeys $ \ x -> foldl' (flip insertKeySet) x keys
592+ return $ withEventTrace " recordDirtyKeys" $ \ addEvent -> do
593+ addEvent (fromString $ unlines $ " dirty: " : map show keys)
594+
581595-- | We return Nothing if the rule has not run and Just Failed if it has failed to produce a value.
582596getValues ::
583597 forall k v .
@@ -672,6 +686,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins debouncer
672686
673687 let clientCapabilities = maybe def LSP. resClientCapabilities lspEnv
674688 dirtyKeys <- newTVarIO mempty
689+ runningKeys <- newTVarIO mempty
675690 -- Take one VFS snapshot at the start
676691 vfsVar <- newTVarIO =<< vfsSnapshot lspEnv
677692 pure ShakeExtras {shakeRecorder = recorder, .. }
@@ -925,6 +940,7 @@ garbageCollectKeys label maxAge checkParents agedKeys = do
925940 ShakeExtras {state, dirtyKeys, lspEnv, shakeRecorder, ideTesting} <- getShakeExtras
926941 (n:: Int , garbage ) <- liftIO $
927942 foldM (removeDirtyKey dirtyKeys state) (0 ,[] ) agedKeys
943+
928944 t <- liftIO start
929945 when (n> 0 ) $ liftIO $ do
930946 logWith shakeRecorder Debug $ LogShakeGarbageCollection (T. pack label) n t
@@ -1186,9 +1202,11 @@ defineEarlyCutoff'
11861202 -> (Value v -> Action (Maybe BS. ByteString , IdeResult v ))
11871203 -> Action (RunResult (A (RuleResult k )))
11881204defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
1189- ShakeExtras {state, progress, dirtyKeys} <- getShakeExtras
1205+ ShakeExtras {state, progress, dirtyKeys, runningKeys } <- getShakeExtras
11901206 options <- getIdeOptions
11911207 (if optSkipProgress options key then id else inProgress progress file) $ do
1208+ let theKey = toKey key file
1209+ liftIO $ atomicallyNamed " define - runningKeys" $ modifyTVar' runningKeys (insertKeySet theKey)
11921210 val <- case mbOld of
11931211 Just old | mode == RunDependenciesSame -> do
11941212 mbValue <- liftIO $ atomicallyNamed " define - read 1" $ getValues state key file
@@ -1234,7 +1252,9 @@ defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
12341252 (if eq then ChangedRecomputeSame else ChangedRecomputeDiff )
12351253 (encodeShakeValue bs) $
12361254 A res
1237- liftIO $ atomicallyNamed " define - dirtyKeys" $ modifyTVar' dirtyKeys (deleteKeySet $ toKey key file)
1255+ liftIO $ atomicallyNamed " define - (runningKeys, dirtyKeys)" $ do
1256+ running <- readTVar runningKeys
1257+ when (memberKeySet theKey running) $ return (deleteKeySet theKey running) >> modifyTVar' dirtyKeys (deleteKeySet theKey)
12381258 return res
12391259 where
12401260 -- Highly unsafe helper to compute the version of a file
0 commit comments