浏览代码

Merge branch 'master' into remove-active

Afshin Taylor Darian 4 年之前
父节点
当前提交
e3471b3976
共有 5 个文件被更改,包括 57 次插入14 次删除
  1. 7 3
      src/handler.ts
  2. 3 3
      src/index.ts
  3. 12 2
      src/service.ts
  4. 34 5
      src/sources.ts
  5. 1 1
      src/tokens.ts

+ 7 - 3
src/handler.ts

@@ -223,9 +223,13 @@ export class DebuggerHandler {
       delete this._statusChangedHandlers[widget.id];
       delete this._contextKernelChangedHandlers[widget.id];
 
-      // clear the model if the handler being removed corresponds
-      // to the current active debug session
-      if (this._service.session?.connection?.path === connection?.path) {
+      // Clear the model if the handler being removed corresponds
+      // to the current active debug session, or if the connection
+      // does not have a kernel.
+      if (
+        this._service.session?.connection?.path === connection?.path ||
+        !this._service.session?.connection?.kernel
+      ) {
         const model = this._service.model;
         model.clear();
       }

+ 3 - 3
src/index.ts

@@ -554,7 +554,7 @@ const main: JupyterFrontEndPlugin<void> = {
         debuggerSources
           .find({
             focus: true,
-            kernel: service.session.connection.kernel.name,
+            kernel: service.session?.connection?.kernel?.name,
             path: service.session?.connection?.path,
             source: frame?.source.path ?? null
           })
@@ -575,8 +575,8 @@ const main: JupyterFrontEndPlugin<void> = {
         const { content, mimeType, path } = source;
         const results = debuggerSources.find({
           focus: true,
-          kernel: service.session.connection.kernel.name,
-          path: service.session.connection.path,
+          kernel: service.session?.connection?.kernel.name,
+          path: service.session?.connection?.path,
           source: path
         });
         if (results.length > 0) {

+ 12 - 2
src/service.ts

@@ -124,7 +124,14 @@ export class DebuggerService implements IDebugger, IDisposable {
    * @param code The source code.
    */
   getCodeId(code: string): string {
-    return this._config.getCodeId(code, this.session.connection.kernel.name);
+    try {
+      return this._config.getCodeId(
+        code,
+        this.session?.connection?.kernel?.name
+      );
+    } catch {
+      return '';
+    }
   }
 
   /**
@@ -558,7 +565,10 @@ export class DebuggerService implements IDebugger, IDisposable {
         val: IDebugger.ISession.IDebugInfoBreakpoints
       ) => {
         const { breakpoints, source } = val;
-        map.set(source, breakpoints);
+        map.set(
+          source,
+          breakpoints.map(point => ({ ...point, verified: true }))
+        );
         return map;
       },
       new Map<string, IDebugger.IBreakpoint[]>()

+ 34 - 5
src/sources.ts

@@ -108,8 +108,11 @@ export class DebuggerSources implements IDebugger.ISources {
       cells.forEach((cell, i) => {
         // check the event is for the correct cell
         const code = cell.model.value.text;
-        const cellId = this._config.getCodeId(code, kernel);
-        if (source !== cellId) {
+        const codeId = this._getCodeId(code, kernel);
+        if (!codeId) {
+          return;
+        }
+        if (source !== codeId) {
           return;
         }
         if (focus) {
@@ -149,7 +152,10 @@ export class DebuggerSources implements IDebugger.ISources {
       const cells = consoleWidget.console.cells;
       each(cells, cell => {
         const code = cell.model.value.text;
-        const codeId = this._config.getCodeId(code, kernel);
+        const codeId = this._getCodeId(code, kernel);
+        if (!codeId) {
+          return;
+        }
         if (source !== codeId) {
           return;
         }
@@ -188,7 +194,10 @@ export class DebuggerSources implements IDebugger.ISources {
       }
 
       const code = editor.model.value.text;
-      const codeId = this._config.getCodeId(code, kernel);
+      const codeId = this._getCodeId(code, kernel);
+      if (!codeId) {
+        return;
+      }
       if (source !== codeId) {
         return;
       }
@@ -218,7 +227,11 @@ export class DebuggerSources implements IDebugger.ISources {
       }
 
       const code = editor.model.value.text;
-      const codeId = this._config.getCodeId(code, kernel);
+      const codeId = this._getCodeId(code, kernel);
+      if (!codeId) {
+        return;
+      }
+
       if (widget.title.caption !== source && source !== codeId) {
         return;
       }
@@ -229,6 +242,22 @@ export class DebuggerSources implements IDebugger.ISources {
     });
     return editors;
   }
+
+  /**
+   * Get the code id for a given source and kernel,
+   * and handle the case of a kernel without parameters.
+   *
+   * @param code The source code.
+   * @param kernel The name of the kernel.
+   */
+  private _getCodeId(code: string, kernel: string): string {
+    try {
+      return this._config.getCodeId(code, kernel);
+    } catch {
+      return '';
+    }
+  }
+
   private _shell: JupyterFrontEnd.IShell;
   private _readOnlyEditorTracker: WidgetTracker<
     MainAreaWidget<CodeEditorWrapper>

+ 1 - 1
src/tokens.ts

@@ -433,7 +433,7 @@ export namespace IDebugger {
      */
     export interface IDebugInfoBreakpoints {
       source: string;
-      breakpoints: DebugProtocol.Breakpoint[];
+      breakpoints: DebugProtocol.SourceBreakpoint[];
     }
 
     /**