提交 1291d9e8 编写于 作者: A Andre Weinand

proposed debug api: add support for custom DAP events

上级 bf3ea73c
......@@ -207,4 +207,14 @@ declare module 'vscode' {
export const onDidChangeActiveDebugSession: Event<DebugSession | undefined>;
}
export interface DebugSession {
/**
* Experimental API that allows hooking custom events from the debug session's debug adapter.
*
* @param callback The callback that is triggered when a custom event is received from the debug adapter.
*/
onCustomEvent(callback: (event: any) => void): void;
}
}
......@@ -31,6 +31,11 @@ export class MainThreadDebugService extends MainThreadDebugServiceShape {
this._proxy.$acceptDebugSessionActiveChanged(undefined);
}
}));
this._toDispose.push(debugService.onDidCustomEvent(event => {
if (event.body && event.body.sessionId) {
this._proxy.$acceptDebugSessionCustomEvent(event.body.sessionId, event);
}
}));
}
public dispose(): void {
......
......@@ -502,6 +502,7 @@ export abstract class ExtHostTaskShape {
export abstract class ExtHostDebugServiceShape {
$acceptDebugSessionTerminated(id: DebugSessionUUID, type: string, name: string): void { throw ni(); }
$acceptDebugSessionActiveChanged(id: DebugSessionUUID | undefined, type?: string, name?: string): void { throw ni(); }
$acceptDebugSessionCustomEvent(id: DebugSessionUUID, event: any): void { throw ni(); }
}
// --- proxy identifiers
......
......@@ -24,8 +24,8 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape {
private _onDidChangeActiveDebugSession: Emitter<vscode.DebugSession | undefined>;
get onDidChangeActiveDebugSession(): Event<vscode.DebugSession | undefined> { return this._onDidChangeActiveDebugSession.event; }
private _activeDebugSession: vscode.DebugSession | undefined;
get activeDebugSession(): vscode.DebugSession | undefined { return this._activeDebugSession; }
private _activeDebugSession: ExtHostDebugSession | undefined;
get activeDebugSession(): ExtHostDebugSession | undefined { return this._activeDebugSession; }
constructor(threadService: IThreadService) {
super();
......@@ -50,6 +50,7 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape {
let debugSession = this._debugSessions.get(id);
if (!debugSession) {
debugSession = new ExtHostDebugSession(this._debugServiceProxy, id, type, name);
this._debugSessions.set(id, debugSession);
}
this._onDidTerminateDebugSession.fire(debugSession);
this._debugSessions.delete(id);
......@@ -61,12 +62,21 @@ export class ExtHostDebugService extends ExtHostDebugServiceShape {
this._activeDebugSession = this._debugSessions.get(id);
if (!this._activeDebugSession) {
this._activeDebugSession = new ExtHostDebugSession(this._debugServiceProxy, id, type, name);
this._debugSessions.set(id, this._activeDebugSession);
}
} else {
this._activeDebugSession = undefined;
}
this._onDidChangeActiveDebugSession.fire(this._activeDebugSession);
}
public $acceptDebugSessionCustomEvent(id: DebugSessionUUID, event: any): void {
let debugSession = this._debugSessions.get(id);
if (debugSession) {
debugSession._onCustomEvent(event);
}
}
}
export class ExtHostDebugSession implements vscode.DebugSession {
......@@ -78,6 +88,7 @@ export class ExtHostDebugSession implements vscode.DebugSession {
private _type: string;
private _name: string;
private _onCustomEventCallback: (event: any) => void;
constructor(proxy: MainThreadDebugServiceShape, id: DebugSessionUUID, type: string, name: string) {
this._debugServiceProxy = proxy;
......@@ -97,4 +108,12 @@ export class ExtHostDebugSession implements vscode.DebugSession {
public customRequest(command: string, args: any): Thenable<any> {
return this._debugServiceProxy.$customDebugAdapterRequest(this._id, command, args);
}
public onCustomEvent(callback: (event: any) => void): void {
this._onCustomEventCallback = callback;
}
public _onCustomEvent(event: any): void {
this._onCustomEventCallback(event);
}
}
......@@ -445,6 +445,11 @@ export interface IDebugService {
*/
onDidEndProcess: Event<IProcess>;
/**
* Allows to register on custom DAP events.
*/
onDidCustomEvent: Event<DebugProtocol.Event>;
/**
* Gets the current configuration manager.
*/
......
......@@ -69,6 +69,7 @@ export class DebugService implements debug.IDebugService {
private sessionStates: Map<string, debug.State>;
private _onDidChangeState: Emitter<debug.State>;
private _onDidEndProcess: Emitter<debug.IProcess>;
private _onDidCustomEvent: Emitter<DebugProtocol.Event>;
private model: Model;
private viewModel: ViewModel;
private configurationManager: ConfigurationManager;
......@@ -110,6 +111,7 @@ export class DebugService implements debug.IDebugService {
this.breakpointsToSendOnResourceSaved = new Set<string>();
this._onDidChangeState = new Emitter<debug.State>();
this._onDidEndProcess = new Emitter<debug.IProcess>();
this._onDidCustomEvent = new Emitter<DebugProtocol.Event>();
this.sessionStates = new Map<string, debug.State>();
this.configurationManager = this.instantiationService.createInstance(ConfigurationManager);
......@@ -414,6 +416,10 @@ export class DebugService implements debug.IDebugService {
this.onSessionEnd(session);
}
}));
this.toDisposeOnSessionEnd.get(session.getId()).push(session.onDidCustomEvent(event => {
this._onDidCustomEvent.fire(event);
}));
}
private fetchThreads(session: RawDebugSession): TPromise<any> {
......@@ -497,6 +503,10 @@ export class DebugService implements debug.IDebugService {
return this._onDidEndProcess.event;
}
public get onDidCustomEvent(): Event<DebugProtocol.Event> {
return this._onDidCustomEvent.event;
}
private updateStateAndEmit(sessionId?: string, newState?: debug.State): void {
if (sessionId) {
if (newState === debug.State.Inactive) {
......
......@@ -62,6 +62,7 @@ export class RawDebugSession extends v8.V8Protocol implements debug.ISession {
private _onDidThread: Emitter<DebugProtocol.ThreadEvent>;
private _onDidOutput: Emitter<DebugProtocol.OutputEvent>;
private _onDidBreakpoint: Emitter<DebugProtocol.BreakpointEvent>;
private _onDidCustomEvent: Emitter<DebugProtocol.Event>;
private _onDidEvent: Emitter<DebugProtocol.Event>;
constructor(
......@@ -90,6 +91,7 @@ export class RawDebugSession extends v8.V8Protocol implements debug.ISession {
this._onDidThread = new Emitter<DebugProtocol.ThreadEvent>();
this._onDidOutput = new Emitter<DebugProtocol.OutputEvent>();
this._onDidBreakpoint = new Emitter<DebugProtocol.BreakpointEvent>();
this._onDidCustomEvent = new Emitter<DebugProtocol.Event>();
this._onDidEvent = new Emitter<DebugProtocol.Event>();
}
......@@ -125,6 +127,10 @@ export class RawDebugSession extends v8.V8Protocol implements debug.ISession {
return this._onDidBreakpoint.event;
}
public get onDidCustomEvent(): Event<DebugProtocol.Event> {
return this._onDidCustomEvent.event;
}
public get onDidEvent(): Event<DebugProtocol.Event> {
return this._onDidEvent.event;
}
......@@ -209,6 +215,8 @@ export class RawDebugSession extends v8.V8Protocol implements debug.ISession {
this._onDidTerminateDebugee.fire(<SessionTerminatedEvent>event);
} else if (event.event === 'exit') {
this._onDidExitAdapter.fire(<SessionExitedEvent>event);
} else {
this._onDidCustomEvent.fire(event);
}
this._onDidEvent.fire(event);
......
......@@ -15,6 +15,10 @@ export class MockDebugService implements debug.IDebugService {
return null;
}
public get onDidCustomEvent(): Event<DebugProtocol.Event> {
return null;
}
public get onDidEndProcess(): Event<debug.IProcess> {
return null;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册