@@ -57,7 +57,7 @@ module Development.IDE.Core.Shake(
57
57
FileVersion (.. ),
58
58
updatePositionMapping ,
59
59
updatePositionMappingHelper ,
60
- deleteValue , recordDirtyKeys ,
60
+ deleteValue , recordDirtyKeys , recordDirtyKeySet ,
61
61
WithProgressFunc , WithIndefiniteProgressFunc ,
62
62
ProgressEvent (.. ),
63
63
DelayedAction , mkDelayedAction ,
@@ -137,6 +137,7 @@ import Development.IDE.Graph.Database (ShakeDatabase,
137
137
shakeNewDatabase ,
138
138
shakeProfileDatabase ,
139
139
shakeRunDatabaseForKeys )
140
+ import Development.IDE.Graph.Internal.Key (deleteKeySet )
140
141
import Development.IDE.Graph.Rule
141
142
import Development.IDE.Types.Action
142
143
import Development.IDE.Types.Diagnostics
@@ -328,6 +329,8 @@ data ShakeExtras = ShakeExtras
328
329
-- ^ Default HLS config, only relevant if the client does not provide any Config
329
330
, dirtyKeys :: TVar KeySet
330
331
-- ^ 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
331
334
}
332
335
333
336
type WithProgressFunc = forall a .
@@ -573,11 +576,22 @@ recordDirtyKeys
573
576
-> k
574
577
-> [NormalizedFilePath ]
575
578
-> 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)
577
581
modifyTVar' dirtyKeys $ \ x -> foldl' (flip insertKeySet) x (toKey key <$> file)
578
582
return $ withEventTrace " recordDirtyKeys" $ \ addEvent -> do
579
583
addEvent (fromString $ unlines $ " dirty " <> show key : map fromNormalizedFilePath file)
580
584
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
+
581
595
-- | We return Nothing if the rule has not run and Just Failed if it has failed to produce a value.
582
596
getValues ::
583
597
forall k v .
@@ -672,6 +686,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins debouncer
672
686
673
687
let clientCapabilities = maybe def LSP. resClientCapabilities lspEnv
674
688
dirtyKeys <- newTVarIO mempty
689
+ runningKeys <- newTVarIO mempty
675
690
-- Take one VFS snapshot at the start
676
691
vfsVar <- newTVarIO =<< vfsSnapshot lspEnv
677
692
pure ShakeExtras {shakeRecorder = recorder, .. }
@@ -925,6 +940,7 @@ garbageCollectKeys label maxAge checkParents agedKeys = do
925
940
ShakeExtras {state, dirtyKeys, lspEnv, shakeRecorder, ideTesting} <- getShakeExtras
926
941
(n:: Int , garbage ) <- liftIO $
927
942
foldM (removeDirtyKey dirtyKeys state) (0 ,[] ) agedKeys
943
+
928
944
t <- liftIO start
929
945
when (n> 0 ) $ liftIO $ do
930
946
logWith shakeRecorder Debug $ LogShakeGarbageCollection (T. pack label) n t
@@ -1186,9 +1202,11 @@ defineEarlyCutoff'
1186
1202
-> (Value v -> Action (Maybe BS. ByteString , IdeResult v ))
1187
1203
-> Action (RunResult (A (RuleResult k )))
1188
1204
defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
1189
- ShakeExtras {state, progress, dirtyKeys} <- getShakeExtras
1205
+ ShakeExtras {state, progress, dirtyKeys, runningKeys } <- getShakeExtras
1190
1206
options <- getIdeOptions
1191
1207
(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)
1192
1210
val <- case mbOld of
1193
1211
Just old | mode == RunDependenciesSame -> do
1194
1212
mbValue <- liftIO $ atomicallyNamed " define - read 1" $ getValues state key file
@@ -1234,7 +1252,9 @@ defineEarlyCutoff' doDiagnostics cmp key file mbOld mode action = do
1234
1252
(if eq then ChangedRecomputeSame else ChangedRecomputeDiff )
1235
1253
(encodeShakeValue bs) $
1236
1254
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)
1238
1258
return res
1239
1259
where
1240
1260
-- Highly unsafe helper to compute the version of a file
0 commit comments