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 #13 from jupyterlab/master
Browse files Browse the repository at this point in the history
merge actual version
  • Loading branch information
KsavinN committed Oct 11, 2019
2 parents a19ccb4 + 63b3852 commit 18d97c7
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 33 deletions.
12 changes: 11 additions & 1 deletion README.md
Expand Up @@ -13,7 +13,7 @@ This extension is under active development and is not yet available.

```bash
# Create a new conda environment
conda create -n jupyterlab-debugger -c conda-forge jupyterlab nodejs xeus-python=0.5 ptvsd
conda create -n jupyterlab-debugger -c conda-forge jupyterlab nodejs xeus-python=0.5.3 ptvsd

# Activate the conda environment
conda activate jupyterlab-debugger
Expand Down Expand Up @@ -47,3 +47,13 @@ export XEUS_LOG=1

jlpm run test
```

### Inspecting debug messages

The [kernelspy extension for JupyterLab](https://github.com/vidartf/jupyterlab-kernelspy) can be used to inspect the debug messages sent between the debugger UI and the kernel.

To install it:

```bash
jupyter labextension install jupyterlab-kernelspy
```
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Expand Up @@ -16,7 +16,7 @@ steps:

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

Expand Down
1 change: 1 addition & 0 deletions src/handlers/cell.ts
Expand Up @@ -62,6 +62,7 @@ export class CellManager {
onActiveCellChanged() {
if (
this.activeCell &&
this.activeCell.isAttached &&
this.activeCell.editor &&
this._debuggerModel &&
this._debuggerModel.session
Expand Down
68 changes: 51 additions & 17 deletions src/index.ts
Expand Up @@ -34,13 +34,18 @@ import { DebuggerSidebar } from './sidebar';

import { SessionTypes } from './breakpoints';
import { DebugSession } from './session';
import { IDisposable } from '@phosphor/disposable';

/**
* The command IDs used by the debugger plugin.
*/
export namespace CommandIDs {
export const create = 'debugger:create';

export const start = 'debugger:start';

export const stop = 'debugger:stop';

export const debugConsole = 'debugger:debug-console';

export const debugFile = 'debugger:debug-file';
Expand Down Expand Up @@ -149,15 +154,6 @@ const notebooks: JupyterFrontEndPlugin<void> = {
// // Manages life cycle signal connections.
// // Manages variables
// });

// this exist only for my test in futre will be removed
const command: string = CommandIDs.debugNotebook;
app.commands.addCommand(command, {
label: 'test',
execute: () => {}
});

palette.addItem({ command, category: 'dev test' });
}
};

Expand Down Expand Up @@ -212,22 +208,54 @@ const tracker: JupyterFrontEndPlugin<IDebugger> = {
update;
});

const command = CommandIDs.create;
let commandStop: IDisposable;

app.commands.addCommand(command, {
const getModel = () => {
return tracker.currentWidget ? tracker.currentWidget.content.model : null;
};

app.commands.addCommand(CommandIDs.stop, {
label: 'Stop',
execute: async () => {
const debuggerModel = getModel();

if (debuggerModel) {
await debuggerModel.session.stop();
commandStop.dispose();
}
}
});

app.commands.addCommand(CommandIDs.start, {
label: 'Start',
isEnabled: () => {
const debuggerModel = getModel();
return (debuggerModel &&
debuggerModel.session !== undefined) as boolean;
},
execute: async () => {
const debuggerModel = getModel();
if (debuggerModel && debuggerModel.session) {
await debuggerModel.session.start();
commandStop = palette.addItem({
command: CommandIDs.stop,
category: 'Debugger'
});
}
}
});

app.commands.addCommand(CommandIDs.create, {
label: 'Debugger',
execute: args => {
const id = (args.id as string) || UUID.uuid4();
if (id) {
console.log('Debugger ID: ', id);
}

const existedWidget = tracker.find(
widget => id === widget.content.model.id
);
const existedWidget = tracker.currentWidget;

if (existedWidget) {
app.shell.add(existedWidget, 'main');
return;
}

Expand All @@ -245,12 +273,18 @@ const tracker: JupyterFrontEndPlugin<IDebugger> = {
}
});

palette.addItem({ command, category: 'Debugger' });
if (palette) {
palette.addItem({ command: CommandIDs.create, category: 'Debugger' });
palette.addItem({
command: CommandIDs.start,
category: 'Debugger'
});
}

if (restorer) {
// Handle state restoration.
void restorer.restore(tracker, {
command: command,
command: CommandIDs.create,
args: widget => ({ id: widget.content.model.id }),
name: widget => widget.content.model.id
});
Expand Down
14 changes: 6 additions & 8 deletions src/tokens.ts
Expand Up @@ -55,22 +55,20 @@ export namespace IDebugger {

export namespace ISession {
/**
* Arguments for 'updateCell' request.
* Arguments for 'dumpCell' request.
* This is an addition to the Debug Adapter Protocol to support
* setting breakpoints for cells
*/
export interface IUpdateCellArguments {
cellId: number;
nextId: number;
export interface IDumpCellArguments {
code: string;
}

/**
* Response to 'updateCell' request.
* Response to 'dumpCell' request.
* This is an addition to the Debug Adapter Protocol to support
* setting breakpoints for cells
*/
export interface IUpdateCellResponse extends DebugProtocol.Response {
export interface IDumpCellResponse extends DebugProtocol.Response {
body: {
sourcePath: string;
};
Expand Down Expand Up @@ -113,7 +111,7 @@ export namespace IDebugger {
terminate: DebugProtocol.TerminateArguments;
terminateThreads: DebugProtocol.TerminateThreadsArguments;
threads: {};
updateCell: IUpdateCellArguments;
dumpCell: IDumpCellArguments;
variables: DebugProtocol.VariablesArguments;
};

Expand Down Expand Up @@ -154,7 +152,7 @@ export namespace IDebugger {
terminate: DebugProtocol.TerminateResponse;
terminateThreads: DebugProtocol.TerminateThreadsResponse;
threads: DebugProtocol.ThreadsResponse;
updateCell: IUpdateCellResponse;
dumpCell: IDumpCellResponse;
variables: DebugProtocol.VariablesResponse;
};

Expand Down
8 changes: 2 additions & 6 deletions tests/src/session.spec.ts
Expand Up @@ -71,9 +71,7 @@ describe('DebugSession', () => {

it('should send debug messages to the kernel', async () => {
const code = 'i=0\ni+=1\ni+=1';
const reply = await debugSession.sendRequest('updateCell', {
cellId: 0,
nextId: 1,
const reply = await debugSession.sendRequest('dumpCell', {
code
});
expect(reply.body.sourcePath).to.contain('.py');
Expand Down Expand Up @@ -130,9 +128,7 @@ describe('protocol', () => {
}
);

const reply = await debugSession.sendRequest('updateCell', {
cellId: 0,
nextId: 1,
const reply = await debugSession.sendRequest('dumpCell', {
code
});
await debugSession.sendRequest('setBreakpoints', {
Expand Down

0 comments on commit 18d97c7

Please sign in to comment.