Skip to content

Commit 9faa179

Browse files
Fix flaky boot def test (haskell#2686)
* fix flaky boot-def test * fix test * refactor to use parser style * remove slight duplication * add comment to test Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
1 parent 7695832 commit 9faa179

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

ghcide/test/exe/Main.hs

+19-6
Original file line numberDiff line numberDiff line change
@@ -5562,12 +5562,25 @@ bootTests = testGroup "boot"
55625562
-- Dirty the cache
55635563
liftIO $ runInDir dir $ do
55645564
cDoc <- createDoc cPath "haskell" cSource
5565-
_ <- getHover cDoc $ Position 4 3
5566-
~() <- skipManyTill anyMessage $ satisfyMaybe $ \case
5567-
FromServerMess (SCustomMethod "ghcide/reference/ready") (NotMess NotificationMessage{_params = fp}) -> do
5568-
A.Success fp' <- pure $ fromJSON fp
5569-
if equalFilePath fp' cPath then pure () else Nothing
5570-
_ -> Nothing
5565+
-- We send a hover request then wait for either the hover response or
5566+
-- `ghcide/reference/ready` notification.
5567+
-- Once we receive one of the above, we wait for the other that we
5568+
-- 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
5571+
-- session will find no definitions.
5572+
let hoverParams = HoverParams cDoc (Position 4 3) Nothing
5573+
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
5578+
let parseHoverResponse = responseForId STextDocumentHover hoverRequestId
5579+
hoverResponseOrReadyMessage <- skipManyTill anyMessage ((Left <$> parseHoverResponse) <|> (Right <$> parseReadyMessage))
5580+
_ <- skipManyTill anyMessage $
5581+
case hoverResponseOrReadyMessage of
5582+
Left _ -> void parseReadyMessage
5583+
Right _ -> void parseHoverResponse
55715584
closeDoc cDoc
55725585
cdoc <- createDoc cPath "haskell" cSource
55735586
locs <- getDefinitions cdoc (Position 7 4)

0 commit comments

Comments
 (0)