@@ -26,10 +26,10 @@ import {
2626 ICell ,
2727 IConnection ,
2828 IDataScience ,
29- IJupyterKernelSpec ,
3029 IJupyterSession ,
3130 IJupyterSessionManager ,
3231 INotebookServer ,
32+ INotebookServerLaunchInfo ,
3333 InterruptResult
3434} from '../types' ;
3535
@@ -109,13 +109,11 @@ class CellSubscriber {
109109// https://www.npmjs.com/package/@jupyterlab /services
110110
111111export class JupyterServerBase implements INotebookServer {
112+ private launchInfo : INotebookServerLaunchInfo | undefined ;
112113 private session : IJupyterSession | undefined ;
113- private connInfo : IConnection | undefined ;
114- private workingDir : string | undefined ;
115114 private sessionStartTime : number | undefined ;
116115 private pendingCellSubscriptions : CellSubscriber [ ] = [ ] ;
117116 private ranInitialSetup = false ;
118- private usingDarkTheme : boolean | undefined ;
119117
120118 constructor (
121119 liveShare : ILiveShareApi ,
@@ -128,23 +126,23 @@ export class JupyterServerBase implements INotebookServer {
128126 this . asyncRegistry . push ( this ) ;
129127 }
130128
131- public async connect ( connInfo : IConnection , kernelSpec : IJupyterKernelSpec | undefined , usingDarkTheme : boolean , cancelToken ?: CancellationToken , workingDir ?: string ) : Promise < void > {
132- // Save connection info. Determines if we need to change directory or not
133- this . connInfo = connInfo ;
134- this . workingDir = workingDir ;
135- this . usingDarkTheme = usingDarkTheme ;
129+ public async connect ( launchInfo : INotebookServerLaunchInfo , cancelToken ?: CancellationToken ) {
130+ // Save our launch info
131+ this . launchInfo = launchInfo ;
136132
137133 // Start our session
138- this . session = await this . sessionManager . startNew ( connInfo , kernelSpec , cancelToken ) ;
134+ this . session = await this . sessionManager . startNew ( launchInfo . connectionInfo , launchInfo . kernelSpec , cancelToken ) ;
139135
140- // Setup our start time. We reject anything that comes in before this time during execute
141- this . sessionStartTime = Date . now ( ) ;
136+ if ( this . session ) {
137+ // Setup our start time. We reject anything that comes in before this time during execute
138+ this . sessionStartTime = Date . now ( ) ;
142139
143- // Wait for it to be ready
144- await this . session . waitForIdle ( ) ;
140+ // Wait for it to be ready
141+ await this . session . waitForIdle ( ) ;
145142
146- // Run our initial setup and plot magics
147- this . initialNotebookSetup ( cancelToken ) ;
143+ // Run our initial setup and plot magics
144+ this . initialNotebookSetup ( cancelToken ) ;
145+ }
148146 }
149147
150148 public shutdown ( ) : Promise < void > {
@@ -192,9 +190,9 @@ export class JupyterServerBase implements INotebookServer {
192190
193191 public async setInitialDirectory ( directory : string ) : Promise < void > {
194192 // If we launched local and have no working directory call this on add code to change directory
195- if ( ! this . workingDir && this . connInfo && this . connInfo . localLaunch ) {
193+ if ( this . launchInfo && ! this . launchInfo . workingDir && this . launchInfo . connectionInfo . localLaunch ) {
196194 await this . changeDirectoryIfPossible ( directory ) ;
197- this . workingDir = directory ;
195+ this . launchInfo . workingDir = directory ;
198196 }
199197 }
200198
@@ -365,15 +363,23 @@ export class JupyterServerBase implements INotebookServer {
365363 throw new Error ( localize . DataScience . sessionDisposed ( ) ) ;
366364 }
367365
366+ public getLaunchInfo ( ) : INotebookServerLaunchInfo | undefined {
367+ if ( ! this . launchInfo ) {
368+ return undefined ;
369+ }
370+
371+ return this . launchInfo ;
372+ }
373+
368374 // Return a copy of the connection information that this server used to connect with
369375 public getConnectionInfo ( ) : IConnection | undefined {
370- if ( ! this . connInfo ) {
376+ if ( ! this . launchInfo ) {
371377 return undefined ;
372378 }
373379
374380 // Return a copy with a no-op for dispose
375381 return {
376- ...this . connInfo ,
382+ ...this . launchInfo . connectionInfo ,
377383 dispose : noop
378384 } ;
379385 }
@@ -458,12 +464,12 @@ export class JupyterServerBase implements INotebookServer {
458464 this . ranInitialSetup = true ;
459465
460466 // When we start our notebook initial, change to our workspace or user specified root directory
461- if ( this . connInfo && this . connInfo . localLaunch && this . workingDir ) {
462- this . changeDirectoryIfPossible ( this . workingDir ) . ignoreErrors ( ) ;
467+ if ( this . launchInfo && this . launchInfo . workingDir && this . launchInfo . connectionInfo . localLaunch ) {
468+ this . changeDirectoryIfPossible ( this . launchInfo . workingDir ) . ignoreErrors ( ) ;
463469 }
464470
465471 this . executeSilently (
466- `%matplotlib inline${ os . EOL } import matplotlib.pyplot as plt${ this . usingDarkTheme ? `${ os . EOL } from matplotlib import style${ os . EOL } style.use(\'dark_background\')` : '' } ` ,
472+ `%matplotlib inline${ os . EOL } import matplotlib.pyplot as plt${ ( this . launchInfo && this . launchInfo . usingDarkTheme ) ? `${ os . EOL } from matplotlib import style${ os . EOL } style.use(\'dark_background\')` : '' } ` ,
467473 cancelToken
468474 ) . ignoreErrors ( ) ;
469475 }
@@ -508,7 +514,7 @@ export class JupyterServerBase implements INotebookServer {
508514 }
509515
510516 private changeDirectoryIfPossible = async ( directory : string ) : Promise < void > => {
511- if ( this . connInfo && this . connInfo . localLaunch && await fs . pathExists ( directory ) ) {
517+ if ( this . launchInfo && this . launchInfo . connectionInfo . localLaunch && await fs . pathExists ( directory ) ) {
512518 await this . executeSilently ( `%cd "${ directory } "` ) ;
513519 }
514520 }
0 commit comments