Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I listen for debug adapter protocol events in a vscode extension?

I know I can send custom request to the debug adapter using vscode.debug.activeDebugSession?.customRequest(command). But what if I want to listen for an event such as Stopped Event?

like image 467
Adrian Avatar asked Oct 29 '25 03:10

Adrian


1 Answers

For custom events, use this:

vscode.debug.onDidReceiveDebugSessionCustomEvent(event => {
    if(event.event == 'stopped') {
        // ...
    }
})

For events intercepted by vscode, you might want to check this answer instead:

The solution for this is called a DebugAdapterTracker.

vscode.debug.registerDebugAdapterTrackerFactory('*', {
  createDebugAdapterTracker(session: DebugSession) {
    return {
      onWillReceiveMessage: m => console.log(`> ${JSON.stringify(m, undefined, 2)}`),
      onDidSendMessage: m => console.log(`< ${JSON.stringify(m, undefined, 2)}`)
    };
  }
});

https://code.visualstudio.com/updates/v1_30#_extension-authoring

Look for "Finalized Debug Adapter Tracker API". It was originally created for Live Share debugging.

like image 195
Adrian Avatar answered Oct 31 '25 01:10

Adrian



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!