Skip to content
This repository has been archived by the owner on Jan 26, 2022. It is now read-only.

Restore debugger session state #75

Merged
merged 1 commit into from
Oct 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ steps:

- bash: |
source activate jupyterlab-debugger
conda install --yes --quiet -c conda-forge nodejs xeus-python=0.5.3 ptvsd python=$PYTHON_VERSION
conda install --yes --quiet -c conda-forge nodejs xeus-python=0.6.1 ptvsd python=$PYTHON_VERSION
python -m pip install -U --pre jupyterlab
displayName: Install dependencies

Expand Down
18 changes: 13 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const consoles: JupyterFrontEndPlugin<void> = {
autoStart: true,
requires: [IDebugger, IConsoleTracker, ILabShell],
activate: (
_,
app: JupyterFrontEnd,
debug: IDebugger,
tracker: IConsoleTracker,
labShell: ILabShell
Expand All @@ -74,7 +74,7 @@ const consoles: JupyterFrontEndPlugin<void> = {
handler: DebuggerConsoleHandler;
};

labShell.currentChanged.connect((_, update) => {
labShell.currentChanged.connect(async (_, update) => {
const widget = update.newValue;

if (!(widget instanceof ConsolePanel)) {
Expand All @@ -86,6 +86,10 @@ const consoles: JupyterFrontEndPlugin<void> = {
} else {
debug.session.client = widget.session;
}
if (debug.session) {
await debug.session.restoreState();
app.commands.notifyCommandChanged();
}
if (debug.tracker.currentWidget) {
const handler = new DebuggerConsoleHandler({
consoleTracker: tracker,
Expand Down Expand Up @@ -163,7 +167,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
autoStart: true,
requires: [IDebugger, INotebookTracker, ILabShell],
activate: (
_,
app: JupyterFrontEnd,
debug: IDebugger,
tracker: INotebookTracker,
labShell: ILabShell
Expand All @@ -173,7 +177,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
handler: DebuggerNotebookHandler;
};

labShell.currentChanged.connect((_, update) => {
labShell.currentChanged.connect(async (_, update) => {
const widget = update.newValue;
if (!(widget instanceof NotebookPanel)) {
return;
Expand All @@ -183,6 +187,10 @@ const notebooks: JupyterFrontEndPlugin<void> = {
} else {
debug.session.client = widget.session;
}
if (debug.session) {
await debug.session.restoreState();
app.commands.notifyCommandChanged();
}
if (debug.tracker.currentWidget) {
const handler = new DebuggerNotebookHandler({
notebookTracker: tracker,
Expand Down Expand Up @@ -394,7 +402,7 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
},
session: {
get: (): IDebugger.ISession | null => {
return null;
return widget ? widget.content.model.session : null;
},
set: (src: IDebugger.ISession | null) => {
if (widget) {
Expand Down
12 changes: 12 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ export class DebugSession implements IDebugger.ISession {
}
}

/**
* Restore the state of a debug session.
*/
async restoreState(): Promise<void> {
try {
const message = await this.sendRequest('debugInfo', {});
this._isStarted = message.body.isStarted;
} catch (err) {
console.error('Error: ', err.message);
}
}

/**
* Send a custom debug request to the kernel.
* @param command debug command.
Expand Down
37 changes: 33 additions & 4 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,18 @@ export namespace IDebugger {
* Stop a running debug session.
*/
stop(): Promise<void>;

jtpio marked this conversation as resolved.
Show resolved Hide resolved
/**
* Restore the state of a debug session.
*/
restoreState(): Promise<void>;
}

export namespace ISession {
/**
* Arguments for 'dumpCell' request.
* This is an addition to the Debug Adapter Protocol to support
* setting breakpoints for cells
* setting breakpoints for cells.
*/
export interface IDumpCellArguments {
code: string;
Expand All @@ -94,14 +99,36 @@ export namespace IDebugger {
/**
* Response to 'dumpCell' request.
* This is an addition to the Debug Adapter Protocol to support
* setting breakpoints for cells
* setting breakpoints for cells.
*/
export interface IDumpCellResponse extends DebugProtocol.Response {
body: {
sourcePath: string;
};
}

/**
* List of breakpoints in a source file.
*/
export interface IDebugInfoBreakpoints {
source: string;
lines: number[];
}

/**
* Response to 'debugInfo' request.
* This is an addition to the Debug Adapter Protocol to be able
* to retrieve the debugger state when restoring a session.
*/
export interface IDebugInfoResponse extends DebugProtocol.Response {
body: {
isStarted: boolean;
hashMethod: string;
hashSeed: number;
breakpoints: IDebugInfoBreakpoints[];
};
}

/**
* Expose all the debug requests types.
*/
Expand All @@ -110,7 +137,9 @@ export namespace IDebugger {
completions: DebugProtocol.CompletionsArguments;
configurationDone: DebugProtocol.ConfigurationDoneArguments;
continue: DebugProtocol.ContinueArguments;
debugInfo: {};
disconnect: DebugProtocol.DisconnectArguments;
dumpCell: IDumpCellArguments;
evaluate: DebugProtocol.EvaluateArguments;
exceptionInfo: DebugProtocol.ExceptionInfoArguments;
goto: DebugProtocol.GotoArguments;
Expand Down Expand Up @@ -139,7 +168,6 @@ export namespace IDebugger {
terminate: DebugProtocol.TerminateArguments;
terminateThreads: DebugProtocol.TerminateThreadsArguments;
threads: {};
dumpCell: IDumpCellArguments;
variables: DebugProtocol.VariablesArguments;
};

Expand All @@ -151,7 +179,9 @@ export namespace IDebugger {
completions: DebugProtocol.CompletionsResponse;
configurationDone: DebugProtocol.ConfigurationDoneResponse;
continue: DebugProtocol.ContinueResponse;
debugInfo: IDebugInfoResponse;
disconnect: DebugProtocol.DisconnectResponse;
dumpCell: IDumpCellResponse;
evaluate: DebugProtocol.EvaluateResponse;
exceptionInfo: DebugProtocol.ExceptionInfoResponse;
goto: DebugProtocol.GotoResponse;
Expand Down Expand Up @@ -180,7 +210,6 @@ export namespace IDebugger {
terminate: DebugProtocol.TerminateResponse;
terminateThreads: DebugProtocol.TerminateThreadsResponse;
threads: DebugProtocol.ThreadsResponse;
dumpCell: IDumpCellResponse;
variables: DebugProtocol.VariablesResponse;
};

Expand Down