|
@@ -6,16 +6,14 @@ import { CodeCell } from '@jupyterlab/cells';
|
|
|
import { CodeMirrorEditor } from '@jupyterlab/codemirror';
|
|
|
import { Editor, Doc } from 'codemirror';
|
|
|
import { DebugSession } from './../session';
|
|
|
+import { Breakpoints } from '../breakpoints';
|
|
|
|
|
|
export class DebuggerNotebookTracker {
|
|
|
constructor(options: DebuggerNotebookTracker.IOptions) {
|
|
|
this.notebookTracker = options.notebookTracker;
|
|
|
this.notebookTracker.widgetAdded.connect(
|
|
|
- (sender, notePanel: NotebookPanel) => {}
|
|
|
- );
|
|
|
-
|
|
|
- this.notebookTracker.currentChanged.connect(
|
|
|
(sender, notePanel: NotebookPanel) => {
|
|
|
+ console.log('first');
|
|
|
if (!this.debuggerSession) {
|
|
|
this.debuggerSession = new DebugSession({
|
|
|
client: notePanel.session
|
|
@@ -25,6 +23,12 @@ export class DebuggerNotebookTracker {
|
|
|
}
|
|
|
);
|
|
|
|
|
|
+ // this.notebookTracker.currentChanged.connect(
|
|
|
+ // (sender, notePanel: NotebookPanel) => {
|
|
|
+
|
|
|
+ // }
|
|
|
+ // );
|
|
|
+
|
|
|
this.notebookTracker.activeCellChanged.connect(
|
|
|
this.onActiveCellChanged,
|
|
|
this
|
|
@@ -36,14 +40,17 @@ export class DebuggerNotebookTracker {
|
|
|
debuggerSession: DebugSession;
|
|
|
|
|
|
protected onActiveCellChanged() {
|
|
|
+ console.log('second');
|
|
|
const activeCell = this.getCell();
|
|
|
- if (activeCell) {
|
|
|
+ if (activeCell && activeCell.editor && this.debuggerSession) {
|
|
|
if (this.previousCell && !this.previousCell.isDisposed) {
|
|
|
this.removeListner(this.previousCell);
|
|
|
}
|
|
|
this.previousCell = activeCell;
|
|
|
+ // console.log(activeCell.editor.uuid);
|
|
|
this.setEditor(activeCell);
|
|
|
}
|
|
|
+ // console.log(this.debuggerSession);
|
|
|
}
|
|
|
|
|
|
protected setEditor(cell: CodeCell) {
|
|
@@ -52,6 +59,9 @@ export class DebuggerNotebookTracker {
|
|
|
}
|
|
|
|
|
|
const editor = cell.editor as CodeMirrorEditor;
|
|
|
+
|
|
|
+ this.previousLineCount = editor.lineCount;
|
|
|
+
|
|
|
editor.setOption('lineNumbers', true);
|
|
|
editor.editor.setOption('gutters', [
|
|
|
'CodeMirror-linenumbers',
|
|
@@ -59,20 +69,24 @@ export class DebuggerNotebookTracker {
|
|
|
]);
|
|
|
|
|
|
editor.editor.on('gutterClick', this.onGutterClick);
|
|
|
- // editor.editor.on('renderLine', this.onNewRenderLine);
|
|
|
+ editor.editor.on('renderLine', this.onNewRenderLine);
|
|
|
}
|
|
|
|
|
|
protected removeListner(cell: CodeCell) {
|
|
|
const editor = cell.editor as CodeMirrorEditor;
|
|
|
editor.setOption('lineNumbers', false);
|
|
|
editor.editor.off('gutterClick', this.onGutterClick);
|
|
|
- // editor.editor.off('renderLine', this.onNewRenderLine);
|
|
|
+ editor.editor.off('renderLine', this.onNewRenderLine);
|
|
|
}
|
|
|
|
|
|
protected getCell(): CodeCell {
|
|
|
return this.notebookTracker.activeCell as CodeCell;
|
|
|
}
|
|
|
|
|
|
+ protected getEditorId(): string {
|
|
|
+ return this.getCell().editor.uuid;
|
|
|
+ }
|
|
|
+
|
|
|
protected getCurrentNoteBook(): NotebookPanel {
|
|
|
return this.notebookTracker.currentWidget;
|
|
|
}
|
|
@@ -82,7 +96,13 @@ export class DebuggerNotebookTracker {
|
|
|
if (!info) {
|
|
|
return;
|
|
|
}
|
|
|
+
|
|
|
const isRemoveGutter = !!info.gutterMarkers;
|
|
|
+ if (isRemoveGutter) {
|
|
|
+ this.removeBreakpoint(lineNumber);
|
|
|
+ } else {
|
|
|
+ this.addBreakpoint(lineNumber);
|
|
|
+ }
|
|
|
|
|
|
editor.setGutterMarker(
|
|
|
lineNumber,
|
|
@@ -91,6 +111,10 @@ export class DebuggerNotebookTracker {
|
|
|
);
|
|
|
};
|
|
|
|
|
|
+ protected removeBreakpoint(lineNumber: number) {}
|
|
|
+
|
|
|
+ protected addBreakpoint(lineNumber: number) {}
|
|
|
+
|
|
|
protected onNewRenderLine = (editor: Editor, line: any) => {
|
|
|
const lineInfo = editor.lineInfo(line);
|
|
|
if (lineInfo.handle && lineInfo.handle.order === false) {
|
|
@@ -101,10 +125,10 @@ export class DebuggerNotebookTracker {
|
|
|
const linesNumber = doc.lineCount();
|
|
|
|
|
|
if (this.previousLineCount !== linesNumber) {
|
|
|
- if (this.previousLineCount > linesNumber) {
|
|
|
- }
|
|
|
if (this.previousLineCount < linesNumber) {
|
|
|
}
|
|
|
+ if (this.previousLineCount > linesNumber) {
|
|
|
+ }
|
|
|
this.previousLineCount = linesNumber;
|
|
|
}
|
|
|
// eage case for backspace line 2
|
|
@@ -112,6 +136,22 @@ export class DebuggerNotebookTracker {
|
|
|
}
|
|
|
};
|
|
|
|
|
|
+ protected changeLines(
|
|
|
+ breakpoints: Breakpoints.IBreakpoint[],
|
|
|
+ lineInfo: any,
|
|
|
+ sign: number
|
|
|
+ ) {
|
|
|
+ breakpoints.map(ele => {
|
|
|
+ if (
|
|
|
+ ele.line > lineInfo.line ||
|
|
|
+ (lineInfo.text === '' && lineInfo.line === ele.line)
|
|
|
+ ) {
|
|
|
+ ele.line = ele.line + sign;
|
|
|
+ }
|
|
|
+ return ele;
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
private createMarkerNode() {
|
|
|
var marker = document.createElement('div');
|
|
|
marker.className = 'jp-breakpoint-marker';
|