@@ -178,7 +178,7 @@ import System.Time.Extra
178
178
data Log
179
179
= LogCreateHieDbExportsMapStart
180
180
| LogCreateHieDbExportsMapFinish ! Int
181
- | LogBuildSessionRestart ! String ! [DelayedActionInternal ] ! (HashSet Key ) ! Seconds ! (Maybe FilePath )
181
+ | LogBuildSessionRestart ! String ! [DelayedActionInternal ] ! (KeySet ) ! Seconds ! (Maybe FilePath )
182
182
| LogBuildSessionRestartTakingTooLong ! Seconds
183
183
| LogDelayedAction ! (DelayedAction () ) ! Seconds
184
184
| LogBuildSessionFinish ! (Maybe SomeException )
@@ -197,7 +197,7 @@ instance Pretty Log where
197
197
vcat
198
198
[ " Restarting build session due to" <+> pretty reason
199
199
, " Action Queue:" <+> pretty (map actionName actionQueue)
200
- , " Keys:" <+> pretty (map show $ HSet. toList keyBackLog)
200
+ , " Keys:" <+> pretty (map show $ toListKeySet keyBackLog)
201
201
, " Aborting previous build session took" <+> pretty (showDuration abortDuration) <+> pretty shakeProfilePath ]
202
202
LogBuildSessionRestartTakingTooLong seconds ->
203
203
" Build restart is taking too long (" <> pretty seconds <> " seconds)"
@@ -279,7 +279,7 @@ data ShakeExtras = ShakeExtras
279
279
,clientCapabilities :: ClientCapabilities
280
280
, withHieDb :: WithHieDb -- ^ Use only to read.
281
281
, hiedbWriter :: HieDbWriter -- ^ use to write
282
- , persistentKeys :: TVar (HMap. HashMap Key GetStalePersistent )
282
+ , persistentKeys :: TVar (KeyMap GetStalePersistent )
283
283
-- ^ Registery for functions that compute/get "stale" results for the rule
284
284
-- (possibly from disk)
285
285
, vfsVar :: TVar VFS
@@ -290,7 +290,7 @@ data ShakeExtras = ShakeExtras
290
290
-- We don't need a STM.Map because we never update individual keys ourselves.
291
291
, defaultConfig :: Config
292
292
-- ^ Default HLS config, only relevant if the client does not provide any Config
293
- , dirtyKeys :: TVar ( HashSet Key )
293
+ , dirtyKeys :: TVar KeySet
294
294
-- ^ Set of dirty rule keys since the last Shake run
295
295
}
296
296
@@ -324,7 +324,7 @@ getPluginConfig plugin = do
324
324
addPersistentRule :: IdeRule k v => k -> (NormalizedFilePath -> IdeAction (Maybe (v ,PositionDelta ,TextDocumentVersion ))) -> Rules ()
325
325
addPersistentRule k getVal = do
326
326
ShakeExtras {persistentKeys} <- getShakeExtrasRules
327
- void $ liftIO $ atomically $ modifyTVar' persistentKeys $ HMap. insert ( Key k) (fmap (fmap (first3 toDyn)) . getVal)
327
+ void $ liftIO $ atomically $ modifyTVar' persistentKeys $ insertKeyMap (newKey k) (fmap (fmap (first3 toDyn)) . getVal)
328
328
329
329
class Typeable a => IsIdeGlobal a where
330
330
@@ -399,7 +399,7 @@ lastValueIO s@ShakeExtras{positionMapping,persistentKeys,state} k file = do
399
399
pmap <- readTVarIO persistentKeys
400
400
mv <- runMaybeT $ do
401
401
liftIO $ Logger. logDebug (logger s) $ T. pack $ " LOOKUP PERSISTENT FOR: " ++ show k
402
- f <- MaybeT $ pure $ HMap. lookup ( Key k) pmap
402
+ f <- MaybeT $ pure $ lookupKeyMap (newKey k) pmap
403
403
(dv,del,ver) <- MaybeT $ runIdeAction " lastValueIO" s $ f file
404
404
MaybeT $ pure $ (,del,ver) <$> fromDynamic dv
405
405
case mv of
@@ -509,7 +509,7 @@ deleteValue
509
509
-> STM ()
510
510
deleteValue ShakeExtras {dirtyKeys, state} key file = do
511
511
STM. delete (toKey key file) state
512
- modifyTVar' dirtyKeys $ HSet. insert (toKey key file)
512
+ modifyTVar' dirtyKeys $ insertKeySet (toKey key file)
513
513
514
514
recordDirtyKeys
515
515
:: Shake. ShakeValue k
@@ -518,7 +518,7 @@ recordDirtyKeys
518
518
-> [NormalizedFilePath ]
519
519
-> STM (IO () )
520
520
recordDirtyKeys ShakeExtras {dirtyKeys} key file = do
521
- modifyTVar' dirtyKeys $ \ x -> foldl' (flip HSet. insert ) x (toKey key <$> file)
521
+ modifyTVar' dirtyKeys $ \ x -> foldl' (flip insertKeySet ) x (toKey key <$> file)
522
522
return $ withEventTrace " recordDirtyKeys" $ \ addEvent -> do
523
523
addEvent (fromString $ unlines $ " dirty " <> show key : map fromNormalizedFilePath file)
524
524
@@ -594,7 +594,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
594
594
positionMapping <- STM. newIO
595
595
knownTargetsVar <- newTVarIO $ hashed HMap. empty
596
596
let restartShakeSession = shakeRestart recorder ideState
597
- persistentKeys <- newTVarIO HMap. empty
597
+ persistentKeys <- newTVarIO mempty
598
598
indexPending <- newTVarIO HMap. empty
599
599
indexCompleted <- newTVarIO 0
600
600
indexProgressToken <- newVar Nothing
@@ -637,7 +637,7 @@ shakeOpen recorder lspEnv defaultConfig idePlugins logger debouncer
637
637
638
638
-- monitoring
639
639
let readValuesCounter = fromIntegral . countRelevantKeys checkParents <$> getStateKeys shakeExtras
640
- readDirtyKeys = fromIntegral . countRelevantKeys checkParents . HSet. toList <$> readTVarIO(dirtyKeys shakeExtras)
640
+ readDirtyKeys = fromIntegral . countRelevantKeys checkParents . toListKeySet <$> readTVarIO(dirtyKeys shakeExtras)
641
641
readIndexPending = fromIntegral . HMap. size <$> readTVarIO (indexPending $ hiedbWriter shakeExtras)
642
642
readExportsMap = fromIntegral . HMap. size . getExportsMap <$> readTVarIO (exportsMap shakeExtras)
643
643
readDatabaseCount = fromIntegral . countRelevantKeys checkParents . map fst <$> shakeGetDatabaseKeys shakeDb
@@ -797,10 +797,10 @@ newSession recorder extras@ShakeExtras{..} vfsMod shakeDb acts reason = do
797
797
workRun restore = withSpan " Shake session" $ \ otSpan -> do
798
798
setTag otSpan " reason" (fromString reason)
799
799
setTag otSpan " queue" (fromString $ unlines $ map actionName reenqueued)
800
- whenJust allPendingKeys $ \ kk -> setTag otSpan " keys" (BS8. pack $ unlines $ map show $ toList kk)
800
+ whenJust allPendingKeys $ \ kk -> setTag otSpan " keys" (BS8. pack $ unlines $ map show $ toListKeySet kk)
801
801
let keysActs = pumpActionThread otSpan : map (run otSpan) (reenqueued ++ acts)
802
802
res <- try @ SomeException $
803
- restore $ shakeRunDatabaseForKeys (HSet. toList <$> allPendingKeys) shakeDb keysActs
803
+ restore $ shakeRunDatabaseForKeys (toListKeySet <$> allPendingKeys) shakeDb keysActs
804
804
return $ do
805
805
let exception =
806
806
case res of
@@ -890,7 +890,7 @@ garbageCollectKeys label maxAge checkParents agedKeys = do
890
890
= atomicallyNamed " GC" $ do
891
891
gotIt <- STM. focus (Focus. member <* Focus. delete) k values
892
892
when gotIt $
893
- modifyTVar' dk (HSet. insert k)
893
+ modifyTVar' dk (insertKeySet k)
894
894
return $ if gotIt then (counter+ 1 , k: keys) else st
895
895
| otherwise = pure st
896
896
@@ -1068,7 +1068,7 @@ defineEarlyCutoff recorder (Rule op) = addRule $ \(Q (key, file)) (old :: Maybe
1068
1068
extras <- getShakeExtras
1069
1069
let diagnostics ver diags = do
1070
1070
traceDiagnostics diags
1071
- updateFileDiagnostics recorder file ver (Key key) extras . map (\ (_,y,z) -> (y,z)) $ diags
1071
+ updateFileDiagnostics recorder file ver (newKey key) extras . map (\ (_,y,z) -> (y,z)) $ diags
1072
1072
defineEarlyCutoff' diagnostics (==) key file old mode $ const $ op key file
1073
1073
defineEarlyCutoff recorder (RuleNoDiagnostics op) = addRule $ \ (Q (key, file)) (old :: Maybe BS. ByteString ) mode -> otTracedAction key file mode traceA $ \ traceDiagnostics -> do
1074
1074
let diagnostics _ver diags = do
@@ -1087,7 +1087,7 @@ defineEarlyCutoff recorder (RuleWithOldValue op) = addRule $ \(Q (key, file)) (o
1087
1087
extras <- getShakeExtras
1088
1088
let diagnostics ver diags = do
1089
1089
traceDiagnostics diags
1090
- updateFileDiagnostics recorder file ver (Key key) extras . map (\ (_,y,z) -> (y,z)) $ diags
1090
+ updateFileDiagnostics recorder file ver (newKey key) extras . map (\ (_,y,z) -> (y,z)) $ diags
1091
1091
defineEarlyCutoff' diagnostics (==) key file old mode $ op key file
1092
1092
1093
1093
defineNoFile :: IdeRule k v => Recorder (WithPriority Log ) -> (k -> Action v ) -> Rules ()
@@ -1160,7 +1160,7 @@ defineEarlyCutoff' doDiagnostics cmp key file old mode action = do
1160
1160
(if eq then ChangedRecomputeSame else ChangedRecomputeDiff )
1161
1161
(encodeShakeValue bs) $
1162
1162
A res
1163
- liftIO $ atomicallyNamed " define - dirtyKeys" $ modifyTVar' dirtyKeys (HSet. delete $ toKey key file)
1163
+ liftIO $ atomicallyNamed " define - dirtyKeys" $ modifyTVar' dirtyKeys (deleteKeySet $ toKey key file)
1164
1164
return res
1165
1165
where
1166
1166
-- Highly unsafe helper to compute the version of a file
@@ -1199,15 +1199,16 @@ updateFileDiagnostics :: MonadIO m
1199
1199
-> ShakeExtras
1200
1200
-> [(ShowDiagnostic ,Diagnostic )] -- ^ current results
1201
1201
-> m ()
1202
- updateFileDiagnostics recorder fp ver k ShakeExtras {diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv} current =
1202
+ updateFileDiagnostics recorder fp ver k ShakeExtras {diagnostics, hiddenDiagnostics, publishedDiagnostics, debouncer, lspEnv, ideTesting} current0 =
1203
1203
liftIO $ withTrace (" update diagnostics " <> fromString(fromNormalizedFilePath fp)) $ \ addTag -> do
1204
1204
addTag " key" (show k)
1205
1205
let (currentShown, currentHidden) = partition ((== ShowDiag ) . fst ) current
1206
1206
uri = filePathToUri' fp
1207
1207
addTagUnsafe :: String -> String -> String -> a -> a
1208
1208
addTagUnsafe msg t x v = unsafePerformIO(addTag (msg <> t) x) `seq` v
1209
1209
update :: (forall a . String -> String -> a -> a ) -> [Diagnostic ] -> STMDiagnosticStore -> STM [Diagnostic ]
1210
- update addTagUnsafe new store = addTagUnsafe " count" (show $ Prelude. length new) $ setStageDiagnostics addTagUnsafe uri ver (T. pack $ show k) new store
1210
+ update addTagUnsafe new store = addTagUnsafe " count" (show $ Prelude. length new) $ setStageDiagnostics addTagUnsafe uri ver (renderKey k) new store
1211
+ current = second diagsFromRule <$> current0
1211
1212
addTag " version" (show ver)
1212
1213
mask_ $ do
1213
1214
-- Mask async exceptions to ensure that updated diagnostics are always
@@ -1230,6 +1231,22 @@ updateFileDiagnostics recorder fp ver k ShakeExtras{diagnostics, hiddenDiagnosti
1230
1231
LSP. sendNotification LSP. STextDocumentPublishDiagnostics $
1231
1232
LSP. PublishDiagnosticsParams (fromNormalizedUri uri) (fmap fromIntegral ver) (List newDiags)
1232
1233
return action
1234
+ where
1235
+ diagsFromRule :: Diagnostic -> Diagnostic
1236
+ diagsFromRule c@ Diagnostic {_range}
1237
+ | coerce ideTesting = c
1238
+ {_relatedInformation =
1239
+ Just $ List [
1240
+ DiagnosticRelatedInformation
1241
+ (Location
1242
+ (filePathToUri $ fromNormalizedFilePath fp)
1243
+ _range
1244
+ )
1245
+ (T. pack $ show k)
1246
+ ]
1247
+ }
1248
+ | otherwise = c
1249
+
1233
1250
1234
1251
newtype Priority = Priority Double
1235
1252
0 commit comments