Skip to content

Commit 73e2dd7

Browse files
committed
refactor AbstractTaskService#_runRestartTaskCommand to async/await and simpler logic
1 parent 698b8ad commit 73e2dd7

File tree

1 file changed

+26
-35
lines changed

1 file changed

+26
-35
lines changed

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

Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -3114,48 +3114,39 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
31143114
}
31153115
}
31163116

3117-
private _runRestartTaskCommand(arg?: any): void {
3118-
const runQuickPick = (promise?: Promise<Task[]>) => {
3119-
this._showQuickPick(promise || this.getActiveTasks(),
3117+
private async _runRestartTaskCommand(arg?: any): Promise<void> {
3118+
3119+
const activeTasks = await this.getActiveTasks();
3120+
3121+
if (this.inTerminal()) {
3122+
// try dispatching using task identifier
3123+
const identifier = this._getTaskIdentifier(arg);
3124+
if (identifier !== undefined) {
3125+
for (const task of activeTasks) {
3126+
if (task.matches(identifier)) {
3127+
this._restart(task);
3128+
return;
3129+
}
3130+
}
3131+
}
3132+
// show quick pick with active tasks
3133+
const entry = await this._showQuickPick(
3134+
activeTasks,
31203135
nls.localize('TaskService.taskToRestart', 'Select the task to restart'),
31213136
{
31223137
label: nls.localize('TaskService.noTaskToRestart', 'No task to restart'),
31233138
task: null
31243139
},
3125-
false, true
3126-
).then(entry => {
3127-
const task: Task | undefined | null = entry ? entry.task : undefined;
3128-
if (task === undefined || task === null) {
3129-
return;
3130-
}
3131-
this._restart(task);
3132-
});
3133-
};
3134-
if (this.inTerminal()) {
3135-
const identifier = this._getTaskIdentifier(arg);
3136-
let promise: Promise<Task[]>;
3137-
if (identifier !== undefined) {
3138-
promise = this.getActiveTasks();
3139-
promise.then((tasks) => {
3140-
for (const task of tasks) {
3141-
if (task.matches(identifier)) {
3142-
this._restart(task);
3143-
return;
3144-
}
3145-
}
3146-
runQuickPick(promise);
3147-
});
3148-
} else {
3149-
runQuickPick();
3140+
false,
3141+
true
3142+
);
3143+
if (entry && entry.task) {
3144+
this._restart(entry.task);
31503145
}
31513146
} else {
3152-
this.getActiveTasks().then((activeTasks) => {
3153-
if (activeTasks.length === 0) {
3154-
return;
3155-
}
3156-
const task = activeTasks[0];
3157-
this._restart(task);
3158-
});
3147+
if (activeTasks.length > 0) {
3148+
this._restart(activeTasks[0]);
3149+
}
31593150
}
31603151
}
31613152

0 commit comments

Comments
 (0)