Quellcode durchsuchen

More clean up and refactoring

Afshin T. Darian vor 4 Jahren
Ursprung
Commit
ea63089cbf
5 geänderte Dateien mit 44 neuen und 53 gelöschten Zeilen
  1. 19 19
      src/editor-finder.ts
  2. 6 11
      src/handlers/tracker.ts
  3. 7 9
      src/index.ts
  4. 11 13
      src/service.ts
  5. 1 1
      src/tokens.ts

+ 19 - 19
src/editor-finder.ts

@@ -88,13 +88,13 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
     if (!this._notebookTracker) {
       return [];
     }
-    const { debugSessionPath, source, focus, kernelName } = findParams;
+    const { focus, kernel, path, source } = findParams;
 
     const editors: CodeEditor.IEditor[] = [];
     this._notebookTracker.forEach(notebookPanel => {
       const sessionContext = notebookPanel.sessionContext;
 
-      if (sessionContext.path !== debugSessionPath) {
+      if (path !== sessionContext.path) {
         return;
       }
 
@@ -107,7 +107,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._config.getCodeId(code, kernelName);
+        const cellId = this._config.getCodeId(code, kernel);
         if (source !== cellId) {
           return;
         }
@@ -132,20 +132,20 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
     if (!this._consoleTracker) {
       return [];
     }
-    const { debugSessionPath, source, focus, kernelName } = findParams;
+    const { focus, kernel, path, source } = findParams;
 
     const editors: CodeEditor.IEditor[] = [];
     this._consoleTracker.forEach(consoleWidget => {
       const sessionContext = consoleWidget.sessionContext;
 
-      if (sessionContext.path !== debugSessionPath) {
+      if (path !== sessionContext.path) {
         return;
       }
 
       const cells = consoleWidget.console.cells;
       each(cells, cell => {
         const code = cell.model.value.text;
-        const codeId = this._config.getCodeId(code, kernelName);
+        const codeId = this._config.getCodeId(code, kernel);
         if (source !== codeId) {
           return;
         }
@@ -168,12 +168,12 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
     if (!this._editorTracker) {
       return;
     }
-    const { debugSessionPath, source, focus, kernelName } = findParams;
+    const { focus, kernel, path, source } = findParams;
 
     const editors: CodeEditor.IEditor[] = [];
     this._editorTracker.forEach(doc => {
       const fileEditor = doc.content;
-      if (debugSessionPath !== fileEditor.context.path) {
+      if (path !== fileEditor.context.path) {
         return;
       }
 
@@ -183,7 +183,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
       }
 
       const code = editor.model.value.text;
-      const codeId = this._config.getCodeId(code, kernelName);
+      const codeId = this._config.getCodeId(code, kernel);
       if (source !== codeId) {
         return;
       }
@@ -203,7 +203,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
   private _findInReadOnlyEditors(
     findParams: IFindParameters
   ): CodeEditor.IEditor[] {
-    const { source, focus, kernelName } = findParams;
+    const { focus, kernel, source } = findParams;
 
     const editors: CodeEditor.IEditor[] = [];
     this._readOnlyEditorTracker.forEach(widget => {
@@ -213,7 +213,7 @@ export class EditorFinder implements IDisposable, IDebuggerEditorFinder {
       }
 
       const code = editor.model.value.text;
-      const codeId = this._config.getCodeId(code, kernelName);
+      const codeId = this._config.getCodeId(code, kernel);
       if (widget.title.caption !== source && source !== codeId) {
         return;
       }
@@ -279,24 +279,24 @@ export namespace EditorFinder {
  */
 interface IFindParameters {
   /**
-   * Path of session connection.
+   * Extra flag prevent disable focus.
    */
-  debugSessionPath: string;
+  focus: boolean;
 
   /**
-   * Source path
+   * Name of current kernel.
    */
-  source: string;
+  kernel: string;
 
   /**
-   * Extra flag prevent disable focus.
+   * Path of session connection.
    */
-  focus: boolean;
+  path: string;
 
   /**
-   * Name of current kernel.
+   * Source path
    */
-  kernelName: string;
+  source: string;
 }
 
 /**

+ 6 - 11
src/handlers/tracker.ts

@@ -122,15 +122,12 @@ export class TrackerHandler implements IDisposable {
     _: CallstackModel,
     frame: CallstackModel.IFrame
   ): void {
-    const debugSessionPath = this._debuggerService.session?.connection?.path;
-    const source = frame?.source.path ?? null;
-    const kernelName = this._debuggerService.session.connection.kernel.name;
     each(
       this._editorFinder.find({
-        debugSessionPath,
-        source,
         focus: true,
-        kernelName
+        kernel: this._debuggerService.session.connection.kernel.name,
+        path: this._debuggerService.session?.connection?.path,
+        source: frame?.source.path ?? null
       }),
       editor => {
         requestAnimationFrame(() => {
@@ -153,14 +150,12 @@ export class TrackerHandler implements IDisposable {
     if (!source) {
       return;
     }
-    const debugSessionPath = this._debuggerService.session.connection.path;
     const { content, mimeType, path } = source;
-    const kernelName = this._debuggerService.session.connection.kernel.name;
     const results = this._editorFinder.find({
-      debugSessionPath,
-      source: path,
       focus: false,
-      kernelName
+      kernel: this._debuggerService.session.connection.kernel.name,
+      path: this._debuggerService.session.connection.path,
+      source: path
     });
     if (results.next()) {
       return;

+ 7 - 9
src/index.ts

@@ -505,21 +505,19 @@ const main: JupyterFrontEndPlugin<void> = {
 
     if (settingRegistry) {
       const setting = await settingRegistry.load(main.id);
-      const updateVariableSettings = (): void => {
+      const updateSettings = (): void => {
         const filters = setting.get('variableFilters').composite as {
           [key: string]: string[];
         };
-        const kernelName = service.session?.connection?.kernel?.name;
-        const list = filters[kernelName];
-        if (!list) {
-          return;
+        const list = filters[service.session?.connection?.kernel?.name];
+        if (list) {
+          sidebar.variables.filter = new Set<string>(list);
         }
-        sidebar.variables.filter = new Set<string>(list);
       };
 
-      updateVariableSettings();
-      setting.changed.connect(updateVariableSettings);
-      sidebar.service.sessionChanged.connect(updateVariableSettings);
+      updateSettings();
+      setting.changed.connect(updateSettings);
+      sidebar.service.sessionChanged.connect(updateSettings);
     }
 
     if (themeManager) {

+ 11 - 13
src/service.ts

@@ -222,19 +222,19 @@ export class DebuggerService implements IDebugger, IDisposable {
     }
 
     const reply = await this.session.restoreState();
-    const { hashMethod, hashSeed, tmpFilePrefix, tmpFileSuffix } = reply.body;
+    const { body } = reply;
     const breakpoints = this._mapBreakpoints(reply.body.breakpoints);
     const stoppedThreads = new Set(reply.body.stoppedThreads);
-    const kernelName = this.session.connection.kernel.name;
+
     this._config.setHashParams({
-      kernel: kernelName,
-      method: hashMethod,
-      seed: hashSeed
+      kernel: this.session.connection.kernel.name,
+      method: body.hashMethod,
+      seed: body.hashSeed
     });
     this._config.setTmpFileParams({
-      kernel: kernelName,
-      prefix: tmpFilePrefix,
-      suffix: tmpFileSuffix
+      kernel: this.session.connection.kernel.name,
+      prefix: body.tmpFilePrefix,
+      suffix: body.tmpFileSuffix
     });
 
     this._model.stoppedThreads = stoppedThreads;
@@ -422,18 +422,16 @@ export class DebuggerService implements IDebugger, IDisposable {
   private _filterBreakpoints(
     breakpoints: Map<string, IDebugger.IBreakpoint[]>
   ): Map<string, IDebugger.IBreakpoint[]> {
-    const debugSessionPath = this._session.connection.path;
-    const kernelName = this.session.connection.kernel.name;
     let bpMapForRestore = new Map<string, IDebugger.IBreakpoint[]>();
     for (let collection of breakpoints) {
       const [id, list] = collection;
       list.forEach(() => {
         each(
           this._editorFinder.find({
-            debugSessionPath,
-            source: id,
             focus: false,
-            kernelName
+            kernel: this.session.connection.kernel.name,
+            path: this._session.connection.path,
+            source: id
           }),
           () => {
             if (list.length > 0) {

+ 1 - 1
src/tokens.ts

@@ -209,7 +209,7 @@ export namespace IDebugger {
      * @param code The source code.
      * @param kernel The kernel name from current session.
      */
-    getCodeId(code: string, kernelName: string): string;
+    getCodeId(code: string, kernel: string): string;
 
     /**
      * Sets the hash parameters for a kernel.