Skip to content

Commit 2267060

Browse files
authored
Merge pull request #32 from Saizan/client-caps
keep track of clientCapabilities
2 parents 71164a0 + 3b00170 commit 2267060

3 files changed

Lines changed: 20 additions & 5 deletions

File tree

src/DAP/Adaptor.hs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ module DAP.Adaptor
5959
, runAdaptorRequest
6060
, withRequest
6161
, getHandle
62+
, getClientCapabilities
6263
) where
6364
----------------------------------------------------------------------------
6465
import Control.Concurrent.Lifted ( fork, killThread )
@@ -230,6 +231,9 @@ getAppStore = asks appStore
230231
getCommand :: Adaptor app Request Command
231232
getCommand = command <$> asks request
232233
----------------------------------------------------------------------------
234+
getClientCapabilities :: Adaptor app request (Maybe InitializeRequestArguments)
235+
getClientCapabilities = asks clientCapabilities
236+
-------------------------------------------------------------------------------
233237
-- | 'sendRaw' (internal use only)
234238
-- Sends a raw JSON payload to the editor. No "seq", "type" or "command" fields are set.
235239
-- The message is still encoded with the ProtocolMessage Header, byte count, and CRLF.

src/DAP/Server.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import Control.Exception ( Exception
3737
, toException
3838
, throwIO )
3939
import Control.Monad ( void )
40-
import Data.Aeson ( decodeStrict, eitherDecode, Value, FromJSON )
40+
import Data.Aeson ( decodeStrict, eitherDecode, Value, FromJSON, Result (..), fromJSON )
4141
import Data.Aeson.Encode.Pretty ( encodePretty )
4242
import Data.ByteString ( ByteString )
4343
import Data.Char ( isDigit )
@@ -124,6 +124,7 @@ initAdaptorState logAction handle address appStore serverConfig = do
124124
handleLock <- newMVar ()
125125
sessionId <- newIORef Nothing
126126
let request = ()
127+
let clientCapabilities = Nothing
127128
pure AdaptorLocal
128129
{ ..
129130
}
@@ -142,16 +143,21 @@ serviceClient
142143
-> IO ()
143144
serviceClient communicate ackResp lcl = do
144145
rrr_or_nextRequest <- runAdaptorPoly lcl st getRequest
145-
case rrr_or_nextRequest of
146+
lcl' <- case rrr_or_nextRequest of
146147
Right nextRequest -> do
147-
let lcl' = lcl{ request = nextRequest }
148+
let lcl' = lcl{ request = nextRequest, clientCapabilities = clientCaps nextRequest }
148149
runAdaptorRequest lcl' st $
149150
communicate (command nextRequest)
150-
Left rrr ->
151+
pure (void lcl')
152+
Left rrr -> do
151153
runAdaptorPoly lcl st $ ackResp rrr
152-
serviceClient communicate ackResp lcl
154+
pure lcl
155+
serviceClient communicate ackResp lcl'
153156
where
154157
st = AdaptorState MessageTypeResponse []
158+
clientCaps Request{command = CommandInitialize, args = Just (fromJSON -> Success v) }
159+
= Just v
160+
clientCaps _ = clientCapabilities lcl
155161
----------------------------------------------------------------------------
156162
-- | Handle exceptions from client threads, parse and log accordingly.
157163
-- Detects if client failed with `TerminateServer` and kills the server accordingly by sending an exception to the main thread.

src/DAP/Types.hs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
{-# LANGUAGE RecordWildCards #-}
1515
{-# LANGUAGE DeriveAnyClass #-}
1616
{-# LANGUAGE DeriveGeneric #-}
17+
{-# LANGUAGE DeriveFunctor #-}
1718
{-# LANGUAGE LambdaCase #-}
1819
----------------------------------------------------------------------------
1920
module DAP.Types
@@ -299,9 +300,13 @@ data AdaptorLocal app request = AdaptorLocal
299300
, logAction :: LogAction IO DAPLog
300301
-- ^ Where to send log output
301302
--
303+
, clientCapabilities :: Maybe InitializeRequestArguments
304+
-- ^ Taken from Initialize Command Requests
305+
302306
, request :: request
303307
-- ^ Connection Request information, if we are responding to a request.
304308
}
309+
deriving Functor
305310

306311
----------------------------------------------------------------------------
307312
type SessionId = Text

0 commit comments

Comments
 (0)