Bladeren bron

Multiple kernels hash parameters solution

krzysztof.sikora 4 jaren geleden
bovenliggende
commit
7114c37419
4 gewijzigde bestanden met toevoegingen van 81 en 35 verwijderingen
  1. 21 9
      src/debugger-configuration.ts
  2. 25 14
      src/editor-finder.ts
  3. 16 6
      src/handlers/tracker.ts
  4. 19 6
      src/service.ts

+ 21 - 9
src/debugger-configuration.ts

@@ -31,9 +31,14 @@ export class DebuggerConfiguration implements IDebuggerConfig {
    * Computes an id based on the given code.
    *
    * @param code The source code.
+   * @param kernelName The kernel name from current session.
    */
-  public getCodeId(code: string): string {
-    return this._tmpFilePrefix + this._hashMethod(code) + this._tmpFileSuffix;
+  public getCodeId(code: string, kernelName: string): string {
+    return (
+      this._tmpFileAssociatedWithKernel.get(kernelName)[0] +
+      this._hashMethod(code) +
+      this._tmpFileAssociatedWithKernel.get(kernelName)[1]
+    );
   }
 
   /**
@@ -57,15 +62,18 @@ export class DebuggerConfiguration implements IDebuggerConfig {
    *
    * @param prefix The prefix used for the temporary files.
    * @param suffix The suffix used for the temporary files.
+   * @param kernelName The kernel name from current session.
    */
-  public setTmpFileParameters(prefix: string, suffix: string): void {
-    this._tmpFilePrefix = prefix;
-    this._tmpFileSuffix = suffix;
+  public setTmpFileParameters(
+    prefix: string,
+    suffix: string,
+    kernelName: string
+  ): void {
+    this._tmpFileAssociatedWithKernel.set(kernelName, [prefix, suffix]);
   }
 
   private _hashMethod: (code: string) => string;
-  private _tmpFilePrefix: string;
-  private _tmpFileSuffix: string;
+  private _tmpFileAssociatedWithKernel = new Map<string, [string, string]>();
 }
 
 export const IDebuggerConfig = new Token<IDebuggerConfig>(
@@ -76,6 +84,10 @@ export const IDebuggerConfig = new Token<IDebuggerConfig>(
  */
 export interface IDebuggerConfig {
   setHashParameters(method: string, seed: number): void;
-  setTmpFileParameters(prefix: string, suffix: string): void;
-  getCodeId(code: string): string;
+  setTmpFileParameters(
+    prefix: string,
+    suffix: string,
+    kernelName: string
+  ): void;
+  getCodeId(code: string, kernelName: string): string;
 }

+ 25 - 14
src/editor-finder.ts

@@ -73,17 +73,19 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
    * @param debugSessionPath The path for the current debug session.
    * @param source The source to find.
    * @param focus - Set to true to focus on the relevant cell. Default to false.
+   * @param kernelName The kernel name of current session.
    */
   find(
     debugSessionPath: string,
     source: string,
-    focus: boolean
+    focus: boolean,
+    kernelName: string
   ): IIterator<CodeEditor.IEditor> {
     return chain(
-      this._findInNotebooks(debugSessionPath, source, focus),
-      this._findInConsoles(debugSessionPath, source, focus),
-      this._findInEditors(debugSessionPath, source, focus),
-      this._findInReadOnlyEditors(debugSessionPath, source, focus)
+      this._findInNotebooks(debugSessionPath, source, focus, kernelName),
+      this._findInConsoles(debugSessionPath, source, focus, kernelName),
+      this._findInEditors(debugSessionPath, source, focus, kernelName),
+      this._findInReadOnlyEditors(debugSessionPath, source, focus, kernelName)
     );
   }
 
@@ -93,11 +95,13 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
    * @param debugSessionPath The path for the current debug session.
    * @param source The source to find.
    * @param focus - Set to true to focus on the relevant cell. Default to false.
+   * @param kernelName The kernel name from current session.
    */
   private _findInNotebooks(
     debugSessionPath: string,
     source: string,
-    focus: boolean
+    focus: boolean,
+    kernelName: string
   ): CodeEditor.IEditor[] {
     if (!this._notebookTracker) {
       return [];
@@ -119,7 +123,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
       cells.forEach((cell, i) => {
         // check the event is for the correct cell
         const code = cell.model.value.text;
-        const cellId = this._debuggerConfiguration.getCodeId(code);
+        const cellId = this._debuggerConfiguration.getCodeId(code, kernelName);
         if (source !== cellId) {
           return;
         }
@@ -141,11 +145,13 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
    * @param debugSessionPath The path for the current debug session.
    * @param source The source to find.
    * @param focus - Set to true to focus on the relevant cell. Default to false.
+   * @param kernelName The kernel name from current session.
    */
   private _findInConsoles(
     debugSessionPath: string,
     source: string,
-    focus: boolean
+    focus: boolean,
+    kernelName: string
   ): CodeEditor.IEditor[] {
     if (!this._consoleTracker) {
       return [];
@@ -161,7 +167,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
       const cells = consoleWidget.console.cells;
       each(cells, cell => {
         const code = cell.model.value.text;
-        const codeId = this._debuggerConfiguration.getCodeId(code);
+        const codeId = this._debuggerConfiguration.getCodeId(code, kernelName);
         if (source !== codeId) {
           return;
         }
@@ -181,11 +187,13 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
    * @param debugSessionPath The path for the current debug session.
    * @param source The source to find.
    * @param focus - Set to true to focus on the relevant cell. Default to false.
+   * @param kernelName The kernel name from current session.
    */
   private _findInEditors(
     debugSessionPath: string,
     source: string,
-    focus: boolean
+    focus: boolean,
+    kernelName: string
   ): CodeEditor.IEditor[] {
     if (!this._editorTracker) {
       return;
@@ -203,7 +211,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
       }
 
       const code = editor.model.value.text;
-      const codeId = this._debuggerConfiguration.getCodeId(code);
+      const codeId = this._debuggerConfiguration.getCodeId(code, kernelName);
       if (source !== codeId) {
         return;
       }
@@ -221,11 +229,13 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
    * @param debugSessionPath The path for the current debug session.
    * @param source The source to find.
    * @param focus Set to true to focus on the relevant cell. Default to false.
+   * @param kernelName The kernel name from current session.
    */
   private _findInReadOnlyEditors(
     debugSessionPath: string,
     source: string,
-    focus: boolean
+    focus: boolean,
+    kernelName: string
   ): CodeEditor.IEditor[] {
     const editors: CodeEditor.IEditor[] = [];
     this._readOnlyEditorTracker.forEach(widget => {
@@ -235,7 +245,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
       }
 
       const code = editor.model.value.text;
-      const codeId = this._debuggerConfiguration.getCodeId(code);
+      const codeId = this._debuggerConfiguration.getCodeId(code, kernelName);
       if (widget.title.caption !== source && source !== codeId) {
         return;
       }
@@ -308,6 +318,7 @@ export interface IDebuggerEditorFinder {
   find(
     debugSessionPath: string,
     source: string,
-    focus: boolean
+    focus: boolean,
+    kernelName: string
   ): IIterator<CodeEditor.IEditor>;
 }

+ 16 - 6
src/handlers/tracker.ts

@@ -124,11 +124,15 @@ export class TrackerHandler implements IDisposable {
   ): void {
     const debugSessionPath = this._debuggerService.session?.connection?.path;
     const source = frame?.source.path ?? null;
-    each(this._editorFinder.find(debugSessionPath, source, true), editor => {
-      requestAnimationFrame(() => {
-        EditorHandler.showCurrentLine(editor, frame.line);
-      });
-    });
+    const kernelName = this._debuggerService.session.connection.kernel.name;
+    each(
+      this._editorFinder.find(debugSessionPath, source, true, kernelName),
+      editor => {
+        requestAnimationFrame(() => {
+          EditorHandler.showCurrentLine(editor, frame.line);
+        });
+      }
+    );
   }
 
   /**
@@ -146,7 +150,13 @@ export class TrackerHandler implements IDisposable {
     }
     const debugSessionPath = this._debuggerService.session.connection.path;
     const { content, mimeType, path } = source;
-    const results = this._editorFinder.find(debugSessionPath, path, false);
+    const kernelName = this._debuggerService.session.connection.kernel.name;
+    const results = this._editorFinder.find(
+      debugSessionPath,
+      path,
+      false,
+      kernelName
+    );
     if (results.next()) {
       return;
     }

+ 19 - 6
src/service.ts

@@ -166,7 +166,10 @@ export class DebuggerService implements IDebugger, IDisposable {
    * @param code The source code.
    */
   getCodeId(code: string): string {
-    return this._debuggerConfiguration.getCodeId(code);
+    return this._debuggerConfiguration.getCodeId(
+      code,
+      this.session.connection.kernel.name
+    );
   }
 
   /**
@@ -227,11 +230,13 @@ export class DebuggerService implements IDebugger, IDisposable {
     const { hashMethod, hashSeed, tmpFilePrefix, tmpFileSuffix } = reply.body;
     const breakpoints = this._mapBreakpoints(reply.body.breakpoints);
     const stoppedThreads = new Set(reply.body.stoppedThreads);
+    const kernelName = this.session.connection.kernel.name;
 
     this._debuggerConfiguration.setHashParameters(hashMethod, hashSeed);
     this._debuggerConfiguration.setTmpFileParameters(
       tmpFilePrefix,
-      tmpFileSuffix
+      tmpFileSuffix,
+      kernelName
     );
 
     this._model.stoppedThreads = stoppedThreads;
@@ -424,11 +429,19 @@ export class DebuggerService implements IDebugger, IDisposable {
     for (let collection of breakpoints) {
       const [id, list] = collection;
       list.forEach(() => {
-        each(this._editorFinder.find(path, id, false), () => {
-          if (list.length > 0) {
-            bpMapForRestore.set(id, list);
+        each(
+          this._editorFinder.find(
+            path,
+            id,
+            false,
+            this.session.connection.kernel.name
+          ),
+          () => {
+            if (list.length > 0) {
+              bpMapForRestore.set(id, list);
+            }
           }
-        });
+        );
       });
     }
     return bpMapForRestore;