Skip to content

Commit 12088e6

Browse files
committed
lockless publishedDiagnostics
1 parent 2b3f5f1 commit 12088e6

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ data ShakeExtras = ShakeExtras
195195
,state :: Values
196196
,diagnostics :: Var DiagnosticStore
197197
,hiddenDiagnostics :: Var DiagnosticStore
198-
,publishedDiagnostics :: Var (HMap.HashMap NormalizedUri [Diagnostic])
198+
,publishedDiagnostics :: STM.Map NormalizedUri [Diagnostic]
199199
-- ^ This represents the set of diagnostics that we have published.
200200
-- Due to debouncing not every change might get published.
201201
,positionMapping :: Var (HMap.HashMap NormalizedUri (Map TextDocumentVersion (PositionDelta, PositionMapping)))
@@ -505,7 +505,7 @@ shakeOpen lspEnv defaultConfig logger debouncer
505505
state <- STM.newIO
506506
diagnostics <- newVar mempty
507507
hiddenDiagnostics <- newVar mempty
508-
publishedDiagnostics <- newVar mempty
508+
publishedDiagnostics <- STM.newIO
509509
positionMapping <- newVar HMap.empty
510510
knownTargetsVar <- newVar $ hashed HMap.empty
511511
let restartShakeSession = shakeRestart ideState
@@ -1162,16 +1162,15 @@ updateFileDiagnostics fp k ShakeExtras{logger, diagnostics, hiddenDiagnostics, p
11621162
let uri = filePathToUri' fp
11631163
let delay = if null newDiags then 0.1 else 0
11641164
registerEvent debouncer delay uri $ do
1165-
join $ mask_ $ modifyVar publishedDiagnostics $ \published -> do
1166-
let lastPublish = HMap.lookupDefault [] uri published
1167-
!published' = HMap.insert uri newDiags published
1168-
action = when (lastPublish /= newDiags) $ case lspEnv of
1165+
join $ mask_ $ do
1166+
lastPublish <- atomically $ STM.focus (Focus.lookupWithDefault [] <* Focus.insert newDiags) uri publishedDiagnostics
1167+
let action = when (lastPublish /= newDiags) $ case lspEnv of
11691168
Nothing -> -- Print an LSP event.
11701169
logInfo logger $ showDiagnosticsColored $ map (fp,ShowDiag,) newDiags
11711170
Just env -> LSP.runLspT env $
11721171
LSP.sendNotification LSP.STextDocumentPublishDiagnostics $
11731172
LSP.PublishDiagnosticsParams (fromNormalizedUri uri) ver (List newDiags)
1174-
return (published', action)
1173+
return action
11751174

11761175
newtype Priority = Priority Double
11771176

0 commit comments

Comments
 (0)