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

Connect Breakpoints widget with NoteBook #36

Merged
merged 46 commits into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
c5b8d24
some changes
KsavinN Aug 29, 2019
833b2cc
add setting breakpoint in UI
KsavinN Aug 30, 2019
e60f900
add notebooktracker to breakpoint wideget
KsavinN Sep 2, 2019
e6bd0dc
Merge branch 'notebook_lines' into debugger-ui
KsavinN Sep 2, 2019
b3e1fa7
debug for test
KsavinN Sep 2, 2019
5ad3971
add method for update breakpoints after changedLines in Notebook
KsavinN Sep 3, 2019
484108a
develope toogle remove all breakpoints
KsavinN Sep 3, 2019
ec77927
Merge branch 'notebook_lines' into debugger-ui
KsavinN Sep 3, 2019
2b0ce1d
changes
KsavinN Sep 6, 2019
c37f31c
refactor , suggest by Jeremy
KsavinN Sep 9, 2019
01aa541
rename INoteTracker variable
KsavinN Sep 9, 2019
8752e6f
Merge pull request #8 from jupyterlab/master
KsavinN Sep 9, 2019
061feff
add DebugerNotebookTracker
KsavinN Sep 9, 2019
2d676fa
Merge branch 'master' into session
KsavinN Sep 9, 2019
7dd3752
add breakpointservice
KsavinN Sep 11, 2019
47d0bb3
add service instance
KsavinN Sep 11, 2019
d303fcd
remove breakpoints
KsavinN Sep 12, 2019
7da863f
change breakpoints UI during new lines
KsavinN Sep 12, 2019
b7551a1
Merge branch 'session' into debugger-ui
KsavinN Sep 12, 2019
743347f
debug forr tests
KsavinN Sep 12, 2019
25b1dc8
new method for redner line
KsavinN Sep 16, 2019
a3995cb
add cellManager
KsavinN Sep 16, 2019
681a7d8
Merge branch 'session' into debugger-ui
KsavinN Sep 17, 2019
7f50def
add and debeug consoletracker plugin
KsavinN Sep 18, 2019
951a239
debug consoleTracker
KsavinN Sep 18, 2019
c24b512
Merge branch 'session' into debugger-ui
KsavinN Sep 18, 2019
fe547a4
check type of kernel and set breakpoints
KsavinN Sep 19, 2019
a0bdb64
Merge branch 'session' into debugger-ui
KsavinN Sep 19, 2019
fdd97c2
Rename/reorganize some paths.
afshin Sep 20, 2019
6fcd20f
BROKEN - just for comments
afshin Sep 25, 2019
6e63811
Merge pull request #9 from afshin/debugger-ui
KsavinN Sep 25, 2019
a053c95
refactoring, still work in progress
KsavinN Sep 27, 2019
c8c3a85
Export debugger sidebar.
afshin Sep 27, 2019
a2d10a6
next refactor
KsavinN Sep 27, 2019
e6c6fa9
Merge branch 'debugger-ui' of https://github.com/afshin/debugger into…
KsavinN Sep 27, 2019
933fade
delete breakpointService , set sidebar in to model of Debuger
KsavinN Sep 27, 2019
0297d8d
add Tracker for handlers between console/notebook
KsavinN Sep 30, 2019
2915521
fix line numbers for breakpoints
KsavinN Oct 1, 2019
85d59d9
fix line numbers for breakpoints
KsavinN Oct 1, 2019
f0f1186
Merge branch 'debugger-ui' of github.com:KsavinN/debugger into debugg…
KsavinN Oct 1, 2019
28bdc70
fix edge cases
KsavinN Oct 1, 2019
9355956
Add sessionChanged signal.
afshin Oct 1, 2019
1baa7f4
set session only in debugger model
KsavinN Oct 1, 2019
d7071cc
set session only in debugger model
KsavinN Oct 1, 2019
79cbf93
Merge branch 'debugger-ui' of github.com:KsavinN/debugger into debugg…
KsavinN Oct 1, 2019
6cd90a5
add debugger widget to main
KsavinN Oct 2, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"@phosphor/coreutils": "^1.3.1",
"@phosphor/disposable": "^1.2.0",
"@phosphor/widgets": "^1.8.0",
"@types/codemirror": "0.0.76",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go to devDependencies

"vscode-debugprotocol": "1.35.0"
},
"devDependencies": {
Expand Down
16 changes: 8 additions & 8 deletions src/breakpoints/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ArrayExt } from '@phosphor/algorithm';
import { ISignal } from '@phosphor/signaling';

