@@ -58,7 +58,9 @@ import Development.IDE.Test (Cursor,
58
58
standardizeQuotes ,
59
59
waitForAction ,
60
60
waitForGC ,
61
- waitForTypecheck )
61
+ waitForTypecheck ,
62
+ isReferenceReady ,
63
+ referenceReady )
62
64
import Development.IDE.Test.Runfiles
63
65
import qualified Development.IDE.Types.Diagnostics as Diagnostics
64
66
import Development.IDE.Types.Location
@@ -5373,7 +5375,7 @@ cradleTests = testGroup "cradle"
5373
5375
[testGroup " dependencies" [sessionDepsArePickedUp]
5374
5376
,testGroup " ignore-fatal" [ignoreFatalWarning]
5375
5377
,testGroup " loading" [loadCradleOnlyonce, retryFailedCradle]
5376
- ,testGroup " multi" [simpleMultiTest, simpleMultiTest2, simpleMultiDefTest]
5378
+ ,testGroup " multi" [simpleMultiTest, simpleMultiTest2, simpleMultiTest3, simpleMultiDefTest]
5377
5379
,testGroup " sub-directory" [simpleSubDirectoryTest]
5378
5380
]
5379
5381
@@ -5493,12 +5495,10 @@ simpleMultiTest :: TestTree
5493
5495
simpleMultiTest = testCase " simple-multi-test" $ withLongTimeout $ runWithExtraFiles " multi" $ \ dir -> do
5494
5496
let aPath = dir </> " a/A.hs"
5495
5497
bPath = dir </> " b/B.hs"
5496
- aSource <- liftIO $ readFileUtf8 aPath
5497
- adoc <- createDoc aPath " haskell" aSource
5498
+ adoc <- openDoc aPath " haskell "
5499
+ bdoc <- openDoc bPath " haskell"
5498
5500
WaitForIdeRuleResult {.. } <- waitForAction " TypeCheck" adoc
5499
5501
liftIO $ assertBool " A should typecheck" ideResultSuccess
5500
- bSource <- liftIO $ readFileUtf8 bPath
5501
- bdoc <- createDoc bPath " haskell" bSource
5502
5502
WaitForIdeRuleResult {.. } <- waitForAction " TypeCheck" bdoc
5503
5503
liftIO $ assertBool " B should typecheck" ideResultSuccess
5504
5504
locs <- getDefinitions bdoc (Position 2 7 )
@@ -5511,15 +5511,30 @@ simpleMultiTest2 :: TestTree
5511
5511
simpleMultiTest2 = testCase " simple-multi-test2" $ runWithExtraFiles " multi" $ \ dir -> do
5512
5512
let aPath = dir </> " a/A.hs"
5513
5513
bPath = dir </> " b/B.hs"
5514
- bSource <- liftIO $ readFileUtf8 bPath
5515
- bdoc <- createDoc bPath " haskell" bSource
5516
- expectNoMoreDiagnostics 10
5517
- aSource <- liftIO $ readFileUtf8 aPath
5518
- (TextDocumentIdentifier adoc) <- createDoc aPath " haskell" aSource
5519
- -- Need to have some delay here or the test fails
5520
- expectNoMoreDiagnostics 10
5514
+ bdoc <- openDoc bPath " haskell"
5515
+ WaitForIdeRuleResult {} <- waitForAction " TypeCheck" bdoc
5516
+ TextDocumentIdentifier auri <- openDoc aPath " haskell"
5517
+ skipManyTill anyMessage $ isReferenceReady aPath
5521
5518
locs <- getDefinitions bdoc (Position 2 7 )
5522
- let fooL = mkL adoc 2 0 2 3
5519
+ let fooL = mkL auri 2 0 2 3
5520
+ checkDefs locs (pure [fooL])
5521
+ expectNoMoreDiagnostics 0.5
5522
+
5523
+ -- Now with 3 components
5524
+ simpleMultiTest3 :: TestTree
5525
+ simpleMultiTest3 = knownBrokenForGhcVersions [GHC92 ] " #2693" $
5526
+ testCase " simple-multi-test3" $ runWithExtraFiles " multi" $ \ dir -> do
5527
+ let aPath = dir </> " a/A.hs"
5528
+ bPath = dir </> " b/B.hs"
5529
+ cPath = dir </> " c/C.hs"
5530
+ bdoc <- openDoc bPath " haskell"
5531
+ WaitForIdeRuleResult {} <- waitForAction " TypeCheck" bdoc
5532
+ TextDocumentIdentifier auri <- openDoc aPath " haskell"
5533
+ skipManyTill anyMessage $ isReferenceReady aPath
5534
+ cdoc <- openDoc cPath " haskell"
5535
+ WaitForIdeRuleResult {} <- waitForAction " TypeCheck" cdoc
5536
+ locs <- getDefinitions cdoc (Position 2 7 )
5537
+ let fooL = mkL auri 2 0 2 3
5523
5538
checkDefs locs (pure [fooL])
5524
5539
expectNoMoreDiagnostics 0.5
5525
5540
@@ -5531,11 +5546,7 @@ simpleMultiDefTest = testCase "simple-multi-def-test" $ runWithExtraFiles "multi
5531
5546
adoc <- liftIO $ runInDir dir $ do
5532
5547
aSource <- liftIO $ readFileUtf8 aPath
5533
5548
adoc <- createDoc aPath " haskell" aSource
5534
- ~ () <- skipManyTill anyMessage $ satisfyMaybe $ \ case
5535
- FromServerMess (SCustomMethod " ghcide/reference/ready" ) (NotMess NotificationMessage {_params = fp}) -> do
5536
- A. Success fp' <- pure $ fromJSON fp
5537
- if equalFilePath fp' aPath then pure () else Nothing
5538
- _ -> Nothing
5549
+ skipManyTill anyMessage $ isReferenceReady aPath
5539
5550
closeDoc adoc
5540
5551
pure adoc
5541
5552
bSource <- liftIO $ readFileUtf8 bPath
@@ -5566,18 +5577,15 @@ bootTests = testGroup "boot"
5566
5577
-- `ghcide/reference/ready` notification.
5567
5578
-- Once we receive one of the above, we wait for the other that we
5568
5579
-- haven't received yet.
5569
- -- If we don't wait for the `ready` notification it is possible
5570
- -- that the `getDefinitions` request/response in the outer ghcide
5580
+ -- If we don't wait for the `ready` notification it is possible
5581
+ -- that the `getDefinitions` request/response in the outer ghcide
5571
5582
-- session will find no definitions.
5572
5583
let hoverParams = HoverParams cDoc (Position 4 3 ) Nothing
5573
5584
hoverRequestId <- sendRequest STextDocumentHover hoverParams
5574
- let parseReadyMessage = satisfy $ \ case
5575
- FromServerMess (SCustomMethod " ghcide/reference/ready" ) (NotMess NotificationMessage {_params = params})
5576
- | A. Success fp <- fromJSON params -> equalFilePath fp cPath
5577
- _ -> False
5585
+ let parseReadyMessage = isReferenceReady cPath
5578
5586
let parseHoverResponse = responseForId STextDocumentHover hoverRequestId
5579
5587
hoverResponseOrReadyMessage <- skipManyTill anyMessage ((Left <$> parseHoverResponse) <|> (Right <$> parseReadyMessage))
5580
- _ <- skipManyTill anyMessage $
5588
+ _ <- skipManyTill anyMessage $
5581
5589
case hoverResponseOrReadyMessage of
5582
5590
Left _ -> void parseReadyMessage
5583
5591
Right _ -> void parseHoverResponse
@@ -5990,11 +5998,7 @@ referenceTestSession name thisDoc docs' f = testSessionWithExtraFiles "reference
5990
5998
loop :: [FilePath ] -> Session ()
5991
5999
loop [] = pure ()
5992
6000
loop docs = do
5993
- doc <- skipManyTill anyMessage $ satisfyMaybe $ \ case
5994
- FromServerMess (SCustomMethod " ghcide/reference/ready" ) (NotMess NotificationMessage {_params = fp}) -> do
5995
- A. Success fp' <- pure $ fromJSON fp
5996
- find (fp' == ) docs
5997
- _ -> Nothing
6001
+ doc <- skipManyTill anyMessage $ referenceReady (`elem` docs)
5998
6002
loop (delete doc docs)
5999
6003
loop docs
6000
6004
f dir
0 commit comments