@@ -651,7 +651,7 @@ function installCLIProxy(context: vscode.ExtensionContext, output: vscode.Output
651
651
652
652
type TerminalOpenMode = 'tab-before' | 'tab-after' | 'split-left' | 'split-right' | 'split-top' | 'split-bottom' ;
653
653
654
- export async function registerTasks ( context : GitpodExtensionContext ) : Promise < void > {
654
+ export async function registerTasks ( context : GitpodExtensionContext , createTerminal : ( options : vscode . ExtensionTerminalOptions , parent : vscode . Terminal | undefined ) => vscode . Terminal ) : Promise < void > {
655
655
const tokenSource = new vscode . CancellationTokenSource ( ) ;
656
656
const token = tokenSource . token ;
657
657
context . subscriptions . push ( {
@@ -698,30 +698,42 @@ export async function registerTasks(context: GitpodExtensionContext): Promise<vo
698
698
return ;
699
699
}
700
700
701
- const terminals = new Map < string , SupervisorTerminal > ( ) ;
701
+ const taskTerminals = new Map < string , SupervisorTerminal > ( ) ;
702
702
try {
703
703
const response = await util . promisify ( context . supervisor . terminal . list . bind ( context . supervisor . terminal , new ListTerminalsRequest ( ) , context . supervisor . metadata , {
704
704
deadline : Date . now ( ) + context . supervisor . deadlines . long
705
705
} ) ) ( ) ;
706
- for ( const terminal of response . getTerminalsList ( ) ) {
707
- terminals . set ( terminal . getAlias ( ) , terminal ) ;
706
+ for ( const term of response . getTerminalsList ( ) ) {
707
+ taskTerminals . set ( term . getAlias ( ) , term ) ;
708
708
}
709
709
} catch ( e ) {
710
- console . error ( 'failed to list terminals:' , e ) ;
710
+ console . error ( 'failed to list task terminals:' , e ) ;
711
711
}
712
712
713
713
let prevTerminal : vscode . Terminal | undefined ;
714
714
for ( const [ alias , taskStatus ] of tasks . entries ( ) ) {
715
- const terminal = terminals . get ( alias ) ;
716
- if ( terminal ) {
715
+ const taskTerminal = taskTerminals . get ( alias ) ;
716
+ if ( taskTerminal ) {
717
717
const openMode : TerminalOpenMode | undefined = taskStatus . getPresentation ( ) ?. getOpenMode ( ) as TerminalOpenMode ;
718
- let parentTerminal = ( openMode && openMode !== 'tab-before' && openMode !== 'tab-after' ) ? prevTerminal : undefined ;
719
- prevTerminal = registerTask ( alias , terminal . getTitle ( ) , context , token , parentTerminal ) ;
718
+ const parentTerminal = ( openMode && openMode !== 'tab-before' && openMode !== 'tab-after' ) ? prevTerminal : undefined ;
719
+ const pty = createTaskPty ( alias , context , token ) ;
720
+
721
+ // Delegate creation of the terminal to the extension caller
722
+ // if proposed API usage is required.
723
+ const terminal = createTerminal (
724
+ {
725
+ name : taskTerminal . getTitle ( ) ,
726
+ pty
727
+ } ,
728
+ parentTerminal
729
+ ) ;
730
+ terminal . show ( ) ;
731
+ prevTerminal = terminal ;
720
732
}
721
733
}
722
734
}
723
735
724
- function registerTask ( alias : string , initialTitle : string , context : GitpodExtensionContext , contextToken : vscode . CancellationToken , parentTerminal ?: vscode . Terminal ) : vscode . Terminal {
736
+ function createTaskPty ( alias : string , context : GitpodExtensionContext , contextToken : vscode . CancellationToken ) : vscode . Pseudoterminal {
725
737
const tokenSource = new vscode . CancellationTokenSource ( ) ;
726
738
contextToken . onCancellationRequested ( ( ) => tokenSource . cancel ( ) ) ;
727
739
const token = tokenSource . token ;
@@ -876,16 +888,5 @@ function registerTask(alias: string, initialTitle: string, context: GitpodExtens
876
888
}
877
889
} ;
878
890
879
- let proposedOptions = vscode . env . uiKind === vscode . UIKind . Web ? {
880
- location : parentTerminal ? { parentTerminal } : 1 /* vscode.TerminalLocation.Panel */
881
- } : { } ;
882
- proposedOptions = { } ; // TODO: enable this
883
- const terminal = vscode . window . createTerminal ( {
884
- name : initialTitle ,
885
- pty,
886
- ...proposedOptions
887
- } ) ;
888
- terminal . show ( ) ;
889
-
890
- return terminal ;
891
+ return pty ;
891
892
}
0 commit comments