add the codebase to LoopState

This commit is contained in:
Mitchell Rosen 2022-04-27 16:58:50 -04:00
parent 5707918fae
commit a6ff8ff8ed
3 changed files with 13 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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