@@ -37,7 +37,7 @@ import Control.Exception ( Exception
3737 , toException
3838 , throwIO )
3939import Control.Monad ( void )
40- import Data.Aeson ( decodeStrict , eitherDecode , Value , FromJSON )
40+ import Data.Aeson ( decodeStrict , eitherDecode , Value , FromJSON , Result ( .. ), fromJSON )
4141import Data.Aeson.Encode.Pretty ( encodePretty )
4242import Data.ByteString ( ByteString )
4343import 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 ()
143144serviceClient 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.
0 commit comments