Skip to content

Commit 73d2f24

Browse files
Copilotanthonykim1meganrogge
authored
Add command to re-run all running tasks (#252212)
* Initial plan * Implement re-run all running tasks command Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> * Improve implementation with constants and better user feedback Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> * Prevent awkward notification that closes terminal tab * Format * Remove menu registration for Rerun All Running Tasks command Co-authored-by: meganrogge <29464607+meganrogge@users.noreply.github.com> * Add completion feedback showing number of tasks restarted Co-authored-by: meganrogge <29464607+meganrogge@users.noreply.github.com> * address whitespace hygiene * do not add unrequested notification. --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: anthonykim1 <62267334+anthonykim1@users.noreply.github.com> Co-authored-by: Anthony Kim <anthonykim@microsoft.com> Co-authored-by: meganrogge <29464607+meganrogge@users.noreply.github.com>
1 parent a4896a2 commit 73d2f24

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import { ITextFileService } from '../../../services/textfile/common/textfiles.js
4747
import { ITerminalGroupService, ITerminalService } from '../../terminal/browser/terminal.js';
4848
import { ITerminalProfileResolverService } from '../../terminal/common/terminal.js';
4949

50-
import { ConfiguringTask, ContributedTask, CustomTask, ExecutionEngine, InMemoryTask, ITaskEvent, ITaskIdentifier, ITaskSet, JsonSchemaVersion, KeyedTaskIdentifier, RuntimeType, Task, TASK_RUNNING_STATE, TaskDefinition, TaskGroup, TaskRunSource, TaskSettingId, TaskSorter, TaskSourceKind, TasksSchemaProperties, USER_TASKS_GROUP_KEY, TaskEventKind, InstancePolicy } from '../common/tasks.js';
50+
import { ConfiguringTask, ContributedTask, CustomTask, ExecutionEngine, InMemoryTask, ITaskEvent, ITaskIdentifier, ITaskSet, JsonSchemaVersion, KeyedTaskIdentifier, RuntimeType, Task, TASK_RUNNING_STATE, TaskDefinition, TaskGroup, TaskRunSource, TaskSettingId, TaskSorter, TaskSourceKind, TasksSchemaProperties, USER_TASKS_GROUP_KEY, TaskEventKind, InstancePolicy, RerunAllRunningTasksCommandId } from '../common/tasks.js';
5151
import { CustomExecutionSupportedContext, ICustomizationProperties, IProblemMatcherRunOptions, ITaskFilter, ITaskProvider, ITaskService, IWorkspaceFolderTaskResult, ProcessExecutionSupportedContext, ServerlessWebContext, ShellExecutionSupportedContext, TaskCommandsRegistered, TaskExecutionSupportedContext } from '../common/taskService.js';
5252
import { ITaskExecuteResult, ITaskResolver, ITaskSummary, ITaskSystem, ITaskSystemInfo, ITaskTerminateResponse, TaskError, TaskErrors, TaskExecuteKind, Triggers, VerifiedTask } from '../common/taskSystem.js';
5353
import { getTemplates as getTaskTemplates } from '../common/taskTemplates.js';
@@ -533,6 +533,12 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
533533
}
534534
});
535535

536+
CommandsRegistry.registerCommand(RerunAllRunningTasksCommandId, async (accessor, arg) => {
537+
if (await this._trust()) {
538+
this._runRerunAllRunningTasksCommand();
539+
}
540+
});
541+
536542
CommandsRegistry.registerCommand('workbench.action.tasks.terminate', async (accessor, arg) => {
537543
if (await this._trust()) {
538544
this._runTerminateCommand(arg);
@@ -3364,6 +3370,19 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
33643370
}
33653371
}
33663372

3373+
private async _runRerunAllRunningTasksCommand(): Promise<void> {
3374+
const activeTasks = await this.getActiveTasks();
3375+
3376+
if (activeTasks.length === 0) {
3377+
this._notificationService.info(nls.localize('TaskService.noRunningTasks', 'No running tasks to restart'));
3378+
return;
3379+
}
3380+
3381+
// Restart all active tasks
3382+
const restartPromises = activeTasks.map(task => this._restart(task));
3383+
await Promise.allSettled(restartPromises);
3384+
}
3385+
33673386
private _getTaskIdentifier(filter?: string | ITaskIdentifier): string | KeyedTaskIdentifier | undefined {
33683387
let result: string | KeyedTaskIdentifier | undefined = undefined;
33693388
if (Types.isString(filter)) {

src/vs/workbench/contrib/tasks/browser/task.contribution.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { StatusbarAlignment, IStatusbarService, IStatusbarEntryAccessor, IStatus
2020

2121
import { IOutputChannelRegistry, Extensions as OutputExt } from '../../../services/output/common/output.js';
2222

23-
import { ITaskEvent, TaskGroup, TaskSettingId, TASKS_CATEGORY, TASK_RUNNING_STATE, TASK_TERMINAL_ACTIVE, TaskEventKind, rerunTaskIcon, RerunForActiveTerminalCommandId } from '../common/tasks.js';
23+
import { ITaskEvent, TaskGroup, TaskSettingId, TASKS_CATEGORY, TASK_RUNNING_STATE, TASK_TERMINAL_ACTIVE, TaskEventKind, rerunTaskIcon, RerunForActiveTerminalCommandId, RerunAllRunningTasksCommandId } from '../common/tasks.js';
2424
import { ITaskService, TaskCommandsRegistered, TaskExecutionSupportedContext } from '../common/taskService.js';
2525

2626
import { Extensions as WorkbenchExtensions, IWorkbenchContributionsRegistry, IWorkbenchContribution, WorkbenchPhase, registerWorkbenchContribution2 } from '../../../common/contributions.js';
@@ -286,6 +286,14 @@ MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
286286
},
287287
when: TaskExecutionSupportedContext
288288
});
289+
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
290+
command: {
291+
id: RerunAllRunningTasksCommandId,
292+
title: nls.localize2('RerunAllRunningTasksAction.label', "Rerun All Running Tasks"),
293+
category: TASKS_CATEGORY
294+
},
295+
when: TaskExecutionSupportedContext
296+
});
289297
MenuRegistry.appendMenuItem(MenuId.CommandPalette, {
290298
command: {
291299
id: 'workbench.action.tasks.showTasks',

src/vs/workbench/contrib/tasks/common/tasks.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1392,4 +1392,6 @@ export namespace TaskDefinition {
13921392
}
13931393
}
13941394

1395-
export const rerunTaskIcon = registerIcon('rerun-task', Codicon.refresh, nls.localize('rerunTaskIcon', 'View icon of the rerun task.')); export const RerunForActiveTerminalCommandId = 'workbench.action.tasks.rerunForActiveTerminal';
1395+
export const rerunTaskIcon = registerIcon('rerun-task', Codicon.refresh, nls.localize('rerunTaskIcon', 'View icon of the rerun task.'));
1396+
export const RerunForActiveTerminalCommandId = 'workbench.action.tasks.rerunForActiveTerminal';
1397+
export const RerunAllRunningTasksCommandId = 'workbench.action.tasks.rerunAllRunningTasks';

0 commit comments

Comments
 (0)