瀏覽代碼

Merge pull request #7820 from jasongrout/sessionkernelconnection

Give kernel connection options to a session connection
Steven Silvester 5 年之前
父節點
當前提交
0e0e7f253a

+ 9 - 5
packages/help-extension/src/index.tsx

@@ -192,16 +192,20 @@ function activate(
     if (!sessionModel.kernel || kernelInfoCache.has(sessionModel.kernel.name)) {
       return;
     }
-    const session = serviceManager.sessions.connectTo({ model: sessionModel });
-    // Note: .ready implies session.kernel.info is non-null
-    void session.kernel!.info.then(kernelInfo => {
+    const session = serviceManager.sessions.connectTo({
+      model: sessionModel,
+      kernelConnectionOptions: { handleComms: false }
+    });
+
+    void session.kernel?.info.then(kernelInfo => {
+      const name = session.kernel!.name;
+
       // Check the cache second time so that, if two callbacks get scheduled,
       // they don't try to add the same commands.
-      if (kernelInfoCache.has(sessionModel.kernel!.name)) {
+      if (kernelInfoCache.has(name)) {
         return;
       }
       // Set the Kernel Info cache.
-      const name = session.kernel!.name;
       kernelInfoCache.set(name, kernelInfo);
 
       // Utility function to check if the current widget

+ 6 - 0
packages/services/src/session/default.ts

@@ -33,6 +33,7 @@ export class SessionConnection implements Session.ISessionConnection {
     this._username = options.username ?? '';
     this._clientId = options.clientId ?? UUID.uuid4();
     this._connectToKernel = options.connectToKernel;
+    this._kernelConnectionOptions = options.kernelConnectionOptions ?? {};
     this.serverSettings =
       options.serverSettings ?? ServerConnection.makeSettings();
     this.setupKernel(options.model.kernel);
@@ -305,6 +306,7 @@ export class SessionConnection implements Session.ISessionConnection {
       return;
     }
     const kc = this._connectToKernel({
+      ...this._kernelConnectionOptions,
       model,
       username: this._username,
       clientId: this._clientId,
@@ -421,4 +423,8 @@ export class SessionConnection implements Session.ISessionConnection {
   private _connectToKernel: (
     options: Kernel.IKernelConnection.IOptions
   ) => Kernel.IKernelConnection;
+  private _kernelConnectionOptions: Omit<
+    Kernel.IKernelConnection.IOptions,
+    'model' | 'username' | 'clientId' | 'serverSettings'
+  >;
 }

+ 12 - 4
packages/services/src/session/session.ts

@@ -186,6 +186,13 @@ export namespace ISessionConnection {
      */
     model: IModel;
 
+    /**
+     * Connects to an existing kernel
+     */
+    connectToKernel(
+      options: Kernel.IKernelConnection.IOptions
+    ): Kernel.IKernelConnection;
+
     /**
      * The server settings.
      */
@@ -202,11 +209,12 @@ export namespace ISessionConnection {
     clientId?: string;
 
     /**
-     * Connects to an existing kernel
+     * Kernel connection options
      */
-    connectToKernel(
-      options: Kernel.IKernelConnection.IOptions
-    ): Kernel.IKernelConnection;
+    kernelConnectionOptions?: Omit<
+      Kernel.IKernelConnection.IOptions,
+      'model' | 'username' | 'clientId' | 'serverSettings'
+    >;
   }
 
   /**