{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeFamilies               #-}

module Development.IDE.Graph.Internal.Action where

import           Control.Exception
import           Control.Monad.Fail
import           Control.Monad.IO.Class
import qualified Development.Shake         as Shake
import           Development.Shake.Classes
import qualified Development.Shake.Rule    as Shake

newtype Action a = Action {Action a -> Action a
fromAction :: Shake.Action a}
    deriving (Applicative Action
a -> Action a
Applicative Action
-> (forall a b. Action a -> (a -> Action b) -> Action b)
-> (forall a b. Action a -> Action b -> Action b)
-> (forall a. a -> Action a)
-> Monad Action
Action a -> (a -> Action b) -> Action b
Action a -> Action b -> Action b
forall a. a -> Action a
forall a b. Action a -> Action b -> Action b
forall a b. Action a -> (a -> Action b) -> Action b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> Action a
$creturn :: forall a. a -> Action a
>> :: Action a -> Action b -> Action b
$c>> :: forall a b. Action a -> Action b -> Action b
>>= :: Action a -> (a -> Action b) -> Action b
$c>>= :: forall a b. Action a -> (a -> Action b) -> Action b
$cp1Monad :: Applicative Action
Monad, Functor Action
a -> Action a
Functor Action
-> (forall a. a -> Action a)
-> (forall a b. Action (a -> b) -> Action a -> Action b)
-> (forall a b c.
    (a -> b -> c) -> Action a -> Action b -> Action c)
-> (forall a b. Action a -> Action b -> Action b)
-> (forall a b. Action a -> Action b -> Action a)
-> Applicative Action
Action a -> Action b -> Action b
Action a -> Action b -> Action a
Action (a -> b) -> Action a -> Action b
(a -> b -> c) -> Action a -> Action b -> Action c
forall a. a -> Action a
forall a b. Action a -> Action b -> Action a
forall a b. Action a -> Action b -> Action b
forall a b. Action (a -> b) -> Action a -> Action b
forall a b c. (a -> b -> c) -> Action a -> Action b -> Action c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
<* :: Action a -> Action b -> Action a
$c<* :: forall a b. Action a -> Action b -> Action a
*> :: Action a -> Action b -> Action b
$c*> :: forall a b. Action a -> Action b -> Action b
liftA2 :: (a -> b -> c) -> Action a -> Action b -> Action c
$cliftA2 :: forall a b c. (a -> b -> c) -> Action a -> Action b -> Action c
<*> :: Action (a -> b) -> Action a -> Action b
$c<*> :: forall a b. Action (a -> b) -> Action a -> Action b
pure :: a -> Action a
$cpure :: forall a. a -> Action a
$cp1Applicative :: Functor Action
Applicative, a -> Action b -> Action a
(a -> b) -> Action a -> Action b
(forall a b. (a -> b) -> Action a -> Action b)
-> (forall a b. a -> Action b -> Action a) -> Functor Action
forall a b. a -> Action b -> Action a
forall a b. (a -> b) -> Action a -> Action b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> Action b -> Action a
$c<$ :: forall a b. a -> Action b -> Action a
fmap :: (a -> b) -> Action a -> Action b
$cfmap :: forall a b. (a -> b) -> Action a -> Action b
Functor, Monad Action
Monad Action -> (forall a. IO a -> Action a) -> MonadIO Action
IO a -> Action a
forall a. IO a -> Action a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
liftIO :: IO a -> Action a
$cliftIO :: forall a. IO a -> Action a
$cp1MonadIO :: Monad Action
MonadIO, Monad Action
Monad Action -> (forall a. String -> Action a) -> MonadFail Action
String -> Action a
forall a. String -> Action a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
fail :: String -> Action a
$cfail :: forall a. String -> Action a
$cp1MonadFail :: Monad Action
MonadFail)

alwaysRerun :: Action ()
alwaysRerun :: Action ()
alwaysRerun = Action () -> Action ()
forall a. Action a -> Action a
Action Action ()
Shake.alwaysRerun

reschedule :: Double -> Action ()
reschedule :: Double -> Action ()
reschedule = Action () -> Action ()
forall a. Action a -> Action a
Action (Action () -> Action ())
-> (Double -> Action ()) -> Double -> Action ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Double -> Action ()
Shake.reschedule

parallel :: [Action a] -> Action [a]
parallel :: [Action a] -> Action [a]
parallel = Action [a] -> Action [a]
forall a. Action a -> Action a
Action (Action [a] -> Action [a])
-> ([Action a] -> Action [a]) -> [Action a] -> Action [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Action a] -> Action [a]
forall a. [Action a] -> Action [a]
Shake.parallel ([Action a] -> Action [a])
-> ([Action a] -> [Action a]) -> [Action a] -> Action [a]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Action a -> Action a) -> [Action a] -> [Action a]
forall a b. (a -> b) -> [a] -> [b]
map Action a -> Action a
forall a. Action a -> Action a
fromAction

