Skip to content

Commit 7663637

Browse files
committed
Helpers for reference/ready message parsing
1 parent 79c4caa commit 7663637

File tree

2 files changed

+26
-17
lines changed

2 files changed

+26
-17
lines changed

ghcide/test/exe/Main.hs

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ import Development.IDE.Test (Cursor,
5858
standardizeQuotes,
5959
waitForAction,
6060
waitForGC,
61-
waitForTypecheck)
61+
waitForTypecheck,
62+
isReferenceReady,
63+
referenceReady)
6264
import Development.IDE.Test.Runfiles
6365
import qualified Development.IDE.Types.Diagnostics as Diagnostics
6466
import Development.IDE.Types.Location
@@ -5534,11 +5536,7 @@ simpleMultiDefTest = testCase "simple-multi-def-test" $ runWithExtraFiles "multi
55345536
adoc <- liftIO $ runInDir dir $ do
55355537
aSource <- liftIO $ readFileUtf8 aPath
55365538
adoc <- createDoc aPath "haskell" aSource
5537-
~() <- skipManyTill anyMessage $ satisfyMaybe $ \case
5538-
FromServerMess (SCustomMethod "ghcide/reference/ready") (NotMess NotificationMessage{_params = fp}) -> do
5539-
A.Success fp' <- pure $ fromJSON fp
5540-
if equalFilePath fp' aPath then pure () else Nothing
5541-
_ -> Nothing
5539+
skipManyTill anyMessage $ isReferenceReady aPath
55425540
closeDoc adoc
55435541
pure adoc
55445542
bSource <- liftIO $ readFileUtf8 bPath
@@ -5566,11 +5564,7 @@ bootTests = testGroup "boot"
55665564
liftIO $ runInDir dir $ do
55675565
cDoc <- createDoc cPath "haskell" cSource
55685566
_ <- getHover cDoc $ Position 4 3
5569-
~() <- skipManyTill anyMessage $ satisfyMaybe $ \case
5570-
FromServerMess (SCustomMethod "ghcide/reference/ready") (NotMess NotificationMessage{_params = fp}) -> do
5571-
A.Success fp' <- pure $ fromJSON fp
5572-
if equalFilePath fp' cPath then pure () else Nothing
5573-
_ -> Nothing
5567+
skipManyTill anyMessage $ isReferenceReady cPath
55745568
closeDoc cDoc
55755569
cdoc <- createDoc cPath "haskell" cSource
55765570
locs <- getDefinitions cdoc (Position 7 4)
@@ -5980,11 +5974,7 @@ referenceTestSession name thisDoc docs' f = testSessionWithExtraFiles "reference
59805974
loop :: [FilePath] -> Session ()
59815975
loop [] = pure ()
59825976
loop docs = do
5983-
doc <- skipManyTill anyMessage $ satisfyMaybe $ \case
5984-
FromServerMess (SCustomMethod "ghcide/reference/ready") (NotMess NotificationMessage{_params = fp}) -> do
5985-
A.Success fp' <- pure $ fromJSON fp
5986-
find (fp' ==) docs
5987-
_ -> Nothing
5977+
doc <- skipManyTill anyMessage $ referenceReady (`elem` docs)
59885978
loop (delete doc docs)
59895979
loop docs
59905980
f dir

ghcide/test/src/Development/IDE/Test.hs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ module Development.IDE.Test
2929
, getStoredKeys
3030
, waitForCustomMessage
3131
, waitForGC
32-
,getBuildKeysBuilt,getBuildKeysVisited,getBuildKeysChanged,getBuildEdgesCount,configureCheckProject) where
32+
, getBuildKeysBuilt
33+
, getBuildKeysVisited
34+
, getBuildKeysChanged
35+
, getBuildEdgesCount
36+
, configureCheckProject
37+
, isReferenceReady
38+
, referenceReady) where
3339

3440
import Control.Applicative.Combinators
3541
import Control.Lens hiding (List)
@@ -254,3 +260,16 @@ configureCheckProject overrideCheckProject =
254260
sendNotification SWorkspaceDidChangeConfiguration
255261
(DidChangeConfigurationParams $ toJSON
256262
def{checkProject = overrideCheckProject})
263+
264+
-- | Pattern match a message from ghcide indicating that a file has been indexed
265+
isReferenceReady :: FilePath -> Session ()
266+
isReferenceReady p = void $ referenceReady (==p)
267+
268+
referenceReady :: (FilePath -> Bool) -> Session FilePath
269+
referenceReady pred = satisfyMaybe $ \case
270+
FromServerMess (SCustomMethod "ghcide/reference/ready") (NotMess NotificationMessage{_params})
271+
| A.Success fp <- A.fromJSON _params
272+
, pred fp
273+
-> Just fp
274+
_ -> Nothing
275+

0 commit comments

Comments
 (0)