@@ -77,6 +77,7 @@ import Test.Tasty.ExpectedFailure (expectFailBecause,
77
77
ignoreTestBecause )
78
78
import Test.Tasty.HUnit (Assertion , assertFailure ,
79
79
(@?=) )
80
+ import Language.LSP.Test (withTimeout )
80
81
81
82
noLiteralCaps :: ClientCapabilities
82
83
noLiteralCaps = def & L. textDocument ?~ textDocumentCaps
@@ -284,25 +285,13 @@ expectNoMoreDiagnostics timeout doc src = do
284
285
-- If timeout is 0 it will wait until the session timeout
285
286
waitForDiagnosticsFromSourceWithTimeout :: Seconds -> TextDocumentIdentifier -> String -> Test. Session [Diagnostic ]
286
287
waitForDiagnosticsFromSourceWithTimeout timeout document source = do
287
- diags <- withTimeout timeout $ waitForDiagnosticsFrom document
288
+ -- todo possible better if there is withTimeout on Seconds in LSP.
289
+ diags <- withTimeout (ceiling timeout) $ waitForDiagnosticsFrom document
288
290
return $ filter matches diags
289
291
where
290
292
matches :: Diagnostic -> Bool
291
293
matches d = d ^. L. source == Just (T. pack source)
292
294
293
- withTimeout :: Seconds -> Session a -> Session a
294
- withTimeout duration f = do
295
- chan <- asks messageChan
296
- timeoutId <- getCurTimeoutId
297
- modify $ \ s -> s { overridingTimeout = True }
298
- tid <- liftIO $ forkIO $ do
299
- threadDelay (ceiling $ duration * 1000000 )
300
- writeChan chan (TimeoutMessage timeoutId)
301
- res <- f
302
- liftIO $ killThread tid
303
- bumpTimeoutId timeoutId
304
- modify $ \ s -> s { overridingTimeout = False }
305
- return res
306
295
307
296
308
297
failIfSessionTimeout :: IO a -> IO a
0 commit comments