@@ -6,6 +6,7 @@ module Development.IDE.Test
6
6
, cursorPosition
7
7
, requireDiagnostic
8
8
, expectDiagnostics
9
+ , expectNoMoreDiagnostics
9
10
) where
10
11
11
12
import Control.Applicative.Combinators
@@ -18,6 +19,7 @@ import Language.Haskell.LSP.Test hiding (message, openDoc')
18
19
import qualified Language.Haskell.LSP.Test as LspTest
19
20
import Language.Haskell.LSP.Types
20
21
import Language.Haskell.LSP.Types.Lens as Lsp
22
+ import System.Time.Extra
21
23
import Test.Tasty.HUnit
22
24
23
25
@@ -41,6 +43,32 @@ requireDiagnostic actuals expected@(severity, cursor, expectedMsg) = do
41
43
&& standardizeQuotes (T. toLower expectedMsg) `T.isInfixOf`
42
44
standardizeQuotes (T. toLower $ d ^. message)
43
45
46
+ -- | wait for @timeout@ seconds and report an assertion failure
47
+ -- if any diagnostic messages arrive in that period
48
+ expectNoMoreDiagnostics :: Seconds -> Session ()
49
+ expectNoMoreDiagnostics timeout = do
50
+ -- Give any further diagnostic messages time to arrive.
51
+ liftIO $ sleep timeout
52
+ -- Send a dummy message to provoke a response from the server.
53
+ -- This guarantees that we have at least one message to
54
+ -- process, so message won't block or timeout.
55
+ void $ sendRequest (CustomClientMethod " non-existent-method" ) ()
56
+ handleMessages
57
+ where
58
+ handleMessages = handleDiagnostic <|> handleCustomMethodResponse <|> ignoreOthers
59
+ handleDiagnostic = do
60
+ diagsNot <- LspTest. message :: Session PublishDiagnosticsNotification
61
+ let fileUri = diagsNot ^. params . uri
62
+ actual = diagsNot ^. params . diagnostics
63
+ liftIO $ assertFailure $
64
+ " Got unexpected diagnostics for " <> show fileUri <>
65
+ " got " <> show actual
66
+ handleCustomMethodResponse =
67
+ -- the CustomClientMethod triggers a log message about ignoring it
68
+ -- handle that and then exit
69
+ void (LspTest. message :: Session LogMessageNotification )
70
+ ignoreOthers = void anyMessage >> handleMessages
71
+
44
72
expectDiagnostics :: [(FilePath , [(DiagnosticSeverity , Cursor , T. Text )])] -> Session ()
45
73
expectDiagnostics expected = do
46
74
expected' <- Map. fromListWith (<>) <$> traverseOf (traverse . _1) (fmap toNormalizedUri . getDocUri) expected
0 commit comments