Skip to content

Commit 4d0cc73

Browse files
committed
attempt to fix tactics test suite in Windows
1 parent e2c86f7 commit 4d0cc73

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ module Test.Hls
2222
waitForAllProgressDone,
2323
PluginDescriptor,
2424
IdeState,
25-
)
25+
waitForBuildQueue
26+
)
2627
where
2728

2829
import Control.Applicative.Combinators
@@ -31,6 +32,7 @@ import Control.Concurrent.Extra
3132
import Control.Exception.Base
3233
import Control.Monad (unless)
3334
import Control.Monad.IO.Class
35+
import Data.Aeson (Value (Null), toJSON)
3436
import Data.ByteString.Lazy (ByteString)
3537
import Data.Default (def)
3638
import qualified Data.Text as T
@@ -42,6 +44,7 @@ import Development.IDE.Graph (ShakeOptions (shakeThreads))
4244
import Development.IDE.Main
4345
import qualified Development.IDE.Main as Ghcide
4446
import qualified Development.IDE.Plugin.HLS.GhcIde as Ghcide
47+
import Development.IDE.Plugin.Test (TestRequest (WaitForShakeQueue))
4548
import Development.IDE.Types.Options
4649
import GHC.IO.Handle
4750
import Ide.Plugin.Config (Config, formattingProvider)
@@ -208,3 +211,14 @@ waitForAllProgressDone = loop
208211
_ -> Nothing
209212
done <- null <$> getIncompleteProgressSessions
210213
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

plugins/hls-tactics-plugin/test/Utils.hs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module Utils where
1010
import Control.DeepSeq (deepseq)
1111
import qualified Control.Exception as E
1212
import Control.Lens hiding (List, failing, (<.>), (.=))
13-
import Control.Monad (unless)
13+
import Control.Monad (unless, void)
1414
import Control.Monad.IO.Class
1515
import Data.Aeson
1616
import Data.Foldable
@@ -108,8 +108,11 @@ mkGoldenTest eq tc occ line col input =
108108
resetGlobalHoleRef
109109
runSessionForTactics $ do
110110
doc <- openDoc (input <.> "hs") "haskell"
111+
-- wait for diagnostics to start coming
111112
_ <- waitForDiagnostics
112-
waitForAllProgressDone
113+
-- wait for the entire build to finish, so that Tactics code actions that
114+
-- use stale data will get uptodate stuff
115+
void waitForBuildQueue
113116
actions <- getCodeActions doc $ pointRange line col
114117
case find ((== Just (tacticTitle tc occ)) . codeActionTitle) actions of
115118
Just (InR CodeAction {_command = Just c}) -> do
@@ -122,7 +125,7 @@ mkGoldenTest eq tc occ line col input =
122125
T.writeFile expected_name edited
123126
expected <- liftIO $ T.readFile expected_name
124127
liftIO $ edited `eq` expected
125-
other -> error $ show other
128+
_ -> error $ show actions
126129

127130

128131
mkCodeLensTest

0 commit comments

Comments
 (0)