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

Commit

Permalink
Merge pull request #201 from jtpio/debugger-flag
Browse files Browse the repository at this point in the history
Add support for the debugger flag in kernel info
  • Loading branch information
jtpio authored Nov 20, 2019
2 parents a9d04e5 + 2dba59a commit 84e0753
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ async function setDebugSession(
} else {
debug.session.client = client;
}
await debug.restoreState(true);
if (debug.isDebuggingEnabled) {
await debug.restoreState(true);
}
app.commands.notifyCommandChanged();
}

Expand Down
9 changes: 8 additions & 1 deletion src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ export class DebugService implements IDebugger {
return this._isDisposed;
}

/**
* Whether debugging is enabled for the current session.
*/
get isDebuggingEnabled(): boolean {
return this._session.kernelInfo.debugger || false;
}

/**
* Returns the mode of the debugger UI.
*
Expand Down Expand Up @@ -166,7 +173,7 @@ export class DebugService implements IDebugger {

/**
* Starts a debugger.
* Precondition: canStart() && !isStarted()
* Precondition: !isStarted()
*/
async start(): Promise<void> {
await this.session.start();
Expand Down
11 changes: 11 additions & 0 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ export class DebugSession implements IDebugger.ISession {
}
}

/**
* Return the kernel info for the debug session.
*/
get kernelInfo(): IDebugger.ISession.IInfoReply | null {
const kernel = this.client.kernel;
if (!kernel) {
return null;
}
return kernel.info as IDebugger.ISession.IInfoReply;
}

/**
* Whether the debug session is started
*/
Expand Down
25 changes: 23 additions & 2 deletions src/tokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import { IClientSession } from '@jupyterlab/apputils';

import { Session } from '@jupyterlab/services';
import { KernelMessage, Session } from '@jupyterlab/services';

import { Token } from '@phosphor/coreutils';

Expand All @@ -22,6 +22,11 @@ import { Debugger } from './debugger';
* An interface describing an application's visual debugger.
*/
export interface IDebugger extends IDisposable {
/**
* Whether debugging is enabled for the current session.
*/
readonly isDebuggingEnabled: boolean;

/**
* The mode of the debugger UI.
*
Expand Down Expand Up @@ -73,7 +78,7 @@ export interface IDebugger extends IDisposable {

/**
* Starts a debugger.
* Precondition: canStart() && !isStarted()
* Precondition: !isStarted()
*/
start(): Promise<void>;

Expand Down Expand Up @@ -150,10 +155,16 @@ 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
*/
readonly isStarted: boolean;

/**
* Signal emitted for debug event messages.
*/
Expand Down Expand Up @@ -187,6 +198,16 @@ export namespace IDebugger {
}

export namespace ISession {
/**
* Response to the 'kernel_info_request' request.
* This interface extends the IInfoReply by adding the `debugger` key
* that isn't part of the protocol yet.
* See this pull request for more info: https://github.com/jupyter/jupyter_client/pull/486
*/
export interface IInfoReply extends KernelMessage.IInfoReply {
debugger: boolean;
}

/**
* Arguments for 'dumpCell' request.
* This is an addition to the Debug Adapter Protocol to support
Expand Down
46 changes: 46 additions & 0 deletions tests/src/service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,52 @@ import { DebugSession } from '../../lib/session';

import { IDebugger } from '../../lib/tokens';

describe('Debugging Support', () => {
let xpythonClient: IClientSession;
let ipykernelClient: IClientSession;

beforeAll(async () => {
xpythonClient = await createClientSession({
kernelPreference: {
name: 'xpython'
}
});
ipykernelClient = await createClientSession({
kernelPreference: {
name: 'python3'
}
});
await Promise.all([
(xpythonClient as ClientSession).initialize(),
(ipykernelClient as ClientSession).initialize()
]);
await Promise.all([
xpythonClient.kernel.ready,
ipykernelClient.kernel.ready
]);
});

afterAll(async () => {
await Promise.all([xpythonClient.shutdown(), ipykernelClient.shutdown()]);
});

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

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

describe('DebugService', () => {
let client: IClientSession;
let model: Debugger.Model;
Expand Down

0 comments on commit 84e0753

Please sign in to comment.