Przeglądaj źródła

add commendt to start debbuger session

Borys Palka 5 lat temu
rodzic
commit
d550da0693
2 zmienionych plików z 51 dodań i 14 usunięć
  1. 2 0
      src/handlers/cell.ts
  2. 49 14
      src/index.ts

+ 2 - 0
src/handlers/cell.ts

@@ -60,8 +60,10 @@ export class CellManager {
   }
 
   onActiveCellChanged() {
+    console.log({ cell: this.activeCell });
     if (
       this.activeCell &&
+      this.activeCell.isAttached &&
       this.activeCell.editor &&
       this._debuggerModel &&
       this._debuggerModel.session

+ 49 - 14
src/index.ts

@@ -34,6 +34,7 @@ import { DebuggerSidebar } from './sidebar';
 
 import { SessionTypes } from './breakpoints';
 import { DebugSession } from './session';
+import { IDisposable } from '@phosphor/disposable';
 
 /**
  * The command IDs used by the debugger plugin.
@@ -41,6 +42,10 @@ import { DebugSession } from './session';
 export namespace CommandIDs {
   export const create = 'debugger:create';
 
+  export const start = 'debugger:start';
+
+  export const stop = 'debugger:stop';
+
   export const debugConsole = 'debugger:debug-console';
 
   export const debugFile = 'debugger:debug-file';
@@ -149,15 +154,6 @@ const notebooks: JupyterFrontEndPlugin<void> = {
     //   // Manages life cycle signal connections.
     //   // Manages variables
     // });
-
-    // this exist only for my test in futre will be removed
-    const command: string = CommandIDs.debugNotebook;
-    app.commands.addCommand(command, {
-      label: 'test',
-      execute: () => {}
-    });
-
-    palette.addItem({ command, category: 'dev test' });
   }
 };
 
@@ -212,9 +208,45 @@ const tracker: JupyterFrontEndPlugin<IDebugger> = {
       update;
     });
 
-    const command = CommandIDs.create;
+    const commandCreateDebugger = CommandIDs.create;
+
+    const commandStartDebugger = CommandIDs.start;
+
+    const commandStopDebugger = CommandIDs.stop;
+
+    var commandStop: IDisposable;
+
+    const getModel = () => {
+      return tracker.currentWidget ? tracker.currentWidget.content.model : null;
+    };
+
+    app.commands.addCommand(commandStopDebugger, {
+      label: 'Stop',
+      execute: async () => {
+        const debuggerModel = getModel();
+
+        if (debuggerModel) {
+          await debuggerModel.session.stop();
+          commandStop.dispose();
+        }
+      }
+    });
+
+    app.commands.addCommand(commandStartDebugger, {
+      label: 'Start',
+      execute: async () => {
+        const debuggerModel = getModel();
+        if (debuggerModel) {
+          await debuggerModel.session.start();
+          commandStop = await palette.addItem({
+            command: commandStopDebugger,
+            category: 'Debugger'
+          });
+        }
+      }
+    });
 
-    app.commands.addCommand(command, {
+    app.commands.addCommand(commandCreateDebugger, {
       label: 'Debugger',
       execute: args => {
         const id = (args.id as string) || UUID.uuid4();
@@ -225,7 +257,6 @@ const tracker: JupyterFrontEndPlugin<IDebugger> = {
         const existedWidget = tracker.find(
           widget => id === widget.content.model.id
         );
-
         if (existedWidget) {
           app.shell.add(existedWidget, 'main');
           return;
@@ -245,12 +276,16 @@ const tracker: JupyterFrontEndPlugin<IDebugger> = {
       }
     });
 
-    palette.addItem({ command, category: 'Debugger' });
+    palette.addItem({ command: commandCreateDebugger, category: 'Debugger' });
+    palette.addItem({
+      command: commandStartDebugger,
+      category: 'Debugger'
+    });
 
     if (restorer) {
       // Handle state restoration.
       void restorer.restore(tracker, {
-        command: command,
+        command: commandCreateDebugger,
         args: widget => ({ id: widget.content.model.id }),
         name: widget => widget.content.model.id
       });