Skip to content

Commit 42c9bec

Browse files
committed
Fix splice plugin tests
1 parent e3f0a71 commit 42c9bec

File tree

2 files changed

+19
-3
lines changed
  • hls-test-utils/src/Test
  • plugins/hls-splice-plugin/test

2 files changed

+19
-3
lines changed

hls-test-utils/src/Test/Hls.hs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE GADTs #-}
12
{-# LANGUAGE LambdaCase #-}
23
module Test.Hls
34
( module Test.Tasty.HUnit,
@@ -14,6 +15,7 @@ module Test.Hls
1415
runSessionWithServer,
1516
runSessionWithServerFormatter,
1617
runSessionWithServer',
18+
waitForProgressDone,
1719
PluginDescriptor,
1820
IdeState,
1921
)
@@ -23,17 +25,18 @@ import Control.Applicative.Combinators
2325
import Control.Concurrent.Async (async, cancel, wait)
2426
import Control.Concurrent.Extra
2527
import Control.Exception.Base
28+
import Control.Monad (unless)
2629
import Control.Monad.IO.Class
2730
import Data.ByteString.Lazy (ByteString)
2831
import Data.Default (def)
2932
import qualified Data.Text as T
3033
import Development.IDE (IdeState, hDuplicateTo',
3134
noLogging)
35+
import Development.IDE.Graph (ShakeOptions (shakeThreads))
3236
import Development.IDE.Main
3337
import qualified Development.IDE.Main as Ghcide
3438
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
3539
import Development.IDE.Types.Options
36-
import Development.IDE.Graph (ShakeOptions (shakeThreads))
3740
import GHC.IO.Handle
3841
import Ide.Plugin.Config (Config, formattingProvider)
3942
import Ide.PluginUtils (pluginDescToIdePlugins)
@@ -134,3 +137,15 @@ runSessionWithServer' plugin conf sconf caps root s = withLock lock $ keepCurren
134137
(t, _) <- duration $ cancel server
135138
putStrLn $ "Finishing canceling (took " <> showDuration t <> "s)"
136139
pure x
140+
141+
-- | Wait for all progress to be done
142+
-- Needs at least one progress done notification to return
143+
waitForProgressDone :: Session ()
144+
waitForProgressDone = loop
145+
where
146+
loop = do
147+
~() <- skipManyTill anyMessage $ satisfyMaybe $ \case
148+
FromServerMess SProgress (NotificationMessage _ _ (ProgressParams _ (End _))) -> Just ()
149+
_ -> Nothing
150+
done <- null <$> getIncompleteProgressSessions
151+
unless done loop

plugins/hls-splice-plugin/test/Main.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ goldenTestWithEdit input tc line col =
9999
{ _start = Position 0 0
100100
, _end = Position (length lns + 1) 1
101101
}
102-
liftIO $ sleep 3
102+
waitForProgressDone -- cradle
103+
waitForProgressDone
103104
alt <- liftIO $ T.readFile (input <.> "error")
104105
void $ applyEdit doc $ TextEdit theRange alt
105106
changeDoc doc [TextDocumentContentChangeEvent (Just theRange) Nothing alt]
@@ -131,5 +132,5 @@ pointRange
131132

132133
-- | Get the title of a code action.
133134
codeActionTitle :: (Command |? CodeAction) -> Maybe Text
134-
codeActionTitle InL{} = Nothing
135+
codeActionTitle InL{} = Nothing
135136
codeActionTitle (InR(CodeAction title _ _ _ _ _ _ _)) = Just title

0 commit comments

Comments
 (0)