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

Commit

Permalink
Check debugging is enabled before restoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jtpio committed Dec 11, 2019
1 parent 9645cc8 commit 122d2d1
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 27 deletions.
20 changes: 14 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ async function setDebugSession(
} else {
debug.session.client = client;
}
const debuggingEnabled = await debug.requestDebuggingEnabled();
if (!debuggingEnabled) {
return;
}
await debug.restoreState(true);
app.commands.notifyCommandChanged();
}
Expand All @@ -86,11 +90,15 @@ class DebuggerHandler<
this.builder = builder;
}

update<W extends ConsolePanel | NotebookPanel | FileEditor>(
async update<W extends ConsolePanel | NotebookPanel | FileEditor>(
debug: IDebugger,
widget: W
): void {
if (!debug.model || this.handlers[widget.id] || !debug.isDebuggingEnabled) {
) {
if (!debug.session) {
return;
}
const debuggingEnabled = await debug.requestDebuggingEnabled();
if (!debug.model || this.handlers[widget.id] || !debuggingEnabled) {
return;
}
const handler = new this.builder({
Expand Down Expand Up @@ -138,7 +146,7 @@ const consoles: JupyterFrontEndPlugin<void> = {
return;
}
await setDebugSession(app, debug, widget.session);
handler.update(debug, widget);
void handler.update(debug, widget);
});
}
};
Expand Down Expand Up @@ -185,7 +193,7 @@ const files: JupyterFrontEndPlugin<void> = {
activeSessions[model.id] = session;
}
await setDebugSession(app, debug, session);
handler.update(debug, content);
void handler.update(debug, content);
} catch {
return;
}
Expand All @@ -209,7 +217,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
return;
}
await setDebugSession(app, debug, widget.session);
handler.update(debug, widget);
void handler.update(debug, widget);
});
}
};
Expand Down
7 changes: 4 additions & 3 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ export class DebugService implements IDebugger, IDisposable {
}

/**
* Whether debugging is enabled for the current session.
* Request whether debugging is enabled for the current session.
*/
get isDebuggingEnabled(): boolean {
return this._session.kernelInfo?.debugger ?? false;
async requestDebuggingEnabled(): Promise<boolean> {
const kernelInfo = await this._session.requestKernelInfo();
return kernelInfo?.debugger ?? false;
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,17 +66,19 @@ export class DebugSession implements IDebugger.ISession {
this._client.iopubMessage.connect(this._handleEvent, this);

if (this.client instanceof ClientSession) {
this._ready = this.client.ready;
this._ready = this.client.ready.then(_ => this.client.kernel.ready);
} else {
this._ready = this.client.kernel.ready;
}
}
}

/**
* Return the kernel info for the debug session.
* Return the kernel info for the debug session, waiting for the
* kernel to be ready.
*/
get kernelInfo(): IDebugger.ISession.IInfoReply | null {
async requestKernelInfo(): Promise<IDebugger.ISession.IInfoReply | null> {
await this._ready;
return (this.client.kernel?.info as IDebugger.ISession.IInfoReply) ?? null;
}

Expand Down
21 changes: 11 additions & 10 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ import { DebugProtocol } from 'vscode-debugprotocol';
* An interface describing an application's visual debugger.
*/
export interface IDebugger {
/**
* Whether debugging is enabled for the current session.
*/
readonly isDebuggingEnabled: boolean;

/**
* The current debugger session.
*/
Expand All @@ -47,6 +42,11 @@ export interface IDebugger {
*/
readonly eventMessage: ISignal<IDebugger, IDebugger.ISession.Event>;

/**
* Request whether debugging is enabled for the current session.
*/
requestDebuggingEnabled(): Promise<boolean>;

/**
* Computes an id based on the given code.
*/
Expand Down Expand Up @@ -144,11 +144,6 @@ export namespace IDebugger {
*/
client: IClientSession | Session.ISession;

/**
* The kernel info for the debug session.
*/
readonly kernelInfo: IDebugger.ISession.IInfoReply | null;

/**
* Whether the debug session is started
*/
Expand All @@ -162,6 +157,12 @@ export namespace IDebugger {
IDebugger.ISession.Event
>;

/**
* Return the kernel info for the debug session, waiting for the
* kernel to be ready.
*/
requestKernelInfo(): Promise<IDebugger.ISession.IInfoReply | null>;

/**
* Start a new debug session.
*/
Expand Down
12 changes: 7 additions & 5 deletions tests/src/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@ describe('Debugging Support', () => {
await Promise.all([xpythonClient.shutdown(), ipykernelClient.shutdown()]);
});

describe('#isDebuggingEnabled', () => {
it('should return true for kernels that have support for debugging', () => {
describe('#requestDebuggingEnabled', () => {
it('should return true for kernels that have support for debugging', async () => {
const debugSession = new DebugSession({ client: xpythonClient });
let service = new DebugService();
service.session = debugSession;
expect(service.isDebuggingEnabled).to.be.true;
const enabled = await service.requestDebuggingEnabled();
expect(enabled).to.be.true;
});

it('should return false for kernels that do not have support for debugging', () => {
it('should return false for kernels that do not have support for debugging', async () => {
const debugSession = new DebugSession({ client: ipykernelClient });
let service = new DebugService();
service.session = debugSession;
expect(service.isDebuggingEnabled).to.be.false;
const enabled = await service.requestDebuggingEnabled();
expect(enabled).to.be.false;
});
});
});
Expand Down

0 comments on commit 122d2d1

Please sign in to comment.