Forráskód Böngészése

debug consoleTracker

Borys Palka 5 éve
szülő
commit
951a239ff0

+ 9 - 27
src/breakpointsService.ts

@@ -8,7 +8,7 @@ import { LineInfo } from './cellManeger';
 export class BreakpointsService {
   constructor() {}
 
-  state: any = {};
+  selectedType: SessionTypes;
   selectedBreakpoints: Breakpoints.IBreakpoint[] = [];
 
   selectedBreakpointsChanged = new Signal<this, Breakpoints.IBreakpoint[]>(
@@ -16,7 +16,7 @@ export class BreakpointsService {
   );
   breakpointChanged = new Signal<this, Breakpoints.IBreakpoint>(this);
 
-  addBreakpoint(session_id: string, editor_id: string, lineInfo: LineInfo) {
+  addBreakpoint(session_id: string, type: string, lineInfo: LineInfo) {
     const breakpoint: Breakpoints.IBreakpoint = {
       line: lineInfo.line,
       active: true,
@@ -33,16 +33,12 @@ export class BreakpointsService {
     return this.selectedBreakpoints;
   }
 
-  onSelectedBreakpoints(session_id: string, editor_id: string) {
-    if (!this.state[session_id]) {
-      this.state[session_id] = {};
-      if (!this.state[session_id][editor_id]) {
-        this.state[session_id][editor_id] = [];
-      }
-    } else {
-      if (!this.state[session_id][editor_id]) {
-        this.state[session_id][editor_id] = [];
-      }
+  onSelectedBreakpoints(session_id: string, type: SessionTypes) {
+    // this still not work
+
+    this.selectedType = type;
+    if (this.selectedType && this.selectedType !== type) {
+      this.clearSelectedBreakpoints();
     }
   }
 
@@ -81,18 +77,4 @@ export class BreakpointsService {
   }
 }
 
-// changeLines(lineInfo: LineInfo, sign: number) {
-//   const breakpoints = this.selectedBreakpoints.map(ele => {
-//     if (
-//       ele.line > lineInfo.line ||
-//       (lineInfo.text === '' && lineInfo.line === ele.line)
-//     ) {
-//       ele.line = ele.line + sign;
-//     }
-//     if (ele.line > 0) {
-//       return ele;
-//     }
-//   });
-//   this.selectedBreakpoints = [...breakpoints];
-//   this.selectedBreakpointsChanged.emit(this.selectedBreakpoints);
-// }
+export type SessionTypes = 'console' | 'notebook';

+ 14 - 16
src/cellManeger/index.ts

@@ -4,20 +4,20 @@
 import { CodeCell } from '@jupyterlab/cells';
 import { CodeMirrorEditor } from '@jupyterlab/codemirror';
 import { Editor, Doc } from 'codemirror';
-import { BreakpointsService } from '../breakpointsService';
+import { BreakpointsService, SessionTypes } from '../breakpointsService';
+import { DebugSession } from '../session';
 
 export class CellManager {
   constructor(options: CellManager.IOptions) {
     this.breakpointService = options.breakpointService;
     this.activeCell = options.activeCell;
-    this.debuggerSessionId = options.sessionId;
+    this.debuggerSession = options.session;
     this.onActiveCellChanged();
-    console.log('new Cell manager');
   }
 
   private _previousCell: CodeCell;
   previousLineCount: number;
-  private _debuggerSessionId: string;
+  private _debuggerSession: DebugSession;
   breakpointService: BreakpointsService;
   private _activeCell: CodeCell;
 
@@ -29,12 +29,12 @@ export class CellManager {
     return this._previousCell;
   }
 
-  set debuggerSessionId(id: string) {
-    this._debuggerSessionId = id;
+  set debuggerSession(session: DebugSession) {
+    this._debuggerSession = session;
   }
 
-  get debuggerSessionId() {
-    return this._debuggerSessionId;
+  get debuggerSession() {
+    return this._debuggerSession;
   }
 
   set activeCell(cell: CodeCell) {
@@ -56,11 +56,9 @@ export class CellManager {
   }
 
   onActiveCellChanged() {
-    if (this.activeCell && this.activeCell.editor && this.debuggerSessionId) {
-      this.breakpointService.onSelectedBreakpoints(
-        this.debuggerSessionId,
-        this.getEditorId()
-      );
+    if (this.activeCell && this.activeCell.editor && this.debuggerSession) {
+      this.breakpointService.onSelectedBreakpoints(this.debuggerSession.id, this
+        .debuggerSession.type as SessionTypes);
       if (this.previousCell && !this.previousCell.isDisposed) {
         this.removeListner(this.previousCell);
         this.clearGutter(this.previousCell);
@@ -114,13 +112,13 @@ export class CellManager {
     const isRemoveGutter = !!info.gutterMarkers;
     if (isRemoveGutter) {
       this.breakpointService.removeBreakpoint(
-        this.debuggerSessionId,
+        this.debuggerSession,
         this.getEditorId,
         info as LineInfo
       );
     } else {
       this.breakpointService.addBreakpoint(
-        this.debuggerSessionId,
+        this.debuggerSession.id,
         this.getEditorId(),
         info as LineInfo
       );
@@ -162,7 +160,7 @@ export class CellManager {
 
 export namespace CellManager {
   export interface IOptions {
-    sessionId: string;
+    session: DebugSession;
     breakpointService: BreakpointsService;
     activeCell?: CodeCell;
   }

+ 4 - 5
src/consoleTracker/index.ts

@@ -36,9 +36,8 @@ export class DebuggerConsoleTracker {
     consolePanel: ConsolePanel,
     widgetTrack: WidgetTracker
   ) {
-    console.log('current change');
     this.consoleSession = consolePanel ? consolePanel.session : false;
-    if (this.debuggerSession) {
+    if (this.debuggerSession && this.consoleSession) {
       this.debuggerSession.dispose();
       this.debuggerSession = new DebugSession({
         client: this.consoleSession as IClientSession
@@ -49,12 +48,12 @@ export class DebuggerConsoleTracker {
           this
         );
         if (consolePanel.console.promptCell) {
-          this.cellManager.debuggerSessionId = this.debuggerSession.id;
+          this.cellManager.debuggerSession = this.debuggerSession;
           this.cellManager.previousCell = this.cellManager.activeCell;
           this.cellManager.activeCell = consolePanel.console.promptCell;
         }
       }
-    } else {
+    } else if (this.consoleSession) {
       this.debuggerSession = new DebugSession({
         client: this.consoleSession as IClientSession
       });
@@ -80,7 +79,7 @@ export class DebuggerConsoleTracker {
       this.cellManager = new CellManager({
         activeCell: update,
         breakpointService: this.breakpointService,
-        sessionId: this.debuggerSession.id
+        session: this.debuggerSession
       });
     }
   }

+ 2 - 2
src/notebookTracker/index.ts

@@ -34,14 +34,14 @@ export class DebuggerNotebookTracker {
   protected onNewCell(noteTracker: NotebookTracker, codeCell: CodeCell) {
     setTimeout(() => {
       if (this.cellManager) {
-        this.cellManager.debuggerSessionId = this.debuggerSession.id;
+        this.cellManager.debuggerSession = this.debuggerSession;
         this.cellManager.activeCell = codeCell;
         this.cellManager.onActiveCellChanged();
       } else {
         const options: CellManager.IOptions = {
           breakpointService: this.breakpointService,
           activeCell: codeCell,
-          sessionId: this.debuggerSession.id
+          session: this.debuggerSession
         };
         this.cellManager = new CellManager(options);
       }

+ 4 - 0
src/session.ts

@@ -32,6 +32,10 @@ export class DebugSession implements IDebugger.ISession {
     return this.client.name;
   }
 
+  get type() {
+    return this.client.type;
+  }
+
   get client(): IClientSession {
     return this._client;
   }