mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-20 14:57:41 +03:00
add the codebase to LoopState
This commit is contained in:
parent
5707918fae
commit
a6ff8ff8ed
@ -13,6 +13,7 @@ import Data.List.NonEmpty (NonEmpty)
|
||||
import qualified Data.List.NonEmpty as Nel
|
||||
import qualified Network.HTTP.Client as HTTP
|
||||
import Unison.Auth.CredentialManager (CredentialManager)
|
||||
import Unison.Codebase (Codebase)
|
||||
import Unison.Codebase.Branch
|
||||
( Branch (..),
|
||||
)
|
||||
@ -28,18 +29,19 @@ import qualified Unison.Util.Free as Free
|
||||
|
||||
type F m i v = Free (Command m i v)
|
||||
|
||||
data Env = Env
|
||||
data Env m v = Env
|
||||
{ authHTTPClient :: HTTP.Manager,
|
||||
codebase :: Codebase m v Ann,
|
||||
credentialManager :: CredentialManager
|
||||
}
|
||||
|
||||
newtype Action m i v a = Action {unAction :: MaybeT (ReaderT Env (StateT (LoopState m v) (F m i v))) a}
|
||||
deriving newtype (Functor, Applicative, Alternative, Monad, MonadIO, MonadState (LoopState m v), MonadReader Env)
|
||||
newtype Action m i v a = Action {unAction :: MaybeT (ReaderT (Env m v) (StateT (LoopState m v) (F m i v))) a}
|
||||
deriving newtype (Functor, Applicative, Alternative, Monad, MonadIO, MonadState (LoopState m v), MonadReader (Env m v))
|
||||
-- We should likely remove this MonadFail instance since it's really hard to debug,
|
||||
-- but it's currently in use.
|
||||
deriving newtype (MonadFail)
|
||||
|
||||
runAction :: Env -> LoopState m v -> Action m i v a -> (F m i v (Maybe a, LoopState m v))
|
||||
runAction :: Env m v -> LoopState m v -> Action m i v a -> (F m i v (Maybe a, LoopState m v))
|
||||
runAction env state (Action m) =
|
||||
m
|
||||
& runMaybeT
|
||||
@ -116,3 +118,8 @@ respondNumbered output = do
|
||||
args <- eval $ NotifyNumbered output
|
||||
unless (null args) $
|
||||
numberedArgs .= toList args
|
||||
|
||||
-- | Get the codebase out of the environment.
|
||||
askCodebase :: Action m i v (Codebase m v Ann)
|
||||
askCodebase =
|
||||
asks codebase
|
||||
|
@ -378,6 +378,7 @@ run dir stanzas codebase runtime config ucmVersion = UnliftIO.try $ do
|
||||
let env =
|
||||
LoopState.Env
|
||||
{ LoopState.authHTTPClient = error "Error: No access to authorized requests from transcripts.",
|
||||
LoopState.codebase = codebase,
|
||||
LoopState.credentialManager = error "Error: No access to credentials from transcripts."
|
||||
}
|
||||
let free = LoopState.runAction env state $ HandleInput.loop
|
||||
|
@ -196,6 +196,7 @@ main dir welcome initialPath (config, cancelConfig) initialInputs runtime codeba
|
||||
let env =
|
||||
LoopState.Env
|
||||
{ LoopState.authHTTPClient = authorizedHTTPClient,
|
||||
LoopState.codebase = codebase,
|
||||
LoopState.credentialManager = credMan
|
||||
}
|
||||
let free = LoopState.runAction env state HandleInput.loop
|
||||
|
Loading…
Reference in New Issue
Block a user