Skip to content

Commit c3c06bc

Browse files
committed
actionFork
1 parent a0a174a commit c3c06bc

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

ghcide/src/Development/IDE/Core/Shake.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,7 @@ newSession extras@ShakeExtras{..} shakeDb acts = do
658658
-- Runs actions from the work queue sequentially
659659
pumpActionThread otSpan = do
660660
d <- liftIO $ atomically $ popQueue actionQueue
661-
void $ parallel [run otSpan d, pumpActionThread otSpan]
661+
actionFork (run otSpan d) $ \_ -> pumpActionThread otSpan
662662

663663
-- TODO figure out how to thread the otSpan into defineEarlyCutoff
664664
run _otSpan d = do

hls-graph/src/Development/IDE/Graph.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Development.IDE.Graph(
55
Rules,
66
Action, action,
77
Key(..),
8-
actionFinally, actionBracket, actionCatch,
8+
actionFinally, actionBracket, actionCatch, actionFork,
99
Shake.ShakeException(..),
1010
-- * Configuration
1111
ShakeOptions(shakeAllowRedefineRules, shakeThreads, shakeFiles, shakeExtra),

hls-graph/src/Development/IDE/Graph/Internal/Action.hs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,18 @@
22
{-# LANGUAGE ScopedTypeVariables #-}
33
{-# LANGUAGE TypeFamilies #-}
44

5-
module Development.IDE.Graph.Internal.Action where
5+
module Development.IDE.Graph.Internal.Action
6+
( actionFork
7+
, actionBracket
8+
, actionCatch
9+
, actionFinally
10+
, alwaysRerun
11+
, apply1
12+
, apply
13+
, parallel
14+
, reschedule
15+
, runActions
16+
) where
617

718
import Control.Concurrent.Async
819
import Control.Exception
@@ -42,16 +53,30 @@ parallel xs = do
4253
liftIO $ writeIORef (actionDeps a) $ (deps ++) <$> concatMapM id newDeps
4354
pure res
4455
where
45-
ignoreState a x = do
46-
ref <- newIORef Nothing
47-
runReaderT (fromAction x) a{actionDeps=ref}
48-
4956
usingState a x = do
5057
ref <- newIORef $ Just []
5158
res <- runReaderT (fromAction x) a{actionDeps=ref}
5259
deps <- readIORef ref
5360
pure (deps, res)
5461

62+
ignoreState :: SAction -> Action b -> IO b
63+
ignoreState a x = do
64+
ref <- newIORef Nothing
65+
runReaderT (fromAction x) a{actionDeps=ref}
66+
67+
actionFork :: Action a -> (Async a -> Action b) -> Action b
68+
actionFork act k = do
69+
a <- Action ask
70+
deps <- liftIO $ readIORef $ actionDeps a
71+
let db = actionDatabase a
72+
case deps of
73+
Nothing -> do
74+
-- if we are already in the rerun mode, nothing we do is going to impact our state
75+
[res] <- liftIO $ withAsync (ignoreState a act) $ \as -> runActions db [k as]
76+
return res
77+
_ ->
78+
error "please help me"
79+
5580
isAsyncException :: SomeException -> Bool
5681
isAsyncException e
5782
| Just (_ :: AsyncCancelled) <- fromException e = True

0 commit comments

Comments
 (0)