فهرست منبع

check type of kernel and set breakpoints

Borys Palka 5 سال پیش
والد
کامیت
fe547a4116
3فایلهای تغییر یافته به همراه36 افزوده شده و 25 حذف شده
  1. 13 14
      src/breakpointsService.ts
  2. 1 3
      src/cellManeger/index.ts
  3. 22 8
      src/index.ts

+ 13 - 14
src/breakpointsService.ts

@@ -8,13 +8,15 @@ import { LineInfo } from './cellManeger';
 export class BreakpointsService {
   constructor() {}
 
-  selectedType: SessionTypes;
-  selectedBreakpoints: Breakpoints.IBreakpoint[] = [];
-
+  private selectedType: SessionTypes;
+  private state = {
+    console: [] as Breakpoints.IBreakpoint[],
+    notebook: [] as Breakpoints.IBreakpoint[]
+  };
+  private selectedBreakpoints: Breakpoints.IBreakpoint[] = [];
   selectedBreakpointsChanged = new Signal<this, Breakpoints.IBreakpoint[]>(
     this
   );
-  breakpointChanged = new Signal<this, Breakpoints.IBreakpoint>(this);
 
   addBreakpoint(session_id: string, type: string, lineInfo: LineInfo) {
     const breakpoint: Breakpoints.IBreakpoint = {
@@ -33,13 +35,14 @@ export class BreakpointsService {
     return this.selectedBreakpoints;
   }
 
-  onSelectedBreakpoints(session_id: string, type: SessionTypes) {
-    // this still not work
-
-    this.selectedType = type;
-    if (this.selectedType && this.selectedType !== type) {
-      this.clearSelectedBreakpoints();
+  set type(newType: SessionTypes) {
+    if (newType === this.selectedType) {
+      return;
     }
+    this.state[this.selectedType] = this.selectedBreakpoints;
+    this.selectedType = newType;
+    this.selectedBreakpoints = this.state[newType];
+    this.selectedBreakpointsChanged.emit(this.selectedBreakpoints);
   }
 
   removeBreakpoint(session_id: any, editor_id: any, lineInfo: any) {
@@ -49,10 +52,6 @@ export class BreakpointsService {
     this.selectedBreakpointsChanged.emit(this.selectedBreakpoints);
   }
 
-  getBreakpointState(session_id: any, editor_id: any, lineInfo: any) {}
-
-  setBreakpointState(session_id: any, editor_id: any, lineInfo: any) {}
-
   clearSelectedBreakpoints() {
     this.selectedBreakpoints = [];
     this.selectedBreakpointsChanged.emit([]);

+ 1 - 3
src/cellManeger/index.ts

@@ -4,7 +4,7 @@
 import { CodeCell } from '@jupyterlab/cells';
 import { CodeMirrorEditor } from '@jupyterlab/codemirror';
 import { Editor, Doc } from 'codemirror';
-import { BreakpointsService, SessionTypes } from '../breakpointsService';
+import { BreakpointsService } from '../breakpointsService';
 import { DebugSession } from '../session';
 
 export class CellManager {
@@ -57,8 +57,6 @@ export class CellManager {
 
   onActiveCellChanged() {
     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);

+ 22 - 8
src/index.ts

@@ -4,20 +4,21 @@
 import {
   ILayoutRestorer,
   JupyterFrontEnd,
-  JupyterFrontEndPlugin
+  JupyterFrontEndPlugin,
+  LabShell
 } from '@jupyterlab/application';
 
 import { ICommandPalette } from '@jupyterlab/apputils';
 
 import { WidgetTracker, MainAreaWidget } from '@jupyterlab/apputils';
 
-import { IConsoleTracker } from '@jupyterlab/console';
+import { IConsoleTracker, ConsolePanel } from '@jupyterlab/console';
 
 import { IStateDB } from '@jupyterlab/coreutils';
 
 import { IEditorTracker } from '@jupyterlab/fileeditor';
 
-import { INotebookTracker } from '@jupyterlab/notebook';
+import { INotebookTracker, NotebookPanel } from '@jupyterlab/notebook';
 
 import { Debugger } from './debugger';
 
@@ -25,7 +26,8 @@ import { Debugger } from './debugger';
 
 import { IDebugger, IDebuggerSidebar } from './tokens';
 import { DebuggerNotebookTracker } from './notebookTracker';
-import { BreakpointsService } from './breakpointsService';
+import { BreakpointsService, SessionTypes } from './breakpointsService';
+
 import { DebuggerConsoleTracker } from './consoleTracker';
 
 // import { ClientSession, IClientSession } from '@jupyterlab/apputils';
@@ -54,7 +56,7 @@ const breakpointService = new BreakpointsService();
 const consoles: JupyterFrontEndPlugin<void> = {
   id: '@jupyterlab/debugger:consoles',
   autoStart: true,
-  requires: [IDebugger, IConsoleTracker, IEditorTracker],
+  requires: [IDebugger, IConsoleTracker],
   activate: (_, debug, tracker: IConsoleTracker) => {
     new DebuggerConsoleTracker({
       consoleTracker: tracker,
@@ -69,8 +71,21 @@ const consoles: JupyterFrontEndPlugin<void> = {
 const files: JupyterFrontEndPlugin<void> = {
   id: '@jupyterlab/debugger:files',
   autoStart: true,
-  optional: [IEditorTracker],
+  requires: [IEditorTracker],
   activate: (app: JupyterFrontEnd, tracker: IEditorTracker | null) => {
+    const shell = app.shell;
+
+    (shell as LabShell).currentChanged.connect((sender, update) => {
+      const newWidget = update.newValue;
+      const session =
+        newWidget && (newWidget as NotebookPanel | ConsolePanel).session
+          ? (newWidget as NotebookPanel | ConsolePanel).session
+          : false;
+      if (session) {
+        breakpointService.type = session.type as SessionTypes;
+      }
+    });
+
     app.commands.addCommand(CommandIDs.debugFile, {
       execute: async _ => {
         if (!tracker || !tracker.currentWidget) {
@@ -105,7 +120,6 @@ const notebooks: JupyterFrontEndPlugin<void> = {
       breakpointService: breakpointService
     });
 
-    // console.log(debugetNoteTracker);
     // this exist only for my test in futre will be removed
     const command: string = CommandIDs.debugNotebook;
     app.commands.addCommand(command, {
@@ -122,7 +136,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
  */
 const sidebar: JupyterFrontEndPlugin<Debugger> = {
   id: '@jupyterlab/debugger:sidebar',
-  optional: [ILayoutRestorer, INotebookTracker, IEditorTracker],
+  optional: [ILayoutRestorer],
   autoStart: true,
   activate: (
     app: JupyterFrontEnd,