@@ -534,20 +534,47 @@ export class MainThreadTask implements MainThreadTaskShape {
534
534
}
535
535
}
536
536
537
- public $executeTask ( value : TaskDTO ) : Promise < TaskExecutionDTO > {
537
+ // Passing in a TaskHandleDTO will cause the task to get re-resolved, which is important for tasks are coming from the core,
538
+ // such as those gotten from a fetchTasks, since they can have missing configuration properties.
539
+ public $executeTask ( value : TaskHandleDTO | TaskDTO ) : Promise < TaskExecutionDTO > {
538
540
return new Promise < TaskExecutionDTO > ( ( resolve , reject ) => {
539
- const task = TaskDTO . to ( value , this . _workspaceContextServer , true ) ! ;
540
- this . _taskService . run ( task ) . then ( undefined , reason => {
541
- // eat the error, it has already been surfaced to the user and we don't care about it here
542
- } ) ;
543
- const result : TaskExecutionDTO = {
544
- id : task . _id ,
545
- task : TaskDTO . from ( task )
546
- } ;
547
- resolve ( result ) ;
541
+ if ( TaskHandleDTO . is ( value ) ) {
542
+ const workspaceFolder = typeof value . workspaceFolder === 'string' ? value . workspaceFolder : this . _workspaceContextServer . getWorkspaceFolder ( URI . revive ( value . workspaceFolder ) ) ;
543
+ if ( workspaceFolder ) {
544
+ this . _taskService . getTask ( workspaceFolder , value . id , true ) . then ( ( task : Task | undefined ) => {
545
+ if ( ! task ) {
546
+ reject ( new Error ( 'Task not found' ) ) ;
547
+ } else {
548
+ this . _taskService . run ( task ) . then ( undefined , reason => {
549
+ // eat the error, it has already been surfaced to the user and we don't care about it here
550
+ } ) ;
551
+ const result : TaskExecutionDTO = {
552
+ id : value . id ,
553
+ task : TaskDTO . from ( task )
554
+ } ;
555
+ resolve ( result ) ;
556
+ }
557
+ } , ( _error ) => {
558
+ reject ( new Error ( 'Task not found' ) ) ;
559
+ } ) ;
560
+ } else {
561
+ reject ( new Error ( 'No workspace folder' ) ) ;
562
+ }
563
+ } else {
564
+ const task = TaskDTO . to ( value , this . _workspaceContextServer , true ) ! ;
565
+ this . _taskService . run ( task ) . then ( undefined , reason => {
566
+ // eat the error, it has already been surfaced to the user and we don't care about it here
567
+ } ) ;
568
+ const result : TaskExecutionDTO = {
569
+ id : task . _id ,
570
+ task : TaskDTO . from ( task )
571
+ } ;
572
+ resolve ( result ) ;
573
+ }
548
574
} ) ;
549
575
}
550
576
577
+
551
578
public $customExecutionComplete ( id : string , result ?: number ) : Promise < void > {
552
579
return new Promise < void > ( ( resolve , reject ) => {
553
580
this . _taskService . getActiveTasks ( ) . then ( ( tasks ) => {
0 commit comments