1+ {-# LANGUAGE GADTs #-}
12{-# LANGUAGE LambdaCase #-}
23module 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
2325import Control.Concurrent.Async (async , cancel , wait )
2426import Control.Concurrent.Extra
2527import Control.Exception.Base
28+ import Control.Monad (unless )
2629import Control.Monad.IO.Class
2730import Data.ByteString.Lazy (ByteString )
2831import Data.Default (def )
2932import qualified Data.Text as T
3033import Development.IDE (IdeState , hDuplicateTo' ,
3134 noLogging )
35+ import Development.IDE.Graph (ShakeOptions (shakeThreads ))
3236import Development.IDE.Main
3337import qualified Development.IDE.Main as Ghcide
3438import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
3539import Development.IDE.Types.Options
36- import Development.IDE.Graph (ShakeOptions (shakeThreads ))
3740import GHC.IO.Handle
3841import Ide.Plugin.Config (Config , formattingProvider )
3942import 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
0 commit comments