actionCatch :: Exception e => Action a -> (e -> Action a) -> Action a
actionCatch :: Action a -> (e -> Action a) -> Action a
actionCatch Action a
a e -> Action a
b = Action a -> Action a
forall a. Action a -> Action a
Action (Action a -> Action a) -> Action a -> Action a
forall a b. (a -> b) -> a -> b
$ Action a -> (e -> Action a) -> Action a
forall e a. Exception e => Action a -> (e -> Action a) -> Action a
Shake.actionCatch (Action a -> Action a
forall a. Action a -> Action a
fromAction Action a
a) (Action a -> Action a
forall a. Action a -> Action a
fromAction (Action a -> Action a) -> (e -> Action a) -> e -> Action a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. e -> Action a
b)

actionBracket :: IO a -> (a -> IO b) -> (a -> Action c) -> Action c
actionBracket :: IO a -> (a -> IO b) -> (a -> Action c) -> Action c
actionBracket IO a
a a -> IO b
b a -> Action c
c = Action c -> Action c
forall a. Action a -> Action a
Action (Action c -> Action c) -> Action c -> Action c
forall a b. (a -> b) -> a -> b
$ IO a -> (a -> IO b) -> (a -> Action c) -> Action c
forall a b c. IO a -> (a -> IO b) -> (a -> Action c) -> Action c
Shake.actionBracket IO a
a a -> IO b
b (Action c -> Action c
forall a. Action a -> Action a
fromAction (Action c -> Action c) -> (a -> Action c) -> a -> Action c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> Action c
c)

actionFinally :: Action a -> IO b -> Action a
actionFinally :: Action a -> IO b -> Action a
actionFinally Action a
a IO b
b = Action a -> Action a
forall a. Action a -> Action a
Action (Action a -> Action a) -> Action a -> Action a
forall a b. (a -> b) -> a -> b
$ Action a -> IO b -> Action a
forall a b. Action a -> IO b -> Action a
Shake.actionFinally (Action a -> Action a
forall a. Action a -> Action a
fromAction Action a
a) IO b
b

apply1 :: (Shake.RuleResult key ~ value, Shake.ShakeValue key, Typeable value) => key -> Action value
apply1 :: key -> Action value
apply1 = Action value -> Action value
forall a. Action a -> Action a
Action (Action value -> Action value)
-> (key -> Action value) -> key -> Action value
forall b c a. (b -> c) -> (a -> b) -> a -> c
. key -> Action value
forall key value.
(Partial, RuleResult key ~ value, ShakeValue key,
 Typeable value) =>
key -> Action value
Shake.apply1

apply :: (Shake.RuleResult key ~ value, Shake.ShakeValue key, Typeable value) => [key] -> Action [value]
apply :: [key] -> Action [value]
apply = Action [value] -> Action [value]
forall a. Action a -> Action a
Action (Action [value] -> Action [value])
-> ([key] -> Action [value]) -> [key] -> Action [value]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [key] -> Action [value]
forall key value.
(Partial, RuleResult key ~ value, ShakeValue key,
 Typeable value) =>
[key] -> Action [value]
Shake.apply