@@ -400,6 +400,10 @@ export class DebugService implements IDebugService {
400400 } ) ;
401401 }
402402
403+ private isExtensionHostDebugging ( config : IConfig ) {
404+ return equalsIgnoreCase ( config . type , 'extensionhost' ) ;
405+ }
406+
403407 private attachExtensionHost ( session : Session , port : number ) : TPromise < void > {
404408
405409 session . configuration . request = 'attach' ;
@@ -418,18 +422,25 @@ export class DebugService implements IDebugService {
418422 const session = this . instantiationService . createInstance ( Session , configuration , root , this . model ) ;
419423 this . allSessions . set ( session . getId ( ) , session ) ;
420424
425+ // register listeners as the very first thing!
426+ this . registerSessionListeners ( session ) ;
427+
428+ // since the Session is now properly registered under its ID and hooked, we can announce it
429+ // this event doesn't go to extensions
421430 this . _onWillNewSession . fire ( session ) ;
422431
423432 const resolved = configuration . resolved ;
424- resolved . __sessionId = session . getId ( ) ;
425433 const dbgr = this . configurationManager . getDebugger ( resolved . type ) ;
426434
427435 return session . initialize ( dbgr ) . then ( ( ) => {
428436
429- this . registerSessionListeners ( session ) ;
430-
431437 const raw = < RawDebugSession > session . raw ;
432438
439+ // pass the sessionID for EH debugging
440+ if ( this . isExtensionHostDebugging ( resolved ) ) {
441+ resolved . __sessionId = session . getId ( ) ;
442+ }
443+
433444 return ( resolved . request === 'attach' ? raw . attach ( resolved ) : raw . launch ( resolved ) ) . then ( result => {
434445
435446 if ( raw . disconnected ) {
@@ -438,6 +449,7 @@ export class DebugService implements IDebugService {
438449
439450 this . focusStackFrame ( undefined , undefined , session ) ;
440451
452+ // since the initialized response has arrived announce the new Session (including extensions)
441453 this . _onDidNewSession . fire ( session ) ;
442454
443455 const internalConsoleOptions = resolved . internalConsoleOptions || this . configurationService . getValue < IDebugConfiguration > ( 'debug' ) . internalConsoleOptions ;
@@ -460,6 +472,7 @@ export class DebugService implements IDebugService {
460472 return this . telemetryDebugSessionStart ( root , resolved . type , dbgr . extensionDescription ) ;
461473
462474 } ) . then ( ( ) => session , ( error : Error | string ) => {
475+
463476 if ( session ) {
464477 session . dispose ( ) ;
465478 }
@@ -483,13 +496,18 @@ export class DebugService implements IDebugService {
483496 }
484497 return undefined ;
485498 } ) ;
486- } ) . then ( undefined , err => {
499+
500+ } ) . then ( undefined , error => {
487501
488502 if ( session ) {
489503 session . dispose ( ) ;
490504 }
491505
492- return TPromise . wrapError ( err ) ;
506+ if ( errors . isPromiseCanceledError ( error ) ) {
507+ // Do not show 'canceled' error messages to the user #7906
508+ return TPromise . as ( null ) ;
509+ }
510+ return TPromise . wrapError ( error ) ;
493511 } ) ;
494512 }
495513
@@ -502,10 +520,14 @@ export class DebugService implements IDebugService {
502520 this . onStateChange ( ) ;
503521 } ) ) ;
504522
505- this . toDispose . push ( session . onDidExitAdapter ( ( ) => {
523+ this . toDispose . push ( session . onDidExitAdapter ( err => {
524+
525+ if ( err ) {
526+ this . notificationService . error ( nls . localize ( 'debugAdapterCrash' , "Debug adapter process has terminated unexpectedly ({0})" , err . message || err . toString ( ) ) ) ;
527+ }
506528
507529 // 'Run without debugging' mode VSCode must terminate the extension host. More details: #3905
508- if ( equalsIgnoreCase ( session . configuration . type , 'extensionhost' ) && session . state === State . Running && session . configuration . noDebug ) {
530+ if ( this . isExtensionHostDebugging ( session . configuration ) && session . state === State . Running && session . configuration . noDebug ) {
509531 this . broadcastService . broadcast ( {
510532 channel : EXTENSION_CLOSE_EXTHOST_BROADCAST_CHANNEL ,
511533 payload : [ session . root . uri . toString ( ) ]
@@ -553,7 +575,7 @@ export class DebugService implements IDebugService {
553575 // Do not run preLaunch and postDebug tasks for automatic restarts
554576 this . skipRunningTask = ! ! restartData ;
555577
556- if ( equalsIgnoreCase ( session . configuration . type , 'extensionHost' ) && session . root ) {
578+ if ( this . isExtensionHostDebugging ( session . configuration ) && session . root ) {
557579 return this . broadcastService . broadcast ( {
558580 channel : EXTENSION_RELOAD_BROADCAST_CHANNEL ,
559581 payload : [ session . root . uri . toString ( ) ]
0 commit comments