@@ -22,7 +22,8 @@ module Test.Hls
22
22
waitForAllProgressDone ,
23
23
PluginDescriptor ,
24
24
IdeState ,
25
- )
25
+ waitForBuildQueue
26
+ )
26
27
where
27
28
28
29
import Control.Applicative.Combinators
@@ -31,6 +32,7 @@ import Control.Concurrent.Extra
31
32
import Control.Exception.Base
32
33
import Control.Monad (unless )
33
34
import Control.Monad.IO.Class
35
+ import Data.Aeson (Value (Null ), toJSON )
34
36
import Data.ByteString.Lazy (ByteString )
35
37
import Data.Default (def )
36
38
import qualified Data.Text as T
@@ -42,6 +44,7 @@ import Development.IDE.Graph (ShakeOptions (shakeThreads))
42
44
import Development.IDE.Main
43
45
import qualified Development.IDE.Main as Ghcide
44
46
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
47
+ import Development.IDE.Plugin.Test (TestRequest (WaitForShakeQueue ))
45
48
import Development.IDE.Types.Options
46
49
import GHC.IO.Handle
47
50
import Ide.Plugin.Config (Config , formattingProvider )
@@ -208,3 +211,14 @@ waitForAllProgressDone = loop
208
211
_ -> Nothing
209
212
done <- null <$> getIncompleteProgressSessions
210
213
unless done loop
214
+
215
+ -- | Wait for the build queue to be empty
216
+ waitForBuildQueue :: Session Seconds
217
+ waitForBuildQueue = do
218
+ let m = SCustomMethod " test"
219
+ waitId <- sendRequest m (toJSON WaitForShakeQueue )
220
+ (td, resp) <- duration $ skipManyTill anyMessage $ responseForId m waitId
221
+ case resp of
222
+ ResponseMessage {_result= Right Null } -> return td
223
+ -- assume a ghcide binary lacking the WaitForShakeQueue method
224
+ _ -> return 0
0 commit comments