Skip to content

Commit 0077dbe

Browse files
authored
Merge pull request #4 from haskell-debugger/api-unlock-custom-event
Api unlock custom event
2 parents b7b248b + 652b447 commit 0077dbe

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

dap.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ extra-source-files:
1919
library
2020
exposed-modules:
2121
DAP
22-
other-modules:
2322
DAP.Adaptor
2423
DAP.Event
2524
DAP.Internal

src/DAP/Adaptor.hs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,9 @@ setDebugSessionId session = modify' $ \s -> s { sessionId = Just session }
144144
registerNewDebugSession
145145
:: SessionId
146146
-> app
147-
-> IO ()
148-
-- ^ Action to run debugger (operates in a forked thread that gets killed when disconnect is set)
149-
-> ((Adaptor app () -> IO ()) -> IO ())
150-
-- ^ Long running operation, meant to be used as a sink for
147+
-> [((Adaptor app () -> IO ()) -> IO ())]
148+
-- ^ Actions to run debugger (operates in a forked thread that gets killed when disconnect is set)
149+
-- Long running operation, meant to be used as a sink for
151150
-- the debugger to emit events and for the adaptor to forward to the editor
152151
-- This function should be in a 'forever' loop waiting on the read end of
153152
-- a debugger channel.
@@ -157,19 +156,18 @@ registerNewDebugSession
157156
-- used when sending events to the editor from the debugger (or from any forked thread).
158157
--
159158
-- >
160-
-- > registerNewDebugSession sessionId appState loadDebugger $ \withAdaptor ->
159+
-- > registerNewDebugSession sessionId appState $ loadDebugger : [\withAdaptor ->
161160
-- > forever $ getDebuggerOutput >>= \output -> do
162161
-- > withAdaptor $ sendOutputEvent defaultOutputEvent { outputEventOutput = output }
163-
-- >
162+
-- > ]
164163
--
165164
-> Adaptor app ()
166-
registerNewDebugSession k v debuggerExecution outputEventSink = do
165+
registerNewDebugSession k v debuggerConcurrentActions = do
167166
store <- gets appStore
168167
adaptorStateMVar <- gets adaptorStateMVar
169168
debuggerThreadState <- liftIO $
170169
DebuggerThreadState
171-
<$> fork debuggerExecution
172-
<*> fork (outputEventSink (runAdaptorWith adaptorStateMVar))
170+
<$> sequence [fork $ action (runAdaptorWith adaptorStateMVar) | action <- debuggerConcurrentActions]
173171
liftIO . atomically $ modifyTVar' store (H.insert k (debuggerThreadState, v))
174172
setDebugSessionId k
175173
logInfo $ BL8.pack $ "Registered new debug session: " <> unpack k
@@ -210,8 +208,7 @@ destroyDebugSession = do
210208
(sessionId, DebuggerThreadState {..}, _) <- getDebugSessionWithThreadIdAndSessionId
211209
store <- getAppStore
212210
liftIO $ do
213-
killThread debuggerThread
214-
killThread debuggerOutputEventThread
211+
mapM_ killThread debuggerThreads
215212
atomically $ modifyTVar' store (H.delete sessionId)
216213
logInfo $ BL8.pack $ "SessionId " <> unpack sessionId <> " ended"
217214
----------------------------------------------------------------------------

src/DAP/Types.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,7 @@ type AppStore app = TVar (H.HashMap SessionId (DebuggerThreadState, app))
302302
-- DAP server).
303303
data DebuggerThreadState
304304
= DebuggerThreadState
305-
{ debuggerThread :: ThreadId
306-
, debuggerOutputEventThread :: ThreadId
305+
{ debuggerThreads :: [ThreadId]
307306
}
308307

309308
----------------------------------------------------------------------------
@@ -876,10 +875,12 @@ data EventType
876875
| EventTypeProgressEnd
877876
| EventTypeInvalidated
878877
| EventTypeMemory
878+
| EventTypeCustom Text
879879
deriving stock (Show, Eq, Read, Generic)
880880
----------------------------------------------------------------------------
881881
instance ToJSON EventType where
882-
toJSON = genericToJSONWithModifier
882+
toJSON (EventTypeCustom e) = toJSON e
883+
toJSON e = genericToJSONWithModifier e
883884
----------------------------------------------------------------------------
884885
data Command
885886
= CommandCancel

0 commit comments

Comments
 (0)