@@ -629,23 +629,15 @@ export async function registerTasks(context: GitpodExtensionContext): Promise<vo
629
629
const taskTerminal = taskTerminals . get ( alias ) ;
630
630
if ( taskTerminal ) {
631
631
const openMode : TerminalOpenMode | undefined = taskStatus . getPresentation ( ) ?. getOpenMode ( ) as TerminalOpenMode ;
632
- const parentTerminal = ( openMode && openMode !== 'tab-before' && openMode !== 'tab-after' ) ? prevTerminal : undefined ;
633
- const pty = createTaskPty ( alias , context , token ) ;
634
-
635
- const terminal = vscode . window . createTerminal ( {
636
- name : taskTerminal . getTitle ( ) ,
637
- pty,
638
- iconPath : new vscode . ThemeIcon ( 'terminal' ) ,
639
- location : parentTerminal ? { parentTerminal } : vscode . TerminalLocation . Panel
640
- } ) ;
632
+ const terminal = createTaskTerminal ( taskTerminal , prevTerminal , openMode , alias , context , token ) ;
641
633
prevTerminal = terminal ;
642
634
}
643
635
}
644
636
// Focus last created terminal
645
637
prevTerminal ?. show ( ) ;
646
638
}
647
639
648
- function createTaskPty ( alias : string , context : GitpodExtensionContext , contextToken : vscode . CancellationToken ) : vscode . Pseudoterminal {
640
+ function createTaskTerminal ( taskTerminal : SupervisorTerminal , prevTerminal : vscode . Terminal | undefined , openMode : TerminalOpenMode , alias : string , context : GitpodExtensionContext , contextToken : vscode . CancellationToken ) : vscode . Terminal {
649
641
const tokenSource = new vscode . CancellationTokenSource ( ) ;
650
642
contextToken . onCancellationRequested ( ( ) => tokenSource . cancel ( ) ) ;
651
643
const token = tokenSource . token ;
@@ -656,6 +648,7 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
656
648
const toDispose = vscode . Disposable . from ( onDidWriteEmitter , onDidCloseEmitter , onDidChangeNameEmitter ) ;
657
649
token . onCancellationRequested ( ( ) => toDispose . dispose ( ) ) ;
658
650
651
+ let terminal : vscode . Terminal
659
652
let pendingWrite = Promise . resolve ( ) ;
660
653
let pendingResize = Promise . resolve ( ) ;
661
654
const pty : vscode . Pseudoterminal = {
@@ -732,13 +725,15 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
732
725
return ;
733
726
}
734
727
tokenSource . cancel ( ) ;
735
-
736
- // await to make sure that close is not cause by the extension host process termination
737
- // in such case we don't want to stop supervisor terminals
728
+ // wait next tick to ensure terminal has exitStatus
738
729
setTimeout ( async ( ) => {
739
730
if ( contextToken . isCancellationRequested ) {
740
731
return ;
741
732
}
733
+ // we don't close tasks if terminal is closed by window reload
734
+ if ( terminal . exitStatus ?. reason === vscode . TerminalExitReason . Shutdown ) {
735
+ return ;
736
+ }
742
737
// Attempt to kill the pty, it may have already been killed at this
743
738
// point but we want to make sure
744
739
try {
@@ -756,8 +751,7 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
756
751
console . error ( `${ alias } terminal: shutdown failed:` , e ) ;
757
752
}
758
753
}
759
- } , 1000 ) ;
760
-
754
+ } , 0 )
761
755
} ,
762
756
handleInput : async ( data : string ) => {
763
757
if ( token . isCancellationRequested ) {
@@ -811,8 +805,16 @@ function createTaskPty(alias: string, context: GitpodExtensionContext, contextTo
811
805
} ) ;
812
806
}
813
807
} ;
808
+ const parentTerminal = ( openMode && openMode !== 'tab-before' && openMode !== 'tab-after' ) ? prevTerminal : undefined ;
809
+
810
+ terminal = vscode . window . createTerminal ( {
811
+ name : taskTerminal . getTitle ( ) ,
812
+ pty,
813
+ iconPath : new vscode . ThemeIcon ( 'terminal' ) ,
814
+ location : parentTerminal ? { parentTerminal } : vscode . TerminalLocation . Panel
815
+ } ) ;
814
816
815
- return pty ;
817
+ return terminal ;
816
818
}
817
819
818
820
/**
0 commit comments