1
+ {-# LANGUAGE GADTs #-}
1
2
{-# LANGUAGE LambdaCase #-}
2
3
module Test.Hls
3
4
( module Test.Tasty.HUnit ,
@@ -14,6 +15,7 @@ module Test.Hls
14
15
runSessionWithServer ,
15
16
runSessionWithServerFormatter ,
16
17
runSessionWithServer' ,
18
+ waitForProgressDone ,
17
19
PluginDescriptor ,
18
20
IdeState ,
19
21
)
@@ -23,17 +25,18 @@ import Control.Applicative.Combinators
23
25
import Control.Concurrent.Async (async , cancel , wait )
24
26
import Control.Concurrent.Extra
25
27
import Control.Exception.Base
28
+ import Control.Monad (unless )
26
29
import Control.Monad.IO.Class
27
30
import Data.ByteString.Lazy (ByteString )
28
31
import Data.Default (def )
29
32
import qualified Data.Text as T
30
33
import Development.IDE (IdeState , hDuplicateTo' ,
31
34
noLogging )
35
+ import Development.IDE.Graph (ShakeOptions (shakeThreads ))
32
36
import Development.IDE.Main
33
37
import qualified Development.IDE.Main as Ghcide
34
38
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
35
39
import Development.IDE.Types.Options
36
- import Development.IDE.Graph (ShakeOptions (shakeThreads ))
37
40
import GHC.IO.Handle
38
41
import Ide.Plugin.Config (Config , formattingProvider )
39
42
import Ide.PluginUtils (pluginDescToIdePlugins )
@@ -134,3 +137,15 @@ runSessionWithServer' plugin conf sconf caps root s = withLock lock $ keepCurren
134
137
(t, _) <- duration $ cancel server
135
138
putStrLn $ " Finishing canceling (took " <> showDuration t <> " s)"
136
139
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
0 commit comments