浏览代码

Clean up a few more changes we’ve made.

Jason Grout 5 年之前
父节点
当前提交
96f89b2e47

+ 1 - 1
packages/console/src/panel.ts

@@ -298,8 +298,8 @@ namespace Private {
       if (executed) {
         caption += `\nLast Execution: ${Time.format(executed.toISOString())}`;
       }
-      panel.title.caption = caption;
       panel.title.label = session.name;
+      panel.title.caption = caption;
     } else {
       panel.title.label = 'Console';
       panel.title.caption = '';

+ 18 - 18
packages/console/src/widget.ts

@@ -288,38 +288,38 @@ export class CodeConsole extends Widget {
    * should wait for the API to determine whether code being submitted is
    * incomplete before attempting submission anyway. The default value is `250`.
    */
-  execute(force = false, timeout = EXECUTION_TIMEOUT): Promise<void> {
+  async execute(force = false, timeout = EXECUTION_TIMEOUT): Promise<void> {
     if (this.session.kernel.status === 'dead') {
-      return Promise.resolve();
+      return;
     }
 
     const promptCell = this.promptCell;
     if (!promptCell) {
-      return Promise.reject('Cannot execute without a prompt cell');
+      throw new Error('Cannot execute without a prompt cell');
     }
     promptCell.model.trusted = true;
 
     if (force) {
       // Create a new prompt cell before kernel execution to allow typeahead.
       this.newPromptCell();
-      return this._execute(promptCell);
+      await this._execute(promptCell);
+      return;
     }
 
     // Check whether we should execute.
-    return this._shouldExecute(timeout).then(should => {
-      if (this.isDisposed) {
-        return;
-      }
-      if (should) {
-        // Create a new prompt cell before kernel execution to allow typeahead.
-        this.newPromptCell();
-        this.promptCell!.editor.focus();
-        return this._execute(promptCell);
-      } else {
-        // add a newline if we shouldn't execute
-        promptCell.editor.newIndentedLine();
-      }
-    });
+    let shouldExecute = await this._shouldExecute(timeout);
+    if (this.isDisposed) {
+      return;
+    }
+    if (shouldExecute) {
+      // Create a new prompt cell before kernel execution to allow typeahead.
+      this.newPromptCell();
+      this.promptCell!.editor.focus();
+      await this._execute(promptCell);
+    } else {
+      // add a newline if we shouldn't execute
+      promptCell.editor.newIndentedLine();
+    }
   }
 
   /**

+ 1 - 1
packages/docregistry/src/context.ts

@@ -767,7 +767,7 @@ export class Context<T extends DocumentRegistry.IModel>
   /**
    * Finish a saveAs operation given a new path.
    */
-  private _finishSaveAs(newPath: string): Promise<void> {
+  private async _finishSaveAs(newPath: string): Promise<void> {
     this._path = newPath;
     return this.session.session
       ?.setPath(newPath)

+ 2 - 1
packages/extensionmanager/src/companions.tsx

@@ -4,7 +4,8 @@
 import { Dialog, showDialog } from '@jupyterlab/apputils';
 
 import * as React from 'react';
-import { KernelSpec } from '@jupyterlab/services/src/kernelspec';
+
+import { KernelSpec } from '@jupyterlab/services';
 
 /**
  * An object representing a companion installation info.

+ 5 - 2
packages/extensionmanager/src/model.ts

@@ -3,7 +3,11 @@
 
 import { VDomModel } from '@jupyterlab/apputils';
 
-import { ServerConnection, ServiceManager } from '@jupyterlab/services';
+import {
+  KernelSpec,
+  ServerConnection,
+  ServiceManager
+} from '@jupyterlab/services';
 
 import * as semver from 'semver';
 
@@ -18,7 +22,6 @@ import {
 import { reportInstallError } from './dialog';
 
 import { Searcher, ISearchResult, isJupyterOrg } from './query';
-import { KernelSpec } from '@jupyterlab/services/src/kernelspec';
 
 /**
  * Information about an extension.

+ 6 - 16
packages/statusbar/src/defaults/kernelStatus.tsx

@@ -138,25 +138,15 @@ export namespace KernelStatus {
       return this._session;
     }
     set session(session: IClientSession | null) {
-      const oldSession = this._session;
-      if (oldSession !== null) {
-        oldSession.statusChanged.disconnect(this._onKernelStatusChanged);
-        oldSession.kernelChanged.disconnect(this._onKernelChanged);
-      }
+      this._session?.statusChanged.disconnect(this._onKernelStatusChanged);
+      this._session?.kernelChanged.disconnect(this._onKernelChanged);
 
       const oldState = this._getAllState();
       this._session = session;
-      if (this._session === null) {
-        this._kernelStatus = 'unknown';
-        this._kernelName = 'unknown';
-      } else {
-        this._kernelStatus = this._session.session.kernel.status;
-        this._kernelName = this._session.kernelDisplayName;
-
-        this._session.statusChanged.connect(this._onKernelStatusChanged);
-        this._session.kernelChanged.connect(this._onKernelChanged);
-      }
-
+      this._kernelStatus = session?.session?.kernel?.status ?? 'unknown';
+      this._kernelName = session?.kernelDisplayName ?? 'unknown';
+      session?.statusChanged.connect(this._onKernelStatusChanged);
+      session?.kernelChanged.connect(this._onKernelChanged);
       this._triggerChange(oldState, this._getAllState());
     }