@@ -13,6 +13,7 @@ module Development.IDE.State.Service(
1313 getServiceEnv,
1414 IdeState, initialise, shutdown,
1515 runAction, runActions,
16+ runActionSync, runActionsSync,
1617 setFilesOfInterest, modifyFilesOfInterest,
1718 writeProfile,
1819 getDiagnostics, unsafeClearDiagnostics,
@@ -100,14 +101,32 @@ setProfiling opts shakeOpts =
100101shutdown :: IdeState -> IO ()
101102shutdown = shakeShut
102103
103−-- | Run a single action using the supplied service.
104+-- | Run a single action using the supplied service. See `runActions`
105+-- for more details.
104106runAction :: IdeState -> Action a -> IO a
105107runAction service action = head <$> runActions service [action]
106108
107109-- | Run a list of actions in parallel using the supplied service.
110+-- This will return as soon as the results of the actions are
111+-- available. There might still be other rules running at this point,
112+-- e.g., the ofInterestRule.
108113runActions :: IdeState -> [Action a] -> IO [a]
109−runActions x = join . shakeRun x
110−
114+runActions x acts = do
115+ var <- newBarrier
116+ _ <- shakeRun x acts (signalBarrier var)
117+ waitBarrier var
118+
119+-- | This is a synchronous variant of `runAction`. See
120+-- `runActionsSync` of more details.
121+runActionSync :: IdeState -> Action a -> IO a
122+runActionSync s a = head <$> runActionsSync s [a]
123+
124+-- | `runActionsSync` is similar to `runActions` but it will
125+-- wait for all rules (so in particular the `ofInterestRule`) to
126+-- finish running. This is mainly useful in tests, where you want
127+-- to wait for all rules to fire so you can check diagnostics.
128+runActionsSync :: IdeState -> [Action a] -> IO [a]
129+runActionsSync s acts = join $ shakeRun s acts (const $ pure ())
111130
112131-- | Set the files-of-interest which will be built and kept-up-to-date.
113132setFilesOfInterest :: IdeState -> Set NormalizedFilePath -> IO ()
@@ -118,7 +137,7 @@ modifyFilesOfInterest state f = do
118137 Env{..} <- getIdeGlobalState state
119138 files <- modifyVar envOfInterestVar $ pure . dupe . f
120139 logDebug state $ "Set files of interest to: " <> T.pack (show $ Set.toList files)
121− void $ shakeRun state []
140+ void $ shakeRun state [] (const $ pure ())
122141
123142getServiceEnv :: Action Env
124143getServiceEnv = getIdeGlobalAction