-----------------------------------------------------------------------------
-- |
-- Module      :  DAP.Event
-- Copyright   :  (C) 2023 David M. Johnson
-- License     :  BSD3-style (see the file LICENSE)
-- Stability   :  experimental
-- Portability :  non-portable
----------------------------------------------------------------------------
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DerivingStrategies         #-}
{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE RecordWildCards            #-}
{-# LANGUAGE DeriveAnyClass             #-}
{-# LANGUAGE DeriveGeneric              #-}
----------------------------------------------------------------------------
module DAP.Event
  ( -- * Event message API
    sendBreakpointEvent
  , sendCapabilitiesEvent
  , sendContinuedEvent
  , sendExitedEvent
  , sendInitializedEvent
  , sendInvalidatedEvent
  , sendLoadedSourceEvent
  , sendMemoryEvent
  , sendModuleEvent
  , sendOutputEvent
  , sendProcessEvent
  , sendProgressEndEvent
  , sendProgressStartEvent
  , sendProgressUpdateEvent
  , sendStoppedEvent
  , sendTerminatedEvent
  , sendThreadEvent
  -- * Defaults
  , defaultContinuedEvent
  , defaultExitedEvent
  , defaultInvalidatedEvent
  , defaultMemoryEvent
  , defaultOutputEvent
  , defaultProcessEvent
  , defaultProgressEndEvent
  , defaultProgressStartEvent
  , defaultProgressUpdateEvent
  , defaultStoppedEvent
  , defaultTerminatedEvent
  , defaultThreadEvent
  ) where
----------------------------------------------------------------------------
import           DAP.Types
import           DAP.Adaptor
----------------------------------------------------------------------------
sendBreakpointEvent :: BreakpointEvent -> Adaptor app Request ()
sendBreakpointEvent :: forall app. BreakpointEvent -> Adaptor app Request ()
sendBreakpointEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeBreakpoint (Adaptor app Request () -> Adaptor app Request ())
-> (BreakpointEvent -> Adaptor app Request ())
-> BreakpointEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BreakpointEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
sendCapabilitiesEvent :: CapabilitiesEvent -> Adaptor app Request ()
sendCapabilitiesEvent :: forall app. CapabilitiesEvent -> Adaptor app Request ()
sendCapabilitiesEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeCapabilities (Adaptor app Request () -> Adaptor app Request ())
-> (CapabilitiesEvent -> Adaptor app Request ())
-> CapabilitiesEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CapabilitiesEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
sendContinuedEvent :: ContinuedEvent -> Adaptor app Request ()
sendContinuedEvent :: forall app. ContinuedEvent -> Adaptor app Request ()
sendContinuedEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeContinued (Adaptor app Request () -> Adaptor app Request ())
-> (ContinuedEvent -> Adaptor app Request ())
-> ContinuedEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ContinuedEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultContinuedEvent :: ContinuedEvent
defaultContinuedEvent :: ContinuedEvent
defaultContinuedEvent
  = ContinuedEvent
  { continuedEventThreadId :: Int
continuedEventThreadId            = Int
0
  , continuedEventAllThreadsContinued :: Bool
continuedEventAllThreadsContinued = Bool
False
  }
----------------------------------------------------------------------------
sendExitedEvent :: ExitedEvent -> Adaptor app Request ()
sendExitedEvent :: forall app. ExitedEvent -> Adaptor app Request ()
sendExitedEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeExited (Adaptor app Request () -> Adaptor app Request ())
-> (ExitedEvent -> Adaptor app Request ())
-> ExitedEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExitedEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultExitedEvent :: ExitedEvent
defaultExitedEvent :: ExitedEvent
defaultExitedEvent
  = ExitedEvent
  { exitedEventExitCode :: Int
exitedEventExitCode = Int
0
  }
----------------------------------------------------------------------------
sendInitializedEvent :: Adaptor app Request ()
sendInitializedEvent :: forall app. Adaptor app Request ()
sendInitializedEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeInitialized (() -> Adaptor app Request ()
forall a. a -> Adaptor app Request a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ())
----------------------------------------------------------------------------
sendInvalidatedEvent :: InvalidatedEvent -> Adaptor app Request ()
sendInvalidatedEvent :: forall app. InvalidatedEvent -> Adaptor app Request ()
sendInvalidatedEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeInvalidated (Adaptor app Request () -> Adaptor app Request ())
-> (InvalidatedEvent -> Adaptor app Request ())
-> InvalidatedEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. InvalidatedEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultInvalidatedEvent :: InvalidatedEvent
defaultInvalidatedEvent :: InvalidatedEvent
defaultInvalidatedEvent
  = InvalidatedEvent
  { invalidatedEventAreas :: [InvalidatedAreas]
invalidatedEventAreas         = []
  , invalidatedEventThreadId :: Maybe Int
invalidatedEventThreadId      = Maybe Int
forall a. Maybe a
Nothing
  , invalidatedEventStackFrameId :: Maybe Int
invalidatedEventStackFrameId  = Maybe Int
forall a. Maybe a
Nothing
  }

----------------------------------------------------------------------------
sendLoadedSourceEvent :: LoadedSourceEvent -> Adaptor app Request ()
sendLoadedSourceEvent :: forall app. LoadedSourceEvent -> Adaptor app Request ()
sendLoadedSourceEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeLoadedSource (Adaptor app Request () -> Adaptor app Request ())
-> (LoadedSourceEvent -> Adaptor app Request ())
-> LoadedSourceEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. LoadedSourceEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
sendMemoryEvent :: MemoryEvent -> Adaptor app Request ()
sendMemoryEvent :: forall app. MemoryEvent -> Adaptor app Request ()
sendMemoryEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeMemory (Adaptor app Request () -> Adaptor app Request ())
-> (MemoryEvent -> Adaptor app Request ())
-> MemoryEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. MemoryEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultMemoryEvent :: MemoryEvent
defaultMemoryEvent :: MemoryEvent
defaultMemoryEvent
  = MemoryEvent
  { memoryEventMemoryReference :: Text
memoryEventMemoryReference  = Text
forall a. Monoid a => a
mempty
  , memoryEventOffset :: Int
memoryEventOffset           = Int
0
  , memoryEventCount :: Int
memoryEventCount            = Int
0
  }
----------------------------------------------------------------------------
sendModuleEvent :: ModuleEvent -> Adaptor app Request ()
sendModuleEvent :: forall app. ModuleEvent -> Adaptor app Request ()
sendModuleEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeModule (Adaptor app Request () -> Adaptor app Request ())
-> (ModuleEvent -> Adaptor app Request ())
-> ModuleEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ModuleEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
sendOutputEvent :: OutputEvent -> Adaptor app request ()
sendOutputEvent :: forall app request. OutputEvent -> Adaptor app request ()
sendOutputEvent = EventType -> Adaptor app request () -> Adaptor app request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeOutput (Adaptor app request () -> Adaptor app request ())
-> (OutputEvent -> Adaptor app request ())
-> OutputEvent
-> Adaptor app request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OutputEvent -> Adaptor app request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultOutputEvent :: OutputEvent
defaultOutputEvent :: OutputEvent
defaultOutputEvent
  = OutputEvent
  { outputEventCategory :: Maybe OutputEventCategory
outputEventCategory           = Maybe OutputEventCategory
forall a. Maybe a
Nothing
  , outputEventOutput :: Text
outputEventOutput             = Text
forall a. Monoid a => a
mempty
  , outputEventGroup :: Maybe EventGroup
outputEventGroup              = Maybe EventGroup
forall a. Maybe a
Nothing
  , outputEventVariablesReference :: Maybe Int
outputEventVariablesReference = Maybe Int
forall a. Maybe a
Nothing
  , outputEventSource :: Maybe Source
outputEventSource             = Maybe Source
forall a. Maybe a
Nothing
  , outputEventLine :: Maybe Int
outputEventLine               = Maybe Int
forall a. Maybe a
Nothing
  , outputEventColumn :: Maybe Int
outputEventColumn             = Maybe Int
forall a. Maybe a
Nothing
  , outputEventData :: Maybe Value
outputEventData               = Maybe Value
forall a. Maybe a
Nothing
  }
----------------------------------------------------------------------------
sendProcessEvent :: ProcessEvent -> Adaptor app Request ()
sendProcessEvent :: forall app. ProcessEvent -> Adaptor app Request ()
sendProcessEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeProcess (Adaptor app Request () -> Adaptor app Request ())
-> (ProcessEvent -> Adaptor app Request ())
-> ProcessEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProcessEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultProcessEvent :: ProcessEvent
defaultProcessEvent :: ProcessEvent
defaultProcessEvent
  = ProcessEvent
  { processEventName :: Text
processEventName            = Text
forall a. Monoid a => a
mempty
  , processEventSystemProcessId :: Maybe Int
processEventSystemProcessId = Maybe Int
forall a. Maybe a
Nothing
  , processEventIsLocalProcess :: Bool
processEventIsLocalProcess  = Bool
True
  , processEventStartMethod :: Maybe StartMethod
processEventStartMethod     = Maybe StartMethod
forall a. Maybe a
Nothing
  , processEventPointerSize :: Maybe Int
processEventPointerSize     = Maybe Int
forall a. Maybe a
Nothing
  }
----------------------------------------------------------------------------
sendProgressEndEvent :: ProgressEndEvent -> Adaptor app Request ()
sendProgressEndEvent :: forall app. ProgressEndEvent -> Adaptor app Request ()
sendProgressEndEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeProgressEnd (Adaptor app Request () -> Adaptor app Request ())
-> (ProgressEndEvent -> Adaptor app Request ())
-> ProgressEndEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProgressEndEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultProgressEndEvent :: ProgressEndEvent
defaultProgressEndEvent :: ProgressEndEvent
defaultProgressEndEvent
  = ProgressEndEvent
  { progressEndEventProgressId :: Text
progressEndEventProgressId  = Text
forall a. Monoid a => a
mempty
  , progressEndEventMessage :: Maybe Text
progressEndEventMessage     = Maybe Text
forall a. Maybe a
Nothing
  }
----------------------------------------------------------------------------
sendProgressStartEvent :: ProgressStartEvent -> Adaptor app Request ()
sendProgressStartEvent :: forall app. ProgressStartEvent -> Adaptor app Request ()
sendProgressStartEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeProgressStart (Adaptor app Request () -> Adaptor app Request ())
-> (ProgressStartEvent -> Adaptor app Request ())
-> ProgressStartEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProgressStartEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultProgressStartEvent :: ProgressStartEvent
defaultProgressStartEvent :: ProgressStartEvent
defaultProgressStartEvent
  = ProgressStartEvent
  { progressStartEventProgressId :: Text
progressStartEventProgressId  = Text
forall a. Monoid a => a
mempty
  , progressStartEventTitle :: Text
progressStartEventTitle       = Text
forall a. Monoid a => a
mempty
  , progressStartEventRequestId :: Maybe Int
progressStartEventRequestId   = Maybe Int
forall a. Maybe a
Nothing
  , progressStartEventCancellable :: Bool
progressStartEventCancellable = Bool
False
  , progressStartEventMessage :: Maybe Text
progressStartEventMessage     = Maybe Text
forall a. Maybe a
Nothing
  , progressStartEventPercentage :: Maybe Int
progressStartEventPercentage  = Maybe Int
forall a. Maybe a
Nothing
  }
----------------------------------------------------------------------------
sendProgressUpdateEvent :: ProgressUpdateEvent -> Adaptor app Request ()
sendProgressUpdateEvent :: forall app. ProgressUpdateEvent -> Adaptor app Request ()
sendProgressUpdateEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeProgressUpdate (Adaptor app Request () -> Adaptor app Request ())
-> (ProgressUpdateEvent -> Adaptor app Request ())
-> ProgressUpdateEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProgressUpdateEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultProgressUpdateEvent :: ProgressUpdateEvent
defaultProgressUpdateEvent :: ProgressUpdateEvent
defaultProgressUpdateEvent
  = ProgressUpdateEvent
  { progressUpdateEventProgressId :: Text
progressUpdateEventProgressId = Text
forall a. Monoid a => a
mempty
  , progressUpdateEventMessage :: Maybe Text
progressUpdateEventMessage    = Maybe Text
forall a. Maybe a
Nothing
  , progressUpdateEventPercentage :: Maybe Int
progressUpdateEventPercentage = Maybe Int
forall a. Maybe a
Nothing
  }
----------------------------------------------------------------------------
sendStoppedEvent :: StoppedEvent -> Adaptor app Request ()
sendStoppedEvent :: forall app. StoppedEvent -> Adaptor app Request ()
sendStoppedEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeStopped (Adaptor app Request () -> Adaptor app Request ())
-> (StoppedEvent -> Adaptor app Request ())
-> StoppedEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StoppedEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultStoppedEvent :: StoppedEvent
defaultStoppedEvent :: StoppedEvent
defaultStoppedEvent
  = StoppedEvent
  { stoppedEventReason :: StoppedEventReason
stoppedEventReason            = StoppedEventReason
StoppedEventReasonStep
  , stoppedEventDescription :: Maybe Text
stoppedEventDescription       = Maybe Text
forall a. Maybe a
Nothing
  , stoppedEventThreadId :: Maybe Int
stoppedEventThreadId          = Int -> Maybe Int
forall a. a -> Maybe a
Just Int
0
  , stoppedEventPreserveFocusHint :: Bool
stoppedEventPreserveFocusHint = Bool
False
  , stoppedEventText :: Maybe Text
stoppedEventText              = Maybe Text
forall a. Maybe a
Nothing
  , stoppedEventAllThreadsStopped :: Bool
stoppedEventAllThreadsStopped = Bool
False
  , stoppedEventHitBreakpointIds :: [Int]
stoppedEventHitBreakpointIds  = []
  }
----------------------------------------------------------------------------
sendTerminatedEvent :: TerminatedEvent -> Adaptor app Request ()
sendTerminatedEvent :: forall app. TerminatedEvent -> Adaptor app Request ()
sendTerminatedEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeTerminated (Adaptor app Request () -> Adaptor app Request ())
-> (TerminatedEvent -> Adaptor app Request ())
-> TerminatedEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TerminatedEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultTerminatedEvent :: TerminatedEvent
defaultTerminatedEvent :: TerminatedEvent
defaultTerminatedEvent
  = TerminatedEvent
  { terminatedEventRestart :: Bool
terminatedEventRestart = Bool
False
  }
----------------------------------------------------------------------------
sendThreadEvent :: ThreadEvent -> Adaptor app Request ()
sendThreadEvent :: forall app. ThreadEvent -> Adaptor app Request ()
sendThreadEvent = EventType -> Adaptor app Request () -> Adaptor app Request ()
forall app request.
EventType -> Adaptor app request () -> Adaptor app request ()
sendSuccesfulEvent EventType
EventTypeThread (Adaptor app Request () -> Adaptor app Request ())
-> (ThreadEvent -> Adaptor app Request ())
-> ThreadEvent
-> Adaptor app Request ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ThreadEvent -> Adaptor app Request ()
forall value app request.
ToJSON value =>
value -> Adaptor app request ()
setBody
----------------------------------------------------------------------------
defaultThreadEvent :: ThreadEvent
defaultThreadEvent :: ThreadEvent
defaultThreadEvent
  = ThreadEvent
  { threadEventReason :: ThreadEventReason
threadEventReason   = ThreadEventReason
ThreadEventReasonStarted
  , threadEventThreadId :: Int
threadEventThreadId = Int
0
  }
----------------------------------------------------------------------------