@@ -378,16 +378,20 @@ updateFileDiagnostics ::
378 -> ShakeExtras
378 -> ShakeExtras
379 -> [Diagnostic] -- ^ current results
379 -> [Diagnostic] -- ^ current results
380 -> Action ()
380 -> Action ()
381−updateFileDiagnostics fp k ShakeExtras{diagnostics, state} current = do
381+updateFileDiagnostics fp k ShakeExtras{diagnostics, state, eventer} current = liftIO $ do
382− (newDiags, oldDiags) <- liftIO $ do
383− modTime <- join <$> getValues state GetModificationTime fp
382+ modTime <- join <$> getValues state GetModificationTime fp
384+ -- Mask async exceptions to ensure that updated diagnostics are always
385+ -- published. Otherwise, we might never publish certain diagnostics if
386+ -- an exception strikes between modifyVar but before
387+ -- publishDiagnosticsNotification.
384− modifyVar diagnostics $ \old -> do
388+ (newDiags, oldDiags) <- modifyVar diagnostics $ \old -> do
385 let oldDiags = getFileDiagnostics fp old
389 let oldDiags = getFileDiagnostics fp old
386 let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime) (T.pack $ show k) current old
390 let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime) (T.pack $ show k) current old
387 let newDiags = getFileDiagnostics fp newDiagsStore
391 let newDiags = getFileDiagnostics fp newDiagsStore
388 pure (newDiagsStore, (newDiags, oldDiags))
392 pure (newDiagsStore, (newDiags, oldDiags))
389− when (newDiags /= oldDiags) $
393+ when (newDiags /= oldDiags) $
390− sendEvent $ publishDiagnosticsNotification fp newDiags
394+ eventer $ publishDiagnosticsNotification fp newDiags
392publishDiagnosticsNotification :: NormalizedFilePath -> [Diagnostic] -> LSP.FromServerMessage
396publishDiagnosticsNotification :: NormalizedFilePath -> [Diagnostic] -> LSP.FromServerMessage
393publishDiagnosticsNotification fp diags =
397publishDiagnosticsNotification fp diags =