@@ -2172,22 +2172,31 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
21722172 if ( ! this . _taskSystem ) {
21732173 return ;
21742174 }
2175- const response = await this . _taskSystem . terminate ( task ) ;
2176- if ( response . success ) {
2177- try {
2178- // Before restarting, check if the task still exists and get updated version
2179- const updatedTask = await this . _findUpdatedTask ( task ) ;
2180- if ( updatedTask ) {
2181- await this . run ( updatedTask ) ;
2182- } else {
2183- // Task no longer exists, show warning
2184- this . _notificationService . warn ( nls . localize ( 'TaskSystem.taskNoLongerExists' , 'Task {0} no longer exists or has been modified. Cannot restart.' , task . configurationProperties . name ) ) ;
2185- }
2186- } catch {
2187- // eat the error, we don't care about it here
2175+
2176+ // Check if the task is currently running
2177+ const isTaskRunning = await this . getActiveTasks ( ) . then ( tasks => tasks . some ( t => t . getMapKey ( ) === task . getMapKey ( ) ) ) ;
2178+
2179+ if ( isTaskRunning ) {
2180+ // Task is running, terminate it first
2181+ const response = await this . _taskSystem . terminate ( task ) ;
2182+ if ( ! response . success ) {
2183+ this . _notificationService . warn ( nls . localize ( 'TaskSystem.restartFailed' , 'Failed to terminate and restart task {0}' , Types . isString ( task ) ? task : task . configurationProperties . name ) ) ;
2184+ return ;
21882185 }
2189- } else {
2190- this . _notificationService . warn ( nls . localize ( 'TaskSystem.restartFailed' , 'Failed to terminate and restart task {0}' , Types . isString ( task ) ? task : task . configurationProperties . name ) ) ;
2186+ }
2187+
2188+ // Task is not running or was successfully terminated, now run it
2189+ try {
2190+ // Before restarting, check if the task still exists and get updated version
2191+ const updatedTask = await this . _findUpdatedTask ( task ) ;
2192+ if ( updatedTask ) {
2193+ await this . run ( updatedTask ) ;
2194+ } else {
2195+ // Task no longer exists, show warning
2196+ this . _notificationService . warn ( nls . localize ( 'TaskSystem.taskNoLongerExists' , 'Task {0} no longer exists or has been modified. Cannot restart.' , task . configurationProperties . name ) ) ;
2197+ }
2198+ } catch {
2199+ // eat the error, we don't care about it here
21912200 }
21922201 }
21932202
@@ -2275,6 +2284,17 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
22752284 } else {
22762285 return undefined ;
22772286 }
2287+ } ,
2288+ async ( taskKey : string ) => {
2289+ // Look up task by its map key across all workspace tasks
2290+ const taskMap = await this . _getGroupedTasks ( ) ;
2291+ const allTasks = taskMap . all ( ) ;
2292+ for ( const task of allTasks ) {
2293+ if ( task . getMapKey ( ) === taskKey ) {
2294+ return task ;
2295+ }
2296+ }
2297+ return undefined ;
22782298 }
22792299 ) ;
22802300 }
@@ -3209,8 +3229,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
32093229 }
32103230
32113231
3212- rerun ( terminalInstanceId : number ) : void {
3213- const task = this . _taskSystem ?. getTaskForTerminal ( terminalInstanceId ) ;
3232+ async rerun ( terminalInstanceId : number ) : Promise < void > {
3233+ const task = await this . _taskSystem ?. getTaskForTerminal ( terminalInstanceId ) ;
32143234 if ( task ) {
32153235 this . _restart ( task ) ;
32163236 } else {
0 commit comments