@@ -19,7 +19,7 @@ import { IContextKey, IContextKeyService } from 'vs/platform/contextkey/common/c
19
19
import { IDialogService } from 'vs/platform/dialogs/common/dialogs' ;
20
20
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
21
21
import { INotificationService } from 'vs/platform/notification/common/notification' ;
22
- import { ICreateContributedTerminalProfileOptions , IShellLaunchConfig , ITerminalBackend , ITerminalLaunchError , ITerminalLogService , ITerminalsLayoutInfo , ITerminalsLayoutInfoById , TerminalExitReason , TerminalLocation , TerminalLocationString , TitleEventSource } from 'vs/platform/terminal/common/terminal' ;
22
+ import { ICreateContributedTerminalProfileOptions , IPtyHostAttachTarget , IRawTerminalInstanceLayoutInfo , IRawTerminalTabLayoutInfo , IShellLaunchConfig , ITerminalBackend , ITerminalLaunchError , ITerminalLogService , ITerminalsLayoutInfo , ITerminalsLayoutInfoById , TerminalExitReason , TerminalLocation , TerminalLocationString , TitleEventSource } from 'vs/platform/terminal/common/terminal' ;
23
23
import { formatMessageForTerminal } from 'vs/platform/terminal/common/terminalStrings' ;
24
24
import { iconForeground } from 'vs/platform/theme/common/colorRegistry' ;
25
25
import { getIconRegistry } from 'vs/platform/theme/common/iconRegistry' ;
@@ -457,55 +457,61 @@ export class TerminalService implements ITerminalService {
457
457
458
458
private async _recreateTerminalGroups ( layoutInfo ?: ITerminalsLayoutInfo ) : Promise < number > {
459
459
let reconnectCounter = 0 ;
460
- let activeGroup : ITerminalGroup | undefined ;
460
+ let activeGroup : Promise < ITerminalGroup | undefined > | undefined ;
461
461
if ( layoutInfo ) {
462
- for ( const groupLayout of layoutInfo . tabs ) {
463
- const terminalLayouts = groupLayout . terminals . filter ( t => t . terminal && t . terminal . isOrphan ) ;
462
+ const tabPromises : Promise < ITerminalGroup | undefined > [ ] = [ ] ;
463
+ for ( const tabLayout of layoutInfo . tabs ) {
464
+ const terminalLayouts = tabLayout . terminals . filter ( t => t . terminal && t . terminal . isOrphan ) ;
464
465
if ( terminalLayouts . length ) {
465
466
reconnectCounter += terminalLayouts . length ;
466
- let terminalInstance : ITerminalInstance | undefined ;
467
- let group : ITerminalGroup | undefined ;
468
- for ( const terminalLayout of terminalLayouts ) {
469
- const attachPersistentProcess = terminalLayout . terminal ! ;
470
- if ( this . _lifecycleService . startupKind !== StartupKind . ReloadedWindow && attachPersistentProcess . type === 'Task' ) {
471
- continue ;
472
- }
473
- mark ( `code/terminal/willRecreateTerminal/${ attachPersistentProcess . id } -${ attachPersistentProcess . pid } ` ) ;
474
- if ( ! terminalInstance ) {
475
- // create group and terminal
476
- terminalInstance = await this . createTerminal ( {
477
- config : { attachPersistentProcess } ,
478
- location : TerminalLocation . Panel
479
- } ) ;
480
- group = this . _terminalGroupService . getGroupForInstance ( terminalInstance ) ;
481
- if ( groupLayout . isActive ) {
482
- activeGroup = group ;
483
- }
484
- } else {
485
- // add split terminals to this group
486
- terminalInstance = await this . createTerminal ( {
487
- config : { attachPersistentProcess } ,
488
- location : { parentTerminal : terminalInstance }
489
- } ) ;
490
- }
491
- mark ( `code/terminal/didRecreateTerminal/${ attachPersistentProcess . id } -${ attachPersistentProcess . pid } ` ) ;
467
+ const promise = this . _recreateTerminalGroup ( tabLayout , terminalLayouts ) ;
468
+ tabPromises . push ( promise ) ;
469
+ if ( tabLayout . isActive ) {
470
+ activeGroup = promise ;
492
471
}
493
- const activeInstance = this . instances . find ( t => {
494
- return t . shellLaunchConfig . attachPersistentProcess ?. id === groupLayout . activePersistentProcessId ;
495
- } ) ;
472
+ const activeInstance = this . instances . find ( t => t . shellLaunchConfig . attachPersistentProcess ?. id === tabLayout . activePersistentProcessId ) ;
496
473
if ( activeInstance ) {
497
474
this . setActiveInstance ( activeInstance ) ;
498
475
}
499
- group ?. resizePanes ( groupLayout . terminals . map ( terminal => terminal . relativeSize ) ) ;
500
476
}
501
477
}
502
478
if ( layoutInfo . tabs . length ) {
503
- this . _terminalGroupService . activeGroup = activeGroup ;
479
+ activeGroup ?. then ( group => this . _terminalGroupService . activeGroup = group ) ;
504
480
}
505
481
}
506
482
return reconnectCounter ;
507
483
}
508
484
485
+ private async _recreateTerminalGroup ( tabLayout : IRawTerminalTabLayoutInfo < IPtyHostAttachTarget | null > , terminalLayouts : IRawTerminalInstanceLayoutInfo < IPtyHostAttachTarget | null > [ ] ) : Promise < ITerminalGroup | undefined > {
486
+ let lastInstance : Promise < ITerminalInstance > | undefined ;
487
+ let group : Promise < ITerminalGroup | undefined > | undefined ;
488
+ for ( const terminalLayout of terminalLayouts ) {
489
+ const attachPersistentProcess = terminalLayout . terminal ! ;
490
+ if ( this . _lifecycleService . startupKind !== StartupKind . ReloadedWindow && attachPersistentProcess . type === 'Task' ) {
491
+ continue ;
492
+ }
493
+ mark ( `code/terminal/willRecreateTerminal/${ attachPersistentProcess . id } -${ attachPersistentProcess . pid } ` ) ;
494
+ if ( ! lastInstance ) {
495
+ // create group and terminal
496
+ lastInstance = this . createTerminal ( {
497
+ config : { attachPersistentProcess } ,
498
+ location : TerminalLocation . Panel
499
+ } ) ;
500
+ group = lastInstance . then ( instance => this . _terminalGroupService . getGroupForInstance ( instance ) ) ;
501
+ } else {
502
+ // TODO: Make parentInstance a promise?
503
+ // add split terminals to this group
504
+ lastInstance = this . createTerminal ( {
505
+ config : { attachPersistentProcess } ,
506
+ location : { parentTerminal : lastInstance }
507
+ } ) ;
508
+ }
509
+ mark ( `code/terminal/didRecreateTerminal/${ attachPersistentProcess . id } -${ attachPersistentProcess . pid } ` ) ;
510
+ }
511
+ group ?. then ( g => g ?. resizePanes ( tabLayout . terminals . map ( terminal => terminal . relativeSize ) ) ) ;
512
+ return group ;
513
+ }
514
+
509
515
private _attachProcessLayoutListeners ( ) : void {
510
516
this . onDidChangeActiveGroup ( ( ) => this . _saveState ( ) ) ;
511
517
this . onDidChangeActiveInstance ( ( ) => this . _saveState ( ) ) ;
@@ -902,15 +908,15 @@ export class TerminalService implements ITerminalService {
902
908
return this . _terminalGroupService ;
903
909
}
904
910
905
- getInstanceHost ( location : ITerminalLocationOptions | undefined ) : ITerminalInstanceHost {
911
+ async getInstanceHost ( location : ITerminalLocationOptions | undefined ) : Promise < ITerminalInstanceHost > {
906
912
if ( location ) {
907
913
if ( location === TerminalLocation . Editor ) {
908
914
return this . _terminalEditorService ;
909
915
} else if ( typeof location === 'object' ) {
910
916
if ( 'viewColumn' in location ) {
911
917
return this . _terminalEditorService ;
912
918
} else if ( 'parentTerminal' in location ) {
913
- return location . parentTerminal . target === TerminalLocation . Editor ? this . _terminalEditorService : this . _terminalGroupService ;
919
+ return ( await location . parentTerminal ) . target === TerminalLocation . Editor ? this . _terminalEditorService : this . _terminalGroupService ;
914
920
}
915
921
} else {
916
922
return this . _terminalGroupService ;
@@ -954,7 +960,7 @@ export class TerminalService implements ITerminalService {
954
960
955
961
// Launch the contributed profile
956
962
if ( contributedProfile ) {
957
- const resolvedLocation = this . resolveLocation ( options ?. location ) ;
963
+ const resolvedLocation = await this . resolveLocation ( options ?. location ) ;
958
964
let location : TerminalLocation | { viewColumn : number ; preserveState ?: boolean } | { splitActiveTerminal : boolean } | undefined ;
959
965
if ( splitActiveTerminal ) {
960
966
location = resolvedLocation === TerminalLocation . Editor ? { viewColumn : SIDE_GROUP } : { splitActiveTerminal : true } ;
@@ -987,8 +993,8 @@ export class TerminalService implements ITerminalService {
987
993
}
988
994
989
995
this . _evaluateLocalCwd ( shellLaunchConfig ) ;
990
- const location = this . resolveLocation ( options ?. location ) || this . defaultLocation ;
991
- const parent = this . _getSplitParent ( options ?. location ) ;
996
+ const location = await this . resolveLocation ( options ?. location ) || this . defaultLocation ;
997
+ const parent = await this . _getSplitParent ( options ?. location ) ;
992
998
this . _terminalHasBeenCreated . set ( true ) ;
993
999
if ( parent ) {
994
1000
return this . _splitTerminal ( shellLaunchConfig , location , parent ) ;
@@ -1029,7 +1035,7 @@ export class TerminalService implements ITerminalService {
1029
1035
} else if ( splitActiveTerminal && options ?. location ) {
1030
1036
let parent = this . activeInstance ;
1031
1037
if ( typeof options . location === 'object' && 'parentTerminal' in options . location ) {
1032
- parent = options . location . parentTerminal ;
1038
+ parent = await options . location . parentTerminal ;
1033
1039
}
1034
1040
if ( ! parent ) {
1035
1041
throw new Error ( 'Cannot split without an active instance' ) ;
@@ -1090,11 +1096,12 @@ export class TerminalService implements ITerminalService {
1090
1096
return instance ;
1091
1097
}
1092
1098
1093
- resolveLocation ( location ?: ITerminalLocationOptions ) : TerminalLocation | undefined {
1099
+ async resolveLocation ( location ?: ITerminalLocationOptions ) : Promise < TerminalLocation | undefined > {
1094
1100
if ( location && typeof location === 'object' ) {
1095
1101
if ( 'parentTerminal' in location ) {
1096
1102
// since we don't set the target unless it's an editor terminal, this is necessary
1097
- return ! location . parentTerminal . target ? TerminalLocation . Panel : location . parentTerminal . target ;
1103
+ const parentTerminal = await location . parentTerminal ;
1104
+ return ! parentTerminal . target ? TerminalLocation . Panel : parentTerminal . target ;
1098
1105
} else if ( 'viewColumn' in location ) {
1099
1106
return TerminalLocation . Editor ;
1100
1107
} else if ( 'splitActiveTerminal' in location ) {
@@ -1105,7 +1112,7 @@ export class TerminalService implements ITerminalService {
1105
1112
return location ;
1106
1113
}
1107
1114
1108
- private _getSplitParent ( location ?: ITerminalLocationOptions ) : ITerminalInstance | undefined {
1115
+ private async _getSplitParent ( location ?: ITerminalLocationOptions ) : Promise < ITerminalInstance | undefined > {
1109
1116
if ( location && typeof location === 'object' && 'parentTerminal' in location ) {
1110
1117
return location . parentTerminal ;
1111
1118
} else if ( location && typeof location === 'object' && 'splitActiveTerminal' in location ) {
0 commit comments