{-# LANGUAGE MultiParamTypeClasses #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Haskell.Debug.Adapter.State.DebugRun.Scopes where
import Control.Monad.IO.Class
import qualified System.Log.Logger as L
import qualified Text.Read as R
import Control.Monad.Except
import qualified Haskell.DAP as DAP
import Haskell.Debug.Adapter.Type
import Haskell.Debug.Adapter.Constant
import qualified Haskell.Debug.Adapter.Utility as U
import qualified Haskell.Debug.Adapter.GHCi as P
import qualified Haskell.Debug.Adapter.State.Utility as SU
instance StateActivityIF DebugRunStateData DAP.ScopesRequest where
action :: AppState DebugRunStateData
-> Request ScopesRequest -> AppContext (Maybe StateTransit)
action AppState DebugRunStateData
_ (ScopesRequest ScopesRequest
req) = do
IO () -> StateT AppStores (ExceptT ErrMsg IO) ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> StateT AppStores (ExceptT ErrMsg IO) ())
-> IO () -> StateT AppStores (ExceptT ErrMsg IO) ()
forall a b. (a -> b) -> a -> b
$ ErrMsg -> ErrMsg -> IO ()
L.debugM ErrMsg
_LOG_APP (ErrMsg -> IO ()) -> ErrMsg -> IO ()
forall a b. (a -> b) -> a -> b
$ ErrMsg
"DebugRunState ScopesRequest called. " ErrMsg -> ErrMsg -> ErrMsg
forall a. [a] -> [a] -> [a]
++ ScopesRequest -> ErrMsg
forall a. Show a => a -> ErrMsg
show ScopesRequest
req
ScopesRequest -> AppContext (Maybe StateTransit)
app ScopesRequest
req
app :: DAP.ScopesRequest -> AppContext (Maybe StateTransit)
app :: ScopesRequest -> AppContext (Maybe StateTransit)
app ScopesRequest
req = (AppContext (Maybe StateTransit)
-> (ErrMsg -> AppContext (Maybe StateTransit))
-> AppContext (Maybe StateTransit))
-> (ErrMsg -> AppContext (Maybe StateTransit))
-> AppContext (Maybe StateTransit)
-> AppContext (Maybe StateTransit)
forall a b c. (a -> b -> c) -> b -> a -> c
flip AppContext (Maybe StateTransit)
-> (ErrMsg -> AppContext (Maybe StateTransit))
-> AppContext (Maybe StateTransit)
forall e (m :: * -> *) a.
MonadError e m =>
m a -> (e -> m a) -> m a
catchError ErrMsg -> AppContext (Maybe StateTransit)
errHdl (AppContext (Maybe StateTransit)
-> AppContext (Maybe StateTransit))
-> AppContext (Maybe StateTransit)
-> AppContext (Maybe StateTransit)
forall a b. (a -> b) -> a -> b
$ do
let args :: ScopesRequestArguments
args = ScopesRequest -> ScopesRequestArguments
DAP.argumentsScopesRequest ScopesRequest
req
dap :: ErrMsg
dap = ErrMsg
":dap-scopes "
cmd :: ErrMsg
cmd = ErrMsg
dap ErrMsg -> ErrMsg -> ErrMsg
forall a. [a] -> [a] -> [a]
++ ScopesRequestArguments -> ErrMsg
forall a. Show a => a -> ErrMsg
U.showDAP ScopesRequestArguments
args
dbg :: ErrMsg
dbg = ErrMsg
dap ErrMsg -> ErrMsg -> ErrMsg
forall a. [a] -> [a] -> [a]
++ ScopesRequestArguments -> ErrMsg
forall a. Show a => a -> ErrMsg
show ScopesRequestArguments
args
ErrMsg -> StateT AppStores (ExceptT ErrMsg IO) ()
P.command ErrMsg
cmd
ErrMsg -> ErrMsg -> StateT AppStores (ExceptT ErrMsg IO) ()
U.debugEV ErrMsg
_LOG_APP ErrMsg
dbg
AppContext [ErrMsg]
P.expectPmpt AppContext [ErrMsg]
-> ([ErrMsg] -> StateT AppStores (ExceptT ErrMsg IO) ErrMsg)
-> StateT AppStores (ExceptT ErrMsg IO) ErrMsg
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [ErrMsg] -> StateT AppStores (ExceptT ErrMsg IO) ErrMsg
SU.takeDapResult StateT AppStores (ExceptT ErrMsg IO) ErrMsg
-> (ErrMsg -> StateT AppStores (ExceptT ErrMsg IO) ())
-> StateT AppStores (ExceptT ErrMsg IO) ()
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= ErrMsg -> StateT AppStores (ExceptT ErrMsg IO) ()
dapHdl
Maybe StateTransit -> AppContext (Maybe StateTransit)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe StateTransit
forall a. Maybe a
Nothing
where
dapHdl :: String -> AppContext ()
dapHdl :: ErrMsg -> StateT AppStores (ExceptT ErrMsg IO) ()
dapHdl ErrMsg
str = case ErrMsg -> Either ErrMsg (Either ErrMsg ScopesResponseBody)
forall a. Read a => ErrMsg -> Either ErrMsg a
R.readEither ErrMsg
str of
Left ErrMsg
err -> ErrMsg -> AppContext (Maybe StateTransit)
errHdl ErrMsg
err AppContext (Maybe StateTransit)
-> StateT AppStores (ExceptT ErrMsg IO) ()
-> StateT AppStores (ExceptT ErrMsg IO) ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> StateT AppStores (ExceptT ErrMsg IO) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Right (Left ErrMsg
err) -> ErrMsg -> AppContext (Maybe StateTransit)
errHdl ErrMsg
err AppContext (Maybe StateTransit)
-> StateT AppStores (ExceptT ErrMsg IO) ()
-> StateT AppStores (ExceptT ErrMsg IO) ()
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> () -> StateT AppStores (ExceptT ErrMsg IO) ()
forall (m :: * -> *) a. Monad m => a -> m a
return ()
Right (Right ScopesResponseBody
body) -> do
Int
resSeq <- AppContext Int
U.getIncreasedResponseSequence
let res :: ScopesResponse
res = ScopesResponse
DAP.defaultScopesResponse {
seqScopesResponse :: Int
DAP.seqScopesResponse = Int
resSeq
, request_seqScopesResponse :: Int
DAP.request_seqScopesResponse = ScopesRequest -> Int
DAP.seqScopesRequest ScopesRequest
req
, successScopesResponse :: Bool
DAP.successScopesResponse = Bool
True
, bodyScopesResponse :: ScopesResponseBody
DAP.bodyScopesResponse = ScopesResponseBody
body
}
Response -> StateT AppStores (ExceptT ErrMsg IO) ()
U.addResponse (Response -> StateT AppStores (ExceptT ErrMsg IO) ())
-> Response -> StateT AppStores (ExceptT ErrMsg IO) ()
forall a b. (a -> b) -> a -> b
$ ScopesResponse -> Response
ScopesResponse ScopesResponse
res
errHdl :: String -> AppContext (Maybe StateTransit)
errHdl :: ErrMsg -> AppContext (Maybe StateTransit)
errHdl ErrMsg
msg = do
IO () -> StateT AppStores (ExceptT ErrMsg IO) ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> StateT AppStores (ExceptT ErrMsg IO) ())
-> IO () -> StateT AppStores (ExceptT ErrMsg IO) ()
forall a b. (a -> b) -> a -> b
$ ErrMsg -> ErrMsg -> IO ()
L.errorM ErrMsg
_LOG_APP ErrMsg
msg
Int
resSeq <- AppContext Int
U.getIncreasedResponseSequence
let res :: ScopesResponse
res = ScopesResponse
DAP.defaultScopesResponse {
seqScopesResponse :: Int
DAP.seqScopesResponse = Int
resSeq
, request_seqScopesResponse :: Int
DAP.request_seqScopesResponse = ScopesRequest -> Int
DAP.seqScopesRequest ScopesRequest
req
, successScopesResponse :: Bool
DAP.successScopesResponse = Bool
False
, messageScopesResponse :: ErrMsg
DAP.messageScopesResponse = ErrMsg
msg
}
Response -> StateT AppStores (ExceptT ErrMsg IO) ()
U.addResponse (Response -> StateT AppStores (ExceptT ErrMsg IO) ())
-> Response -> StateT AppStores (ExceptT ErrMsg IO) ()
forall a b. (a -> b) -> a -> b
$ ScopesResponse -> Response
ScopesResponse ScopesResponse
res
Maybe StateTransit -> AppContext (Maybe StateTransit)
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe StateTransit
forall a. Maybe a
Nothing