1- import { injectable , inject , named } from 'inversify' ;
1+ import { injectable , inject , named , optional } from 'inversify' ;
22import { EventEmitter , Uri , CancellationToken , l10n } from 'vscode' ;
33import { generateUuid as uuid } from '../../../platform/common/uuid' ;
4- import { IExtensionContext , IOutputChannel } from '../../../platform/common/types' ;
4+ import { IConfigurationService , IExtensionContext , IOutputChannel } from '../../../platform/common/types' ;
55import { IExtensionSyncActivationService } from '../../../platform/activation/types' ;
66import { logger } from '../../../platform/logging' ;
77import { DeepnoteEnvironmentStorage } from './deepnoteEnvironmentStorage.node' ;
@@ -11,17 +11,27 @@ import {
1111 DeepnoteEnvironmentWithStatus ,
1212 EnvironmentStatus
1313} from './deepnoteEnvironment' ;
14- import { IDeepnoteEnvironmentManager , IDeepnoteServerStarter , IDeepnoteToolkitInstaller } from '../types' ;
14+ import {
15+ IDeepnoteEnvironmentManager ,
16+ IDeepnoteServerProvider ,
17+ IDeepnoteServerStarter ,
18+ IDeepnoteToolkitInstaller
19+ } from '../types' ;
1520import { Cancellation } from '../../../platform/common/cancellation' ;
1621import { STANDARD_OUTPUT_CHANNEL } from '../../../platform/common/constants' ;
22+ import { IJupyterRequestAgentCreator , IJupyterRequestCreator } from '../../jupyter/types' ;
1723
1824/**
1925 * Manager for Deepnote kernel environments.
2026 * Handles CRUD operations and server lifecycle management.
2127 */
2228@injectable ( )
2329export class DeepnoteEnvironmentManager implements IExtensionSyncActivationService , IDeepnoteEnvironmentManager {
30+ // Track server handles per notebook URI for cleanup
31+ // private readonly notebookServerHandles = new Map<string, string>();
32+
2433 private environments : Map < string , DeepnoteEnvironment > = new Map ( ) ;
34+ private tmpStartingServers : Map < string , boolean > = new Map ( ) ;
2535 private readonly _onDidChangeEnvironments = new EventEmitter < void > ( ) ;
2636 public readonly onDidChangeEnvironments = this . _onDidChangeEnvironments . event ;
2737 private initializationPromise : Promise < void > | undefined ;
@@ -31,6 +41,12 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
3141 @inject ( DeepnoteEnvironmentStorage ) private readonly storage : DeepnoteEnvironmentStorage ,
3242 @inject ( IDeepnoteToolkitInstaller ) private readonly toolkitInstaller : IDeepnoteToolkitInstaller ,
3343 @inject ( IDeepnoteServerStarter ) private readonly serverStarter : IDeepnoteServerStarter ,
44+ @inject ( IDeepnoteServerProvider ) private readonly serverProvider : IDeepnoteServerProvider ,
45+ @inject ( IJupyterRequestCreator ) private readonly requestCreator : IJupyterRequestCreator ,
46+ @inject ( IJupyterRequestAgentCreator )
47+ @optional ( )
48+ private readonly requestAgentCreator : IJupyterRequestAgentCreator | undefined ,
49+ @inject ( IConfigurationService ) private readonly configService : IConfigurationService ,
3450 @inject ( IOutputChannel ) @named ( STANDARD_OUTPUT_CHANNEL ) private readonly outputChannel : IOutputChannel
3551 ) { }
3652
@@ -135,6 +151,8 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
135151 let status : EnvironmentStatus ;
136152 if ( config . serverInfo ) {
137153 status = EnvironmentStatus . Running ;
154+ } else if ( this . tmpStartingServers . get ( id ) ) {
155+ status = EnvironmentStatus . Starting ;
138156 } else {
139157 status = EnvironmentStatus . Stopped ;
140158 }
@@ -207,6 +225,9 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
207225 throw new Error ( `Environment not found: ${ id } ` ) ;
208226 }
209227
228+ this . tmpStartingServers . set ( id , true ) ;
229+ this . _onDidChangeEnvironments . fire ( ) ;
230+
210231 try {
211232 logger . info ( `Ensuring server is running for environment: ${ config . name } (${ id } )` ) ;
212233
@@ -239,6 +260,8 @@ export class DeepnoteEnvironmentManager implements IExtensionSyncActivationServi
239260 } catch ( error ) {
240261 logger . error ( `Failed to start server for environment: ${ config . name } (${ id } )` , error ) ;
241262 throw error ;
263+ } finally {
264+ this . tmpStartingServers . delete ( id ) ;
242265 }
243266 }
244267
0 commit comments