dap-0.3.0.0: A debug adaptor protocol library
Copyright(C) 2023 David M. Johnson
LicenseBSD3-style (see the file LICENSE)
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

DAP.Adaptor

Description

 
Synopsis

Message Construction

setBody :: ToJSON value => value -> Adaptor app request () Source #

setField :: ToJSON value => Key -> value -> Adaptor app request () Source #

Response

sendErrorResponse :: ErrorMessage -> Maybe Message -> Adaptor app Request () Source #

Sends unsuccessful response Only used internally within the Server module

Events

sendSuccesfulEvent :: EventType -> Adaptor app request () -> Adaptor app request () Source #

Sends successful event

Reverse Requests

sendReverseRequest :: ReverseCommand -> Adaptor app Request () Source #

Write reverse request to Handle

Server

withConnectionLock :: IO () -> Adaptor app request () Source #

Request Arguments

getArguments :: (Show value, FromJSON value) => Adaptor app Request value Source #

Attempt to parse arguments from the Request

getReverseRequestResponseBody :: (Show value, FromJSON value) => ReverseRequestResponse -> Adaptor app r value Source #

Attempt to parse arguments from a ReverseRequestResponse (not in env)

Debug Session

registerNewDebugSession Source #

Arguments

:: SessionId 
-> app 
-> [(Adaptor app () () -> IO ()) -> IO ()]

Actions to run debugger (operates in a forked thread that gets killed when disconnect is set) Long running operation, meant to be used as a sink for the debugger to emit events and for the adaptor to forward to the editor This function should be in a forever loop waiting on the read end of a debugger channel.

This event handler thread also takes an argument that allows any child thread to execute events on behalf of the DAP server (in 'Adaptor app ()'). This function should always be used when sending events to the editor from the debugger (or from any forked thread).

registerNewDebugSession sessionId appState $ loadDebugger : [\withAdaptor ->
  forever $ getDebuggerOutput >>= \output -> do
    withAdaptor $ sendOutputEvent defaultOutputEvent { outputEventOutput = output }
  ]
-> Adaptor app request () 

updateDebugSession :: (app -> app) -> Adaptor app request () Source #

destroyDebugSession :: Adaptor app request () Source #

Whenever a debug Session ends (cleanly or otherwise) this function will remove the local debugger communication state from the global state

Error handling

sendError :: ErrorMessage -> Maybe Message -> Adaptor app request a Source #

Raises an error Meant abort the current reqeust / response cycle, prematurely sending an ErrorResponse https://microsoft.github.io/debug-adapter-protocol/specification#Base_Protocol_ErrorResponse

Logging

logWarn :: Text -> Adaptor app request () Source #

logError :: Text -> Adaptor app request () Source #

logInfo :: Text -> Adaptor app request () Source #

logger :: LogAction IO DAPLog -> Level -> SockAddr -> Maybe DebugStatus -> Text -> IO () Source #

Meant for external consumption

debugMessage :: DebugStatus -> ByteString -> Adaptor app request () Source #

Meant for internal consumption, used to signify a message has been SENT from the server

Internal use

send :: Adaptor app Request () -> Adaptor app Request () Source #

Function for constructing a payload and writing bytes to a socket. This function takes care of incrementing sequence numbers and setting fields automatically that are required for response messages. i.e. "request_seq" and "command". We also have to be sure to reset the message payload

sendRaw :: ToJSON value => value -> Adaptor app request () Source #

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.

Internal function used to execute actions on behalf of the DAP server

runAdaptorWith :: AdaptorLocal app request -> AdaptorState -> Adaptor app request () -> IO () Source #

Evaluates Adaptor action by using and updating the state in the MVar

runAdaptor :: AdaptorLocal app Request -> AdaptorState -> Adaptor app Request () -> IO () Source #

Utility for evaluating a monad transformer stack