export class Body extends ReactWidget {
constructor(model: Breakpoints.IModel) {
constructor(model: Breakpoints.Model) {
super();
this.model = model;
this.addClass('jp-DebuggerBreakpoints-body');
Expand All @@ -18,14 +18,14 @@ export class Body extends ReactWidget {
return <BreakpointsComponent model={this.model} />;
}

readonly model: Breakpoints.IModel;
readonly model: Breakpoints.Model;
}

const BreakpointsComponent = ({ model }: { model: Breakpoints.IModel }) => {
const BreakpointsComponent = ({ model }: { model: Breakpoints.Model }) => {
const [breakpoints, setBreakpoints] = useState(model.breakpoints);

model.breakpointsChanged.connect(
(_: Breakpoints.IModel, updates: Breakpoints.IBreakpoint[]) => {
(_: Breakpoints.Model, updates: Breakpoints.IBreakpoint[]) => {
if (ArrayExt.shallowEqual(breakpoints, updates)) {
return;
}
Expand All @@ -35,9 +35,9 @@ const BreakpointsComponent = ({ model }: { model: Breakpoints.IModel }) => {

return (
<div>
{breakpoints.map((breakpoint: any) => (
{breakpoints.map((breakpoint: Breakpoints.IBreakpoint) => (
<BreakpointComponent
key={breakpoint.id}
key={breakpoint.line}
breakpoint={breakpoint}
breakpointChanged={model.breakpointChanged}
/>
Expand All @@ -51,13 +51,13 @@ const BreakpointComponent = ({
breakpointChanged
}: {
breakpoint: Breakpoints.IBreakpoint;
breakpointChanged: ISignal<Breakpoints.IModel, Breakpoints.IBreakpoint>;
breakpointChanged: ISignal<Breakpoints.Model, Breakpoints.IBreakpoint>;
}) => {
const [active, setActive] = useState(breakpoint.active);
breakpoint.active = active;

breakpointChanged.connect(
(_: Breakpoints.IModel, updates: Breakpoints.IBreakpoint) => {
(_: Breakpoints.Model, updates: Breakpoints.IBreakpoint) => {
setActive(updates.active);
}
);
Expand Down
123 changes: 78 additions & 45 deletions src/breakpoints/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { Toolbar, ToolbarButton } from '@jupyterlab/apputils';
import { Widget, Panel, PanelLayout } from '@phosphor/widgets';
import { DebugProtocol } from 'vscode-debugprotocol';
import { Body } from './body';
import { Signal, ISignal } from '@phosphor/signaling';
import { Signal } from '@phosphor/signaling';
import { LineInfo } from '../handlers/cell';

// import { BreakpointsService } from '../breakpointsService';

export class Breakpoints extends Panel {
constructor(options: Breakpoints.IOptions = {}) {
constructor(options: Breakpoints.IOptions) {
super();

this.model = new Breakpoints.IModel(MOCK_BREAKPOINTS);
this.model = new Breakpoints.Model([]);
this.addClass('jp-DebuggerBreakpoints');
this.title.label = 'Breakpoints';

Expand Down Expand Up @@ -42,7 +44,7 @@ export class Breakpoints extends Panel {
new ToolbarButton({
iconClassName: 'jp-CloseAllIcon',
onClick: () => {
this.model.breakpoints = [];
this.model.clearSelectedBreakpoints();
},
tooltip: 'Remove All Breakpoints'
})
Expand All @@ -51,7 +53,7 @@ export class Breakpoints extends Panel {

private isAllActive = true;
readonly body: Widget;
readonly model: Breakpoints.IModel;
readonly model: Breakpoints.Model;
}

class BreakpointsHeader extends Widget {
Expand All @@ -75,44 +77,94 @@ export namespace Breakpoints {
active: boolean;
}

/**
* The breakpoints UI model.
*/
export interface IModel {}

export class IModel implements IModel {
export class Model {
constructor(model: IBreakpoint[]) {
this._state = model;
}

get breakpointsChanged(): ISignal<this, IBreakpoint[]> {
return this._breakpointsChanged;
this._breakpoints = model;
}

get breakpoints(): IBreakpoint[] {
return this._state;
return this._breakpoints;
}

get breakpointChanged(): ISignal<this, IBreakpoint> {
get breakpointChanged(): Signal<this, IBreakpoint> {
return this._breakpointChanged;
}

set breakpoints(breakpoints: IBreakpoint[]) {
this._state = breakpoints;
this._breakpointsChanged.emit(this._state);
this._breakpoints = [...breakpoints];
this.breakpointsChanged.emit(this._breakpoints);
}

set breakpoint(breakpoint: IBreakpoint) {
const index = this._state.findIndex(ele => ele.id === breakpoint.id);
const index = this._breakpoints.findIndex(
ele => ele.line === breakpoint.line
);
if (index !== -1) {
this._state[index] = breakpoint;
this._breakpoints[index] = breakpoint;
this._breakpointChanged.emit(breakpoint);
} else {
this.breakpoints = [...this.breakpoints, breakpoint];
}
}

addBreakpoint(session: string, type: string, lineInfo: LineInfo) {
const breakpoint: Breakpoints.IBreakpoint = {
line: lineInfo.line + 1,
active: true,
verified: true,
source: {
name: session
}
};
this.breakpoints = [...this._breakpoints, breakpoint];
}

set type(newType: SessionTypes) {
if (newType === this.selectedType) {
return;
}
this.state[this.selectedType] = this.breakpoints;
this.selectedType = newType;
this.breakpoints = this.state[newType];
}

removeBreakpoint(lineInfo: any) {
const breakpoints = this.breakpoints.filter(
ele => ele.line !== lineInfo.line + 1
);
this.breakpoints = breakpoints;
}

clearSelectedBreakpoints() {
this.breakpoints = [];
Copy link
Member

@jtpio jtpio Sep 4, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as above

this.clearedBreakpoints.emit(this.selectedType);
}

private _state: IBreakpoint[];
private _breakpointsChanged = new Signal<this, IBreakpoint[]>(this);
changeLines(linesInfo: LineInfo[]) {
if (!linesInfo && this.breakpoints.length === 0) {
return;
}
if (linesInfo.length === 0) {
this.breakpoints = [];
} else {
const breakpoint = { ...this.breakpoints[0] };
let breakpoints: Breakpoints.IBreakpoint[] = [];
linesInfo.forEach(ele => {
breakpoints.push({ ...breakpoint, line: ele.line + 1 });
});
this.breakpoints = [...breakpoints];
}
}

private _breakpoints: IBreakpoint[];
breakpointsChanged = new Signal<this, IBreakpoint[]>(this);
clearedBreakpoints = new Signal<this, SessionTypes | null>(this);
private selectedType: SessionTypes;
private _breakpointChanged = new Signal<this, IBreakpoint>(this);
private state = {
console: [] as Breakpoints.IBreakpoint[],
notebook: [] as Breakpoints.IBreakpoint[]
};
}

/**
Expand All @@ -121,23 +173,4 @@ export namespace Breakpoints {
export interface IOptions extends Panel.IOptions {}
}

const MOCK_BREAKPOINTS = [
{
id: 0,
active: true,
verified: true,
source: {
name: 'untitled.py'
},
line: 6
},
{
id: 1,
verified: true,
active: false,
source: {
name: 'untitled.py'
},
line: 7
}
];
export type SessionTypes = 'console' | 'notebook';
67 changes: 53 additions & 14 deletions src/debugger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@

import { IDataConnector } from '@jupyterlab/coreutils';

import { BoxPanel, TabPanel } from '@phosphor/widgets';
import { ReadonlyJSONValue } from '@phosphor/coreutils';

import { ReadonlyJSONValue, UUID } from '@phosphor/coreutils';
import { INotebookTracker } from '@jupyterlab/notebook';

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

import { IDisposable } from '@phosphor/disposable';

import { DebuggerSidebar } from './sidebar';
import { ISignal, Signal } from '@phosphor/signaling';

export class Debugger extends BoxPanel {
readonly model: Debugger.Model;
import { BoxPanel } from '@phosphor/widgets';

readonly tabs = new TabPanel();
import { DebugSession } from './session';

readonly sidebar: DebuggerSidebar;
import { IDebuggerSidebar } from './tokens';

export class Debugger extends BoxPanel {
constructor(options: Debugger.IOptions) {
super({ direction: 'left-to-right' });

this.model = new Debugger.Model(options);
this.sidebar = new DebuggerSidebar(this.model);
this.title.label = 'Debugger';
// this.sidebar = new DebuggerSidebar(this.model);
this.title.label = 'Debugger-' + options.id;

this.addClass('jp-Debugger');
this.addWidget(this.tabs);
this.addWidget(this.sidebar);
// this.addWidget(this.sidebar);
}

readonly model: Debugger.Model;

dispose(): void {
if (this.isDisposed) {
return;
Expand All @@ -45,25 +47,58 @@ export class Debugger extends BoxPanel {
export namespace Debugger {
export interface IOptions {
connector?: IDataConnector<ReadonlyJSONValue>;

id?: string;
session?: IClientSession;
sidebar?: IDebuggerSidebar;
}

export class Model implements IDisposable {
constructor(options: Debugger.Model.IOptions) {
this.connector = options.connector || null;
this.id = options.id || UUID.uuid4();
this.session = new DebugSession({ client: options.session });
this.id = options.id;
void this._populate();
}

readonly connector: IDataConnector<ReadonlyJSONValue> | null;

readonly id: string;

get sidebar() {
return this._sidebar;
}

set sidebar(newSidebar: IDebuggerSidebar) {
this._sidebar = newSidebar;
}

get session() {
return this._session;
}

set session(session: DebugSession | null) {
if (this._session === session) {
return;
}
if (this._session) {
this._session.dispose();
}
this._session = session;
this._sessionChanged.emit(undefined);
}

get sessionChanged(): ISignal<this, void> {
return this._sessionChanged;
}

get isDisposed(): boolean {
return this._isDisposed;
}

get notebookTracker() {
return this._notebook;
}

dispose(): void {
this._isDisposed = true;
}
Expand All @@ -77,6 +112,10 @@ export namespace Debugger {
}

private _isDisposed = false;
private _notebook: INotebookTracker;
private _session: DebugSession | null;
private _sessionChanged = new Signal<this, void>(this);
private _sidebar: IDebuggerSidebar;
}

export namespace Model {
Expand Down