@@ -22,6 +22,7 @@ import {
2222 ProcessExecutionOptionsDTO , ProcessExecutionDTO ,
2323 ShellExecutionOptionsDTO , ShellExecutionDTO ,
2424 CustomExecutionDTO ,
25+ CustomExecution2DTO ,
2526 TaskDTO , TaskHandleDTO , TaskFilterDTO , TaskProcessStartedDTO , TaskProcessEndedDTO , TaskSystemInfoDTO , TaskSetDTO
2627} from '../common/shared/tasks' ;
2728import { ExtHostVariableResolverService } from 'vs/workbench/api/node/extHostDebugService' ;
@@ -79,7 +80,7 @@ namespace ProcessExecutionOptionsDTO {
7980}
8081
8182namespace ProcessExecutionDTO {
82- export function is ( value : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | undefined ) : value is ProcessExecutionDTO {
83+ export function is ( value : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | CustomExecution2DTO | undefined ) : value is ProcessExecutionDTO {
8384 if ( value ) {
8485 const candidate = value as ProcessExecutionDTO ;
8586 return candidate && ! ! candidate . process ;
@@ -124,7 +125,7 @@ namespace ShellExecutionOptionsDTO {
124125}
125126
126127namespace ShellExecutionDTO {
127- export function is ( value : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | undefined ) : value is ShellExecutionDTO {
128+ export function is ( value : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | CustomExecution2DTO | undefined ) : value is ShellExecutionDTO {
128129 if ( value ) {
129130 const candidate = value as ShellExecutionDTO ;
130131 return candidate && ( ! ! candidate . commandLine || ! ! candidate . command ) ;
@@ -162,7 +163,7 @@ namespace ShellExecutionDTO {
162163}
163164
164165namespace CustomExecutionDTO {
165- export function is ( value : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | undefined ) : value is CustomExecutionDTO {
166+ export function is ( value : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | CustomExecution2DTO | undefined ) : value is CustomExecutionDTO {
166167 if ( value ) {
167168 let candidate = value as CustomExecutionDTO ;
168169 return candidate && candidate . customExecution === 'customExecution' ;
@@ -178,6 +179,23 @@ namespace CustomExecutionDTO {
178179 }
179180}
180181
182+ namespace CustomExecution2DTO {
183+ export function is ( value : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | CustomExecution2DTO | undefined ) : value is CustomExecution2DTO {
184+ if ( value ) {
185+ let candidate = value as CustomExecution2DTO ;
186+ return candidate && candidate . customExecution === 'customExecution2' ;
187+ } else {
188+ return false ;
189+ }
190+ }
191+
192+ export function from ( value : vscode . CustomExecution2 ) : CustomExecution2DTO {
193+ return {
194+ customExecution : 'customExecution2'
195+ } ;
196+ }
197+ }
198+
181199namespace TaskHandleDTO {
182200 export function from ( value : types . Task ) : TaskHandleDTO {
183201 let folder : UriComponents | undefined ;
@@ -211,14 +229,17 @@ namespace TaskDTO {
211229 if ( value === undefined || value === null ) {
212230 return undefined ;
213231 }
214- let execution : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | undefined ;
232+ let execution : ShellExecutionDTO | ProcessExecutionDTO | CustomExecutionDTO | CustomExecution2DTO | undefined ;
215233 if ( value . execution instanceof types . ProcessExecution ) {
216234 execution = ProcessExecutionDTO . from ( value . execution ) ;
217235 } else if ( value . execution instanceof types . ShellExecution ) {
218236 execution = ShellExecutionDTO . from ( value . execution ) ;
219237 } else if ( ( < vscode . Task2 > value ) . execution2 && ( < vscode . Task2 > value ) . execution2 instanceof types . CustomExecution ) {
220238 execution = CustomExecutionDTO . from ( < types . CustomExecution > ( < vscode . Task2 > value ) . execution2 ) ;
239+ } else if ( ( < vscode . Task2 > value ) . execution2 && ( < vscode . Task2 > value ) . execution2 instanceof types . CustomExecution2 ) {
240+ execution = CustomExecution2DTO . from ( < types . CustomExecution2 > ( < vscode . Task2 > value ) . execution2 ) ;
221241 }
242+
222243 const definition : TaskDefinitionDTO | undefined = TaskDefinitionDTO . from ( value . definition ) ;
223244 let scope : number | UriComponents ;
224245 if ( value . scope ) {
@@ -468,6 +489,8 @@ export class ExtHostTask implements ExtHostTaskShape {
468489 private _taskExecutions : Map < string , TaskExecutionImpl > ;
469490 private _providedCustomExecutions : Map < string , CustomExecutionData > ;
470491 private _activeCustomExecutions : Map < string , CustomExecutionData > ;
492+ private _providedCustomExecutions2 : Map < string , vscode . CustomExecution2 > ;
493+ private _activeCustomExecutions2 : Map < string , vscode . CustomExecution2 > ;
471494
472495 private readonly _onDidExecuteTask : Emitter < vscode . TaskStartEvent > = new Emitter < vscode . TaskStartEvent > ( ) ;
473496 private readonly _onDidTerminateTask : Emitter < vscode . TaskEndEvent > = new Emitter < vscode . TaskEndEvent > ( ) ;
@@ -491,6 +514,8 @@ export class ExtHostTask implements ExtHostTaskShape {
491514 this . _taskExecutions = new Map < string , TaskExecutionImpl > ( ) ;
492515 this . _providedCustomExecutions = new Map < string , CustomExecutionData > ( ) ;
493516 this . _activeCustomExecutions = new Map < string , CustomExecutionData > ( ) ;
517+ this . _providedCustomExecutions2 = new Map < string , vscode . CustomExecution2 > ( ) ;
518+ this . _activeCustomExecutions2 = new Map < string , vscode . CustomExecution2 > ( ) ;
494519 }
495520
496521 public registerTaskProvider ( extension : IExtensionDescription , type : string , provider : vscode . TaskProvider ) : vscode . Disposable {
@@ -555,6 +580,19 @@ export class ExtHostTask implements ExtHostTaskShape {
555580 }
556581
557582 public async $onDidStartTask ( execution : TaskExecutionDTO , terminalId : number ) : Promise < void > {
583+ const execution2 : vscode . CustomExecution2 | undefined = this . _providedCustomExecutions2 . get ( execution . id ) ;
584+ if ( execution2 ) {
585+ if ( this . _activeCustomExecutions2 . get ( execution . id ) !== undefined ) {
586+ throw new Error ( 'We should not be trying to start the same custom task executions twice.' ) ;
587+ }
588+
589+ // Clone the custom execution to keep the original untouched. This is important for multiple runs of the same task.
590+ this . _activeCustomExecutions2 . set ( execution . id , execution2 ) ;
591+ this . _terminalService . performTerminalIdAction ( terminalId , async terminal => {
592+ this . _terminalService . attachVirtualProcessToTerminal ( terminalId , await execution2 . callback ( ) ) ;
593+ } ) ;
594+ }
595+
558596 // Once a terminal is spun up for the custom execution task this event will be fired.
559597 // At that point, we need to actually start the callback, but
560598 // only if it hasn't already begun.
@@ -630,6 +668,7 @@ export class ExtHostTask implements ExtHostTaskShape {
630668 // since we obviously cannot send callback functions through the proxy.
631669 // So, clear out any existing ones.
632670 this . _providedCustomExecutions . clear ( ) ;
671+ this . _providedCustomExecutions2 . clear ( ) ;
633672
634673 // Set up a list of task ID promises that we can wait on
635674 // before returning the provided tasks. The ensures that
@@ -657,6 +696,9 @@ export class ExtHostTask implements ExtHostTaskShape {
657696 // We need the task id's pre-computed for custom task executions because when OnDidStartTask
658697 // is invoked, we have to be able to map it back to our data.
659698 taskIdPromises . push ( this . addCustomExecution ( taskDTO , < vscode . Task2 > task ) ) ;
699+ } else if ( CustomExecution2DTO . is ( taskDTO . execution ) ) {
700+ taskIdPromises . push ( this . addCustomExecution2 ( taskDTO , < vscode . Task2 > task ) ) ;
701+
660702 }
661703 }
662704 }
@@ -705,6 +747,10 @@ export class ExtHostTask implements ExtHostTaskShape {
705747 await this . addCustomExecution ( taskDTO , < vscode . Task2 > task ) ;
706748 }
707749
750+ if ( CustomExecution2DTO . is ( resolvedTaskDTO . execution ) ) {
751+ await this . addCustomExecution2 ( taskDTO , < vscode . Task2 > task ) ;
752+ }
753+
708754 return resolvedTaskDTO ;
709755 }
710756
@@ -758,6 +804,11 @@ export class ExtHostTask implements ExtHostTaskShape {
758804 this . _providedCustomExecutions . set ( taskId , new CustomExecutionData ( < vscode . CustomExecution > ( < vscode . Task2 > task ) . execution2 , this . _terminalService ) ) ;
759805 }
760806
807+ private async addCustomExecution2 ( taskDTO : TaskDTO , task : vscode . Task2 ) : Promise < void > {
808+ const taskId = await this . _proxy . $createTaskId ( taskDTO ) ;
809+ this . _providedCustomExecutions2 . set ( taskId , < vscode . CustomExecution2 > ( < vscode . Task2 > task ) . execution2 ) ;
810+ }
811+
761812 private async getTaskExecution ( execution : TaskExecutionDTO | string , task ?: vscode . Task ) : Promise < TaskExecutionImpl > {
762813 if ( typeof execution === 'string' ) {
763814 const taskExecution = this . _taskExecutions . get ( execution ) ;
@@ -787,5 +838,9 @@ export class ExtHostTask implements ExtHostTaskShape {
787838 this . _proxy . $customExecutionComplete ( execution . id , extensionCallback . result ) ;
788839 extensionCallback . dispose ( ) ;
789840 }
841+ const extensionCallback2 : vscode . CustomExecution2 | undefined = this . _activeCustomExecutions2 . get ( execution . id ) ;
842+ if ( extensionCallback2 ) {
843+ this . _activeCustomExecutions2 . delete ( execution . id ) ;
844+ }
790845 }
791846}
0 commit comments