浏览代码

add breakpointservice

Borys Palka 5 年之前
父节点
当前提交
7dd37525d7
共有 3 个文件被更改,包括 74 次插入13 次删除
  1. 14 0
      src/breakpointsService.ts
  2. 49 9
      src/notebookTracker/index.ts
  3. 11 4
      src/session.ts

+ 14 - 0
src/breakpointsService.ts

@@ -0,0 +1,14 @@
+// Copyright (c) Jupyter Development Team.
+// Distributed under the terms of the Modified BSD License.
+
+export class BreakpointsService {
+  constructor() {}
+
+  addBreakpoint() {}
+
+  removeBreakpoint() {}
+
+  getBreakpointState() {}
+
+  setBreakpointState() {}
+}

+ 49 - 9
src/notebookTracker/index.ts

@@ -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';

+ 11 - 4
src/session.ts

@@ -21,16 +21,22 @@ export class DebugSession implements IDebugger.ISession {
    */
   constructor(options: DebugSession.IOptions) {
     this.client = options.client;
-    this.path = this.client.path || '';
-    this.type = this.client.type;
+    this.id = this.client.name;
   }
 
   /**
    * The client session to connect to a debugger.
    */
   private _client: IClientSession;
-  type: string;
-  path?: string;
+  private _id: string;
+
+  get id() {
+    return this._id;
+  }
+
+  set id(id: string) {
+    this._id = id;
+  }
 
   get client(): IClientSession {
     return this._client;
@@ -46,6 +52,7 @@ export class DebugSession implements IDebugger.ISession {
     }
 
     this._client = client;
+    this._id = client.name;
     this._client.iopubMessage.connect(this._handleEvent, this);
   }