From a6ff8ff8ed49f4f0f7cfe7012cf13040f3c2e9b9 Mon Sep 17 00:00:00 2001 From: Mitchell Rosen Date: Wed, 27 Apr 2022 16:58:50 -0400 Subject: [PATCH] add the codebase to LoopState --- .../Codebase/Editor/HandleInput/LoopState.hs | 15 +++++++++++---- .../src/Unison/Codebase/TranscriptParser.hs | 1 + unison-cli/src/Unison/CommandLine/Main.hs | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/unison-cli/src/Unison/Codebase/Editor/HandleInput/LoopState.hs b/unison-cli/src/Unison/Codebase/Editor/HandleInput/LoopState.hs index 67ce4d546..ac5d7f395 100644 --- a/unison-cli/src/Unison/Codebase/Editor/HandleInput/LoopState.hs +++ b/unison-cli/src/Unison/Codebase/Editor/HandleInput/LoopState.hs @@ -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 diff --git a/unison-cli/src/Unison/Codebase/TranscriptParser.hs b/unison-cli/src/Unison/Codebase/TranscriptParser.hs index 686f8fe60..754316d8b 100644 --- a/unison-cli/src/Unison/Codebase/TranscriptParser.hs +++ b/unison-cli/src/Unison/Codebase/TranscriptParser.hs @@ -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 diff --git a/unison-cli/src/Unison/CommandLine/Main.hs b/unison-cli/src/Unison/CommandLine/Main.hs index 6d1d89d3e..70d51fcb0 100644 --- a/unison-cli/src/Unison/CommandLine/Main.hs +++ b/unison-cli/src/Unison/CommandLine/Main.hs @@ -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