microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.44k stars 28.62k forks source link

How to send custom event from Debug Adapter to vscode client? #113538

Closed Abbyyan closed 3 years ago

Abbyyan commented 3 years ago
  1. I'm working with a debug extension. When the debugger show some output , such as open document, i want to get the info on the vscode side and use vscode API to open a document. But how can i achieve this please? Read from BreakpointEvent, is there any method to define a custom event and custom the event on the vscode(client ) side please? If so , where should i define the vscode event please? Thanks a lot.
  2. Find from https://github.com/microsoft/vscode-debugadapter-node/blob/fe3dbb9a9b5526b8c2d8aff1986321a2bb2f465d/adapter/src/debugSession.ts#L864, there is a customRequest . Does this means i can send a custom request from Debug Adapter to vsocde(client)? If so, how i can handle how to deal with the request on the client side please? Thanks a lot.
Abbyyan commented 3 years ago

Should i send a custom event from DA and receive on the vscode client using onDidReceiveDebugSessionCustomEvent just like https://github.com/microsoft/vscode/issues/49389?

Abbyyan commented 3 years ago

Find this https://github.com/microsoft/vscode/issues/40864 one. I've send an event in my DA like

// DebugAdapter.ts
const customEvent = { event: "customEvent", body: ["testsRoot"] } as DebugProtocol.Event;
this.sendEvent(customEvent);

and receive it on the vscode side

// extension.ts
export function activate(context: vscode.ExtensionContext) {
    context.subscriptions.push(vscode.debug.onDidReceiveDebugSessionCustomEvent((e) => {
        vscode.window.showInformationMessage('onDidReceiveDebugSessionCustomEvent!!!!!!' + e.event);
    }));
}

And the log shows i've enter the customEvent function in DA, but i can't see the info from vscode size. Could you please give me some suggestions if possible. Thanks a lot.

Abbyyan commented 3 years ago

The issue https://github.com/microsoft/vscode/issues/71651#issuecomment-479949977 really helps me a lot. https://github.com/DanTup/vscode-repro-71651/commit/769928975ded0e74b3817bc96f8425226f0e7d22 shows a detailed usage of onDidReceiveDebugSessionCustomEvent . The reason of onDidReceiveDebugSessionCustomEvent above is because i set the activationEvents in package.json only on commands and want to test it on Debug. Add onDebug into activationEvents, it works. Thanks a lot.