Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/DAP/Adaptor.hs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ module DAP.Adaptor
, runAdaptorRequest
, withRequest
, getHandle
, getClientCapabilities
) where
----------------------------------------------------------------------------
import Control.Concurrent.Lifted ( fork, killThread )
Expand Down Expand Up @@ -230,6 +231,9 @@ getAppStore = asks appStore
getCommand :: Adaptor app Request Command
getCommand = command <$> asks request
----------------------------------------------------------------------------
getClientCapabilities :: Adaptor app request (Maybe InitializeRequestArguments)
getClientCapabilities = asks clientCapabilities
-------------------------------------------------------------------------------
-- | 'sendRaw' (internal use only)
-- Sends a raw JSON payload to the editor. No "seq", "type" or "command" fields are set.
-- The message is still encoded with the ProtocolMessage Header, byte count, and CRLF.
Expand Down
16 changes: 11 additions & 5 deletions src/DAP/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import Control.Exception ( Exception
, toException
, throwIO )
import Control.Monad ( void )
import Data.Aeson ( decodeStrict, eitherDecode, Value, FromJSON )
import Data.Aeson ( decodeStrict, eitherDecode, Value, FromJSON, Result (..), fromJSON )
import Data.Aeson.Encode.Pretty ( encodePretty )
import Data.ByteString ( ByteString )
import Data.Char ( isDigit )
Expand Down Expand Up @@ -124,6 +124,7 @@ initAdaptorState logAction handle address appStore serverConfig = do
handleLock <- newMVar ()
sessionId <- newIORef Nothing
let request = ()
let clientCapabilities = Nothing
pure AdaptorLocal
{ ..
}
Expand All @@ -142,16 +143,21 @@ serviceClient
-> IO ()
serviceClient communicate ackResp lcl = do
rrr_or_nextRequest <- runAdaptorPoly lcl st getRequest
case rrr_or_nextRequest of
lcl' <- case rrr_or_nextRequest of
Right nextRequest -> do
let lcl' = lcl{ request = nextRequest }
let lcl' = lcl{ request = nextRequest, clientCapabilities = clientCaps nextRequest }
runAdaptorRequest lcl' st $
communicate (command nextRequest)
Left rrr ->
pure (void lcl')
Left rrr -> do
runAdaptorPoly lcl st $ ackResp rrr
serviceClient communicate ackResp lcl
pure lcl
serviceClient communicate ackResp lcl'
where
st = AdaptorState MessageTypeResponse []
clientCaps Request{command = CommandInitialize, args = Just (fromJSON -> Success v) }
= Just v
clientCaps _ = clientCapabilities lcl
----------------------------------------------------------------------------
-- | Handle exceptions from client threads, parse and log accordingly.
-- Detects if client failed with `TerminateServer` and kills the server accordingly by sending an exception to the main thread.
Expand Down
5 changes: 5 additions & 0 deletions src/DAP/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE LambdaCase #-}
----------------------------------------------------------------------------
module DAP.Types
Expand Down Expand Up @@ -299,9 +300,13 @@ data AdaptorLocal app request = AdaptorLocal
, logAction :: LogAction IO DAPLog
-- ^ Where to send log output
--
, clientCapabilities :: Maybe InitializeRequestArguments
-- ^ Taken from Initialize Command Requests

, request :: request
-- ^ Connection Request information, if we are responding to a request.
}
deriving Functor

----------------------------------------------------------------------------
type SessionId = Text
Expand Down
Loading