@@ -310,7 +310,7 @@ export class CodeApplication extends Disposable {
310310 }
311311 }
312312
313- startup ( ) : Promise < void > {
313+ async startup ( ) : Promise < void > {
314314 this . logService . debug ( 'Starting VS Code' ) ;
315315 this . logService . debug ( `from: ${ this . environmentService . appRoot } ` ) ;
316316 this . logService . debug ( 'args:' , this . environmentService . args ) ;
@@ -340,62 +340,55 @@ export class CodeApplication extends Disposable {
340340 // Create Electron IPC Server
341341 this . electronIpcServer = new ElectronIPCServer ( ) ;
342342
343- const startupWithMachineId = ( machineId : string ) => {
344- this . logService . trace ( `Resolved machine identifier: ${ machineId } ` ) ;
343+ // Resolve unique machine ID
344+ this . logService . trace ( 'Resolving machine identifier...' ) ;
345+ const machineId = await this . resolveMachineId ( ) ;
346+ this . logService . trace ( `Resolved machine identifier: ${ machineId } ` ) ;
345347
346- // Spawn shared process
347- this . sharedProcess = this . instantiationService . createInstance ( SharedProcess , machineId , this . userEnv ) ;
348- this . sharedProcessClient = this . sharedProcess . whenReady ( ) . then ( ( ) => connect ( this . environmentService . sharedIPCHandle , 'main' ) ) ;
348+ // Spawn shared process
349+ this . sharedProcess = this . instantiationService . createInstance ( SharedProcess , machineId , this . userEnv ) ;
350+ this . sharedProcessClient = this . sharedProcess . whenReady ( ) . then ( ( ) => connect ( this . environmentService . sharedIPCHandle , 'main' ) ) ;
349351
350- // Services
351- return this . initServices ( machineId ) . then ( appInstantiationService => {
352+ // Services
353+ const appInstantiationService = await this . initServices ( machineId ) ;
352354
353- // Create driver
354- if ( this . environmentService . driverHandle ) {
355- serveDriver ( this . electronIpcServer , this . environmentService . driverHandle , this . environmentService , appInstantiationService ) . then ( server => {
356- this . logService . info ( 'Driver started at:' , this . environmentService . driverHandle ) ;
357- this . _register ( server ) ;
358- } ) ;
359- }
355+ // Create driver
356+ if ( this . environmentService . driverHandle ) {
357+ ( async ( ) => {
358+ const server = await serveDriver ( this . electronIpcServer , this . environmentService . driverHandle ! , this . environmentService , appInstantiationService ) ;
360359
361- // Setup Auth Handler
362- const authHandler = appInstantiationService . createInstance ( ProxyAuthHandler ) ;
363- this . _register ( authHandler ) ;
360+ this . logService . info ( 'Driver started at:' , this . environmentService . driverHandle ) ;
361+ this . _register ( server ) ;
362+ } ) ( ) ;
363+ }
364364
365- // Open Windows
366- const windows = appInstantiationService . invokeFunction ( accessor => this . openFirstWindow ( accessor ) ) ;
365+ // Setup Auth Handler
366+ const authHandler = appInstantiationService . createInstance ( ProxyAuthHandler ) ;
367+ this . _register ( authHandler ) ;
367368
368- // Post Open Windows Tasks
369- appInstantiationService . invokeFunction ( accessor => this . afterWindowOpen ( accessor ) ) ;
369+ // Open Windows
370+ const windows = appInstantiationService . invokeFunction ( accessor => this . openFirstWindow ( accessor ) ) ;
370371
371- // Tracing: Stop tracing after windows are ready if enabled
372- if ( this . environmentService . args . trace ) {
373- this . stopTracingEventually ( windows ) ;
374- }
375- } ) ;
376- } ;
372+ // Post Open Windows Tasks
373+ appInstantiationService . invokeFunction ( accessor => this . afterWindowOpen ( accessor ) ) ;
377374
378- // Resolve unique machine ID
379- this . logService . trace ( 'Resolving machine identifier...' ) ;
380- const resolvedMachineId = this . resolveMachineId ( ) ;
381- if ( typeof resolvedMachineId === 'string' ) {
382- return startupWithMachineId ( resolvedMachineId ) ;
383- } else {
384- return resolvedMachineId . then ( machineId => startupWithMachineId ( machineId ) ) ;
375+ // Tracing: Stop tracing after windows are ready if enabled
376+ if ( this . environmentService . args . trace ) {
377+ this . stopTracingEventually ( windows ) ;
385378 }
386379 }
387380
388- private resolveMachineId ( ) : string | Promise < string > {
389- const machineId = this . stateService . getItem < string > ( CodeApplication . MACHINE_ID_KEY ) ;
381+ private async resolveMachineId ( ) : Promise < string > {
382+ let machineId = this . stateService . getItem < string > ( CodeApplication . MACHINE_ID_KEY ) ;
390383 if ( machineId ) {
391384 return machineId ;
392385 }
393386
394- return getMachineId ( ) . then ( machineId => {
395- this . stateService . setItem ( CodeApplication . MACHINE_ID_KEY , machineId ) ;
387+ machineId = await getMachineId ( ) ;
396388
397- return machineId ;
398- } ) ;
389+ this . stateService . setItem ( CodeApplication . MACHINE_ID_KEY , machineId ) ;
390+
391+ return machineId ;
399392 }
400393
401394 private stopTracingEventually ( windows : ICodeWindow [ ] ) : void {
@@ -433,7 +426,7 @@ export class CodeApplication extends Disposable {
433426 } ) ;
434427 }
435428
436- private initServices ( machineId : string ) : Promise < IInstantiationService > {
429+ private async initServices ( machineId : string ) : Promise < IInstantiationService > {
437430 const services = new ServiceCollection ( ) ;
438431
439432 if ( process . platform === 'win32' ) {
@@ -475,10 +468,12 @@ export class CodeApplication extends Disposable {
475468 const appInstantiationService = this . instantiationService . createChild ( services ) ;
476469
477470 // Init services that require it
478- return appInstantiationService . invokeFunction ( accessor => Promise . all ( [
471+ await appInstantiationService . invokeFunction ( accessor => Promise . all ( [
479472 this . initStorageService ( accessor ) ,
480473 this . initBackupService ( accessor )
481- ] ) ) . then ( ( ) => appInstantiationService ) ;
474+ ] ) ) ;
475+
476+ return appInstantiationService ;
482477 }
483478
484479 private initStorageService ( accessor : ServicesAccessor ) : Promise < void > {
@@ -558,15 +553,17 @@ export class CodeApplication extends Disposable {
558553 const environmentService = accessor . get ( IEnvironmentService ) ;
559554
560555 urlService . registerHandler ( {
561- handleURL ( uri : URI ) : Promise < boolean > {
556+ async handleURL ( uri : URI ) : Promise < boolean > {
562557 if ( windowsMainService . getWindowCount ( ) === 0 ) {
563558 const cli = { ...environmentService . args , goto : true } ;
564559 const [ window ] = windowsMainService . open ( { context : OpenContext . API , cli, forceEmpty : true } ) ;
565560
566- return window . ready ( ) . then ( ( ) => urlService . open ( uri ) ) ;
561+ await window . ready ( ) ;
562+
563+ return urlService . open ( uri ) ;
567564 }
568565
569- return Promise . resolve ( false ) ;
566+ return false ;
570567 }
571568 } ) ;
572569 }
@@ -738,9 +735,7 @@ export class CodeApplication extends Disposable {
738735 dispose ( ) : void {
739736 this . _disposeRunner . dispose ( ) ;
740737 connectionPool . delete ( this . _authority ) ;
741- this . _connection . then ( ( connection ) => {
742- connection . dispose ( ) ;
743- } ) ;
738+ this . _connection . then ( connection => connection . dispose ( ) ) ;
744739 }
745740
746741 async getClient ( ) : Promise < Client < RemoteAgentConnectionContext > > {
0 commit comments