Skip to content

Commit

Permalink
Merge pull request #6704 from JohanMabille/debug
Browse files Browse the repository at this point in the history
Added debug messages
  • Loading branch information
afshin committed Jul 31, 2019
2 parents 75166c6 + 1f20115 commit 97bc2ca
Show file tree
Hide file tree
Showing 3 changed files with 223 additions and 3 deletions.
34 changes: 34 additions & 0 deletions packages/services/src/kernel/default.ts
Expand Up @@ -602,6 +602,40 @@ export class DefaultKernel implements Kernel.IKernel {
>;
}

/**
* Send an experimental `debug_request` message.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this function is *NOT* considered
* part of the public API, and may change without notice.
*/
requestDebug(
content: KernelMessage.IDebugRequestMsg['content'],
disposeOnDone: boolean = true
): Kernel.IControlFuture<
KernelMessage.IDebugRequestMsg,
KernelMessage.IDebugReplyMsg
> {
let msg = KernelMessage.createMessage({
msgType: 'debug_request',
channel: 'control',
username: this._username,
session: this._clientId,
content
});
return this.sendControlMessage(
msg,
true,
disposeOnDone
) as Kernel.IControlFuture<
KernelMessage.IDebugRequestMsg,
KernelMessage.IDebugReplyMsg
>;
}

/**
* Send an `is_complete_request` message.
*
Expand Down
24 changes: 24 additions & 0 deletions packages/services/src/kernel/kernel.ts
Expand Up @@ -278,6 +278,30 @@ export namespace Kernel {
KernelMessage.IExecuteReplyMsg
>;

/**
* Send an experimental `debug_request` message.
*
* @hidden
*
* @param content - The content of the request.
*
* @param disposeOnDone - Whether to dispose of the future when done.
*
* @returns A kernel future.
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this function is *NOT* considered
* part of the public API, and may change without notice.
*/
requestDebug(
content: KernelMessage.IDebugRequestMsg['content'],
disposeOnDone?: boolean
): Kernel.IControlFuture<
KernelMessage.IDebugRequestMsg,
KernelMessage.IDebugReplyMsg
>;

/**
* Send an `is_complete_request` message.
*
Expand Down
168 changes: 165 additions & 3 deletions packages/services/src/kernel/messages.ts
Expand Up @@ -109,6 +109,39 @@ export namespace KernelMessage {
options: IOptions<T>
): T;

/**
* @hidden
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this function is *NOT* considered
* part of the public API, and may change without notice.
*/
export function createMessage<T extends IDebugRequestMsg>(
options: IOptions<T>
): T;

/**
* @hidden
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this function is *NOT* considered
* part of the public API, and may change without notice.
*/
export function createMessage<T extends IDebugReplyMsg>(
options: IOptions<T>
): T;

/**
* @hidden
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this function is *NOT* considered
* part of the public API, and may change without notice.
*/
export function createMessage<T extends IDebugEventMsg>(
options: IOptions<T>
): T;

export function createMessage<T extends Message>(options: IOptions<T>): T {
return {
buffers: options.buffers || [],
Expand Down Expand Up @@ -155,11 +188,21 @@ export namespace KernelMessage {

/**
* Control message types.
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, debug message types are *NOT*
* considered part of the public API, and may change without notice.
*/
export type ControlMessageType = never;
export type ControlMessageType = 'debug_request' | 'debug_reply';

/**
* IOPub message types.
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, debug message types are *NOT*
* considered part of the public API, and may change without notice.
*/
export type IOPubMessageType =
| 'clear_output'
Expand All @@ -172,7 +215,8 @@ export namespace KernelMessage {
| 'execute_result'
| 'status'
| 'stream'
| 'update_display_data';
| 'update_display_data'
| 'debug_event';

/**
* Stdin message types.
Expand Down Expand Up @@ -310,6 +354,14 @@ export namespace KernelMessage {
channel: 'stdin';
}

/**
* Message types.
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, debug message types are *NOT*
* considered part of the public API, and may change without notice.
*/
export type Message =
| IClearOutputMsg
| ICommCloseMsg<'iopub'>
Expand Down Expand Up @@ -340,7 +392,10 @@ export namespace KernelMessage {
| IIsCompleteRequestMsg
| IStatusMsg
| IStreamMsg
| IUpdateDisplayDataMsg;
| IUpdateDisplayDataMsg
| IDebugRequestMsg
| IDebugReplyMsg
| IDebugEventMsg;

//////////////////////////////////////////////////
// IOPub Messages
Expand Down Expand Up @@ -503,6 +558,40 @@ export namespace KernelMessage {
return msg.header.msg_type === 'clear_output';
}

/**
* An experimental `'debug_event'` message on the `'iopub'` channel
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/
export interface IDebugEventMsg extends IIOPubMessage<'debug_event'> {
content: {
seq: number;
type: 'event';
event: string;
body?: any;
};
}

/**
* Test whether a kernel message is an experimental `'debug_event'` message.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/

export function isDebugEventMsg(msg: IMessage): msg is IDebugEventMsg {
return msg.header.msg_type === 'debug_event';
}

//////////////////////////////////////////////////
// Comm Messages
/////////////////////////////////////////////////
Expand Down Expand Up @@ -1022,6 +1111,79 @@ export namespace KernelMessage {
content: ReplyContent<ICommInfoReply>;
}

/////////////////////////////////////////////////
// Control Messages
/////////////////////////////////////////////////

/**
* An experimental `'debug_request'` messsage on the `'control'` channel.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this function is *NOT* considered
* part of the public API, and may change without notice.
*/
export interface IDebugRequestMsg extends IControlMessage<'debug_request'> {
content: {
seq: number;
type: 'request';
command: string;
arguments?: any;
};
}

/**
* Test whether a kernel message is an experimental `'debug_request'` message.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/
export function isDebugRequestMsg(msg: IMessage): msg is IDebugRequestMsg {
return msg.header.msg_type === 'debug_request';
}

/**
* An experimental `'debug_reply'` messsage on the `'control'` channel.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/
export interface IDebugReplyMsg extends IControlMessage<'debug_reply'> {
content: {
seq: number;
type: 'response';
request_seq: number;
success: boolean;
command: string;
message?: string;
body?: any;
};
}

/**
* Test whether a kernel message is an experimental `'debug_reply'` message.
*
* @hidden
*
* #### Notes
* Debug messages are experimental messages that are not in the official
* kernel message specification. As such, this is *NOT* considered
* part of the public API, and may change without notice.
*/
export function isDebugReplyMsg(msg: IMessage): msg is IDebugReplyMsg {
return msg.header.msg_type === 'debug_reply';
}

//////////////////////////////////////////////////
// Stdin Messages
/////////////////////////////////////////////////
Expand Down

0 comments on commit 97bc2ca

Please sign in to comment.