Quellcode durchsuchen

Merge pull request #16 from jupyterlab/master

get iterration
KsavinN vor 5 Jahren
Ursprung
Commit
b03f19fab9
8 geänderte Dateien mit 94 neuen und 30 gelöschten Zeilen
  1. 1 1
      azure-pipelines.yml
  2. 10 3
      src/debugger.ts
  3. 2 2
      src/handlers/console.ts
  4. 18 20
      src/index.ts
  5. 12 0
      src/session.ts
  6. 33 4
      src/tokens.ts
  7. 4 0
      style/index.css
  8. 14 0
      tests/src/session.spec.ts

+ 1 - 1
azure-pipelines.yml

@@ -16,7 +16,7 @@ steps:
 
 - bash: |
     source activate jupyterlab-debugger
-    conda install --yes --quiet -c conda-forge nodejs xeus-python=0.5.3 ptvsd python=$PYTHON_VERSION
+    conda install --yes --quiet -c conda-forge nodejs xeus-python=0.6.1 ptvsd python=$PYTHON_VERSION
     python -m pip install -U --pre jupyterlab
   displayName: Install dependencies
 

+ 10 - 3
src/debugger.ts

@@ -11,9 +11,11 @@ import { IClientSession } from '@jupyterlab/apputils';
 
 import { IDisposable } from '@phosphor/disposable';
 
+import { Message } from '@phosphor/messaging';
+
 import { ISignal, Signal } from '@phosphor/signaling';
 
-import { BoxPanel } from '@phosphor/widgets';
+import { SplitPanel } from '@phosphor/widgets';
 
 import { DebuggerEditors } from './editors';
 
@@ -21,9 +23,9 @@ import { DebuggerSidebar } from './sidebar';
 
 import { IDebugger } from './tokens';
 
