on master help sign in
Mask async exceptions in updateFileDiagnostics (#1944)

* Mask async exceptions in updateFileDiagnostics * lsp-tests remove flaky flag

commitff492c37b364ab38adb7084021072df59d85cc35 authorAndreas Herrmann <42969706+aherrmann-da@users.noreply.github.com> dateMon 1 Jul 2019, 09:14 (7 years ago) parent205cce9
1 file changed+10−6
src/Development/IDE/Core/Shake.hs+10−6
src/Development/IDE/Core/Shake.hs+10−6
@@ -378,16 +378,20 @@ updateFileDiagnostics ::
378378 -> ShakeExtras
379379 -> [Diagnostic] -- ^ current results
380380 -> Action ()
381−updateFileDiagnostics fp k ShakeExtras{diagnostics, state} current = do
382− (newDiags, oldDiags) <- liftIO $ do
383− modTime <- join <$> getValues state GetModificationTime fp
384− modifyVar diagnostics $ \old -> do
381+updateFileDiagnostics fp k ShakeExtras{diagnostics, state, eventer} current = liftIO $ do
382+ modTime <- join <$> getValues state GetModificationTime fp
383+ mask_ $ do
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.
388+ (newDiags, oldDiags) <- modifyVar diagnostics $ \old -> do
385389 let oldDiags = getFileDiagnostics fp old
386390 let newDiagsStore = setStageDiagnostics fp (vfsVersion =<< modTime) (T.pack $ show k) current old
387391 let newDiags = getFileDiagnostics fp newDiagsStore
388392 pure (newDiagsStore, (newDiags, oldDiags))
389− when (newDiags /= oldDiags) $
390− sendEvent $ publishDiagnosticsNotification fp newDiags
393+ when (newDiags /= oldDiags) $
394+ eventer $ publishDiagnosticsNotification fp newDiags
391395
392396publishDiagnosticsNotification :: NormalizedFilePath -> [Diagnostic] -> LSP.FromServerMessage
393397publishDiagnosticsNotification fp diags =