Skip to content

Commit ac3943c

Browse files
committed
tighten up the update diagnostics loop to avoid contention
1 parent 05f25c9 commit ac3943c

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

ghcide/src/Development/IDE/Core/Debouncer.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ asyncRegisterEvent d 0 k fire = do
4444
whenJust (Map.lookup k m) cancel
4545
pure $ Map.delete k m
4646
fire
47-
asyncRegisterEvent d delay k fire = modifyVar_ d $ \m -> mask_ $ do
48-
whenJust (Map.lookup k m) cancel
47+
asyncRegisterEvent d delay k fire = do
4948
a <- asyncWithUnmask $ \unmask -> unmask $ do
5049
sleep delay
5150
fire
5251
modifyVar_ d (pure . Map.delete k)
53-
pure $ Map.insert k a m
52+
modifyVar_ d $ \m -> mask_ $ do
53+
whenJust (Map.lookup k m) cancel
54+
pure $ Map.insert k a m
5455

5556
-- | Debouncer used in the DAML CLI compiler that emits events immediately.
5657
noopDebouncer :: Debouncer k

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,15 +1100,16 @@ updateFileDiagnostics fp k ShakeExtras{logger, diagnostics, hiddenDiagnostics, p
11001100
let uri = filePathToUri' fp
11011101
let delay = if null newDiags then 0.1 else 0
11021102
registerEvent debouncer delay uri $ do
1103-
mask_ $ modifyVar_ publishedDiagnostics $ \published -> do
1103+
join $ mask_ $ modifyVar publishedDiagnostics $ \published -> do
11041104
let lastPublish = HMap.lookupDefault [] uri published
1105-
when (lastPublish /= newDiags) $ case lspEnv of
1106-
Nothing -> -- Print an LSP event.
1107-
logInfo logger $ showDiagnosticsColored $ map (fp,ShowDiag,) newDiags
1108-
Just env -> LSP.runLspT env $
1109-
LSP.sendNotification LSP.STextDocumentPublishDiagnostics $
1110-
LSP.PublishDiagnosticsParams (fromNormalizedUri uri) ver (List newDiags)
1111-
pure $! HMap.insert uri newDiags published
1105+
!published' = HMap.insert uri newDiags published
1106+
action = when (lastPublish /= newDiags) $ case lspEnv of
1107+
Nothing -> -- Print an LSP event.
1108+
logInfo logger $ showDiagnosticsColored $ map (fp,ShowDiag,) newDiags
1109+
Just env -> LSP.runLspT env $
1110+
LSP.sendNotification LSP.STextDocumentPublishDiagnostics $
1111+
LSP.PublishDiagnosticsParams (fromNormalizedUri uri) ver (List newDiags)
1112+
return (published', action)
11121113

11131114
newtype Priority = Priority Double
11141115

0 commit comments

Comments
 (0)