-export class Debugger extends BoxPanel {
+export class Debugger extends SplitPanel {
   constructor(options: Debugger.IOptions) {
-    super({ direction: 'left-to-right' });
+    super({ orientation: 'horizontal' });
     this.title.label = 'Debugger';
     this.title.iconClass = 'jp-BugIcon';
 
@@ -50,6 +52,11 @@ export class Debugger extends BoxPanel {
     this.model.dispose();
     super.dispose();
   }
+
+  protected onAfterAttach(msg: Message) {
+    this.addWidget(this.sidebar);
+    this.sidebar.show();
+  }
 }
 
 /**

+ 2 - 2
src/handlers/console.ts

@@ -14,7 +14,7 @@ import { IDisposable } from '@phosphor/disposable';
 import { Signal } from '@phosphor/signaling';
 
 export class DebuggerConsoleHandler implements IDisposable {
-  constructor(options: DebuggerNotebookHandler.IOptions) {
+  constructor(options: DebuggerConsoleHandler.IOptions) {
     this.debuggerModel = options.debuggerModel;
     this.consoleTracker = options.consoleTracker;
     this.breakpoints = this.debuggerModel.sidebar.breakpoints.model;
@@ -60,7 +60,7 @@ export class DebuggerConsoleHandler implements IDisposable {
   }
 }
 
-export namespace DebuggerNotebookHandler {
+export namespace DebuggerConsoleHandler {
   export interface IOptions {
     debuggerModel: Debugger.Model;
     consoleTracker: IConsoleTracker;

+ 18 - 20
src/index.ts

@@ -64,7 +64,7 @@ const consoles: JupyterFrontEndPlugin<void> = {
   autoStart: true,
   requires: [IDebugger, IConsoleTracker, ILabShell],
   activate: (
-    _,
+    app: JupyterFrontEnd,
     debug: IDebugger,
     tracker: IConsoleTracker,
     labShell: ILabShell
@@ -74,7 +74,7 @@ const consoles: JupyterFrontEndPlugin<void> = {
       handler: DebuggerConsoleHandler;
     };
 
-    labShell.currentChanged.connect((_, update) => {
+    labShell.currentChanged.connect(async (_, update) => {
       const widget = update.newValue;
 
       if (!(widget instanceof ConsolePanel)) {
@@ -86,6 +86,10 @@ const consoles: JupyterFrontEndPlugin<void> = {
       } else {
         debug.session.client = widget.session;
       }
+      if (debug.session) {
+        await debug.session.restoreState();
+        app.commands.notifyCommandChanged();
+      }
       if (debug.tracker.currentWidget) {
         const handler = new DebuggerConsoleHandler({
           consoleTracker: tracker,
@@ -163,7 +167,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
   autoStart: true,
   requires: [IDebugger, INotebookTracker, ILabShell],
   activate: (
-    _,
+    app: JupyterFrontEnd,
     debug: IDebugger,
     tracker: INotebookTracker,
     labShell: ILabShell
@@ -173,7 +177,7 @@ const notebooks: JupyterFrontEndPlugin<void> = {
       handler: DebuggerNotebookHandler;
     };
 
-    labShell.currentChanged.connect((_, update) => {
+    labShell.currentChanged.connect(async (_, update) => {
       const widget = update.newValue;
       if (!(widget instanceof NotebookPanel)) {
         return;
@@ -183,6 +187,10 @@ const notebooks: JupyterFrontEndPlugin<void> = {
       } else {
         debug.session.client = widget.session;
       }
+      if (debug.session) {
+        await debug.session.restoreState();
+        app.commands.notifyCommandChanged();
+      }
       if (debug.tracker.currentWidget) {
         const handler = new DebuggerNotebookHandler({
           notebookTracker: tracker,
@@ -253,16 +261,13 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
             sidebar.parent = null;
           }
 
-          // edge case when realod page after set condensed mode
+          // edge case when reload page after set condensed mode
           widget.title.label = 'Debugger';
           shell.add(widget, 'main');
           return;
         }
 
-        if (sidebar.isAttached) {
-          return;
-        }
-
+        // mode = 'condensed'
         if (widget.isAttached) {
           widget.parent = null;
         }
@@ -310,16 +315,9 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
       },
       execute: () => {
         const currentMode = tracker.currentWidget.content.model.mode;
-        tracker.currentWidget.content.model.mode =
-          currentMode === 'expanded' ? 'condensed' : 'expanded';
-        let mode = tracker.currentWidget.content.model.mode;
-
-        if (mode === 'condensed') {
-          void commands.execute(CommandIDs.mount, { mode });
-        } else if (mode === 'expanded') {
-          widget.content.sidebar.close();
-          void commands.execute(CommandIDs.mount, { mode });
-        }
+        const mode = currentMode === 'expanded' ? 'condensed' : 'expanded';
+        tracker.currentWidget.content.model.mode = mode;
+        void commands.execute(CommandIDs.mount, { mode });
       }
     });
 
@@ -394,7 +392,7 @@ const main: JupyterFrontEndPlugin<IDebugger> = {
         },
         session: {
           get: (): IDebugger.ISession | null => {
-            return null;
+            return widget ? widget.content.model.session : null;
           },
           set: (src: IDebugger.ISession | null) => {
             if (widget) {

+ 12 - 0
src/session.ts

@@ -135,6 +135,18 @@ export class DebugSession implements IDebugger.ISession {
     }
   }
 
+  /**
+   * Restore the state of a debug session.
+   */
+  async restoreState(): Promise<void> {
+    try {
+      const message = await this.sendRequest('debugInfo', {});
+      this._isStarted = message.body.isStarted;
+    } catch (err) {
+      console.error('Error: ', err.message);
+    }
+  }
+
   /**
    * Send a custom debug request to the kernel.
    * @param command debug command.

+ 33 - 4
src/tokens.ts

@@ -79,13 +79,18 @@ export namespace IDebugger {
      * Stop a running debug session.
      */
     stop(): Promise<void>;
+
+    /**
+     * Restore the state of a debug session.
+     */
+    restoreState(): Promise<void>;
   }
 
   export namespace ISession {
     /**
      * Arguments for 'dumpCell' request.
      * This is an addition to the Debug Adapter Protocol to support
-     * setting breakpoints for cells
+     * setting breakpoints for cells.
      */
     export interface IDumpCellArguments {
       code: string;
@@ -94,7 +99,7 @@ export namespace IDebugger {
     /**
      * Response to 'dumpCell' request.
      * This is an addition to the Debug Adapter Protocol to support
-     * setting breakpoints for cells
+     * setting breakpoints for cells.
      */
     export interface IDumpCellResponse extends DebugProtocol.Response {
       body: {
@@ -102,6 +107,28 @@ export namespace IDebugger {
       };
     }
 
+    /**
+     * List of breakpoints in a source file.
+     */
+    export interface IDebugInfoBreakpoints {
+      source: string;
+      lines: number[];
+    }
+
+    /**
+     * Response to 'debugInfo' request.
+     * This is an addition to the Debug Adapter Protocol to be able
+     * to retrieve the debugger state when restoring a session.
+     */
+    export interface IDebugInfoResponse extends DebugProtocol.Response {
+      body: {
+        isStarted: boolean;
+        hashMethod: string;
+        hashSeed: number;
+        breakpoints: IDebugInfoBreakpoints[];
+      };
+    }
+
     /**
      * Expose all the debug requests types.
      */
@@ -110,7 +137,9 @@ export namespace IDebugger {
       completions: DebugProtocol.CompletionsArguments;
       configurationDone: DebugProtocol.ConfigurationDoneArguments;
       continue: DebugProtocol.ContinueArguments;
+      debugInfo: {};
       disconnect: DebugProtocol.DisconnectArguments;
+      dumpCell: IDumpCellArguments;
       evaluate: DebugProtocol.EvaluateArguments;
       exceptionInfo: DebugProtocol.ExceptionInfoArguments;
       goto: DebugProtocol.GotoArguments;
@@ -139,7 +168,6 @@ export namespace IDebugger {
       terminate: DebugProtocol.TerminateArguments;
       terminateThreads: DebugProtocol.TerminateThreadsArguments;
       threads: {};
-      dumpCell: IDumpCellArguments;
       variables: DebugProtocol.VariablesArguments;
     };
 
@@ -151,7 +179,9 @@ export namespace IDebugger {
       completions: DebugProtocol.CompletionsResponse;
       configurationDone: DebugProtocol.ConfigurationDoneResponse;
       continue: DebugProtocol.ContinueResponse;
+      debugInfo: IDebugInfoResponse;
       disconnect: DebugProtocol.DisconnectResponse;
+      dumpCell: IDumpCellResponse;
       evaluate: DebugProtocol.EvaluateResponse;
       exceptionInfo: DebugProtocol.ExceptionInfoResponse;
       goto: DebugProtocol.GotoResponse;
@@ -180,7 +210,6 @@ export namespace IDebugger {
       terminate: DebugProtocol.TerminateResponse;
       terminateThreads: DebugProtocol.TerminateThreadsResponse;
       threads: DebugProtocol.ThreadsResponse;
-      dumpCell: IDumpCellResponse;
       variables: DebugProtocol.VariablesResponse;
     };
 

+ 4 - 0
style/index.css

@@ -16,6 +16,10 @@
   bottom: 0;
 }
 
+.jp-Debugger .p-SplitPanel-handle {
+  background-color: var(--jp-border-color2);
+}
+
 /* font awesome */
 
 .fa {

+ 14 - 0
tests/src/session.spec.ts

@@ -159,6 +159,20 @@ describe('protocol', () => {
     client.dispose();
   });
 
+  describe('#debugInfo', () => {
+    it('should return the state of the current debug session', async () => {
+      const reply = await debugSession.sendRequest('debugInfo', {});
+      expect(reply.body.isStarted).to.be.true;
+
+      const breakpoints = reply.body.breakpoints;
+      // breakpoints are in the same file
+      expect(breakpoints.length).to.equal(1);
+
+      const breakpointsInfo = breakpoints[0];
+      expect(breakpointsInfo.lines).to.deep.equal([3, 5]);
+    });
+  });
+
   describe('#stackTrace', () => {
     it('should return the correct stackframes', async () => {
       const reply = await debugSession.sendRequest('stackTrace', {