Skip to content

Commit 559f974

Browse files
committed
Contributed tasks aren't added to recent
microsoft#94547
1 parent 0518862 commit 559f974

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -761,10 +761,22 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
761761
}
762762
}
763763

764-
private setRecentlyUsedTask(task: Task): void {
765-
const key = task.getRecentlyUsedKey();
764+
private async setRecentlyUsedTask(task: Task): Promise<void> {
765+
let key = task.getRecentlyUsedKey();
766766
if (!InMemoryTask.is(task) && key) {
767-
this.getRecentlyUsedTasks().set(key, JSON.stringify(this.createCustomizableTask(task)));
767+
const customizations = this.createCustomizableTask(task);
768+
if (ContributedTask.is(task) && customizations) {
769+
let custom: CustomTask[] = [];
770+
let customized: IStringDictionary<ConfiguringTask> = Object.create(null);
771+
await this.computeTasksForSingleConfig(task._source.workspaceFolder ?? this.workspaceFolders[0], {
772+
version: '2.0.0',
773+
tasks: [customizations]
774+
}, TaskRunSource.System, custom, customized, TaskConfig.TaskConfigSource.TasksJson, true);
775+
for (const configuration in customized) {
776+
key = customized[configuration].getRecentlyUsedKey()!;
777+
}
778+
}
779+
this.getRecentlyUsedTasks().set(key, JSON.stringify(customizations));
768780
this.saveRecentlyUsedTasks();
769781
}
770782
}
@@ -1398,15 +1410,15 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
13981410
});
13991411
}
14001412

1401-
private handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {
1413+
private async handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {
14021414
if (executeResult.task.taskLoadMessages && executeResult.task.taskLoadMessages.length > 0) {
14031415
executeResult.task.taskLoadMessages.forEach(loadMessage => {
14041416
this._outputChannel.append(loadMessage + '\n');
14051417
});
14061418
this.showOutput();
14071419
}
14081420

1409-
this.setRecentlyUsedTask(executeResult.task);
1421+
await this.setRecentlyUsedTask(executeResult.task);
14101422
if (executeResult.kind === TaskExecuteKind.Active) {
14111423
let active = executeResult.active;
14121424
if (active && active.same) {
@@ -1644,7 +1656,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
16441656
await Promise.all(customTasksPromises);
16451657
if (needsRecentTasksMigration) {
16461658
// At this point we have all the tasks and can migrate the recently used tasks.
1647-
this.migrateRecentTasks(result.all());
1659+
await this.migrateRecentTasks(result.all());
16481660
}
16491661
return result;
16501662
}, () => {
@@ -2244,7 +2256,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
22442256
return (this.getRecentlyUsedTasksV1().size > 0) && (this.getRecentlyUsedTasks().size === 0);
22452257
}
22462258

2247-
public migrateRecentTasks(tasks: Task[]) {
2259+
public async migrateRecentTasks(tasks: Task[]) {
22482260
if (!this.needsRecentTasksMigration()) {
22492261
return;
22502262
}
@@ -2256,12 +2268,13 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
22562268
taskMap[key] = task;
22572269
}
22582270
});
2259-
recentlyUsedTasks.keys().reverse().forEach(key => {
2271+
const reversed = recentlyUsedTasks.keys().reverse();
2272+
for (const key in reversed) {
22602273
let task = taskMap[key];
22612274
if (task) {
2262-
this.setRecentlyUsedTask(task);
2275+
await this.setRecentlyUsedTask(task);
22632276
}
2264-
});
2277+
}
22652278
this.storageService.remove(AbstractTaskService.RecentlyUsedTasks_Key, StorageScope.WORKSPACE);
22662279
}
22672280

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export interface ITaskService {
7979
tryResolveTask(configuringTask: ConfiguringTask): Promise<Task | undefined>;
8080
getTasksForGroup(group: string): Promise<Task[]>;
8181
getRecentlyUsedTasks(): LinkedMap<string, string>;
82-
migrateRecentTasks(tasks: Task[]): void;
82+
migrateRecentTasks(tasks: Task[]): Promise<void>;
8383
createSorter(): TaskSorter;
8484

8585
getTaskDescription(task: Task | ConfiguringTask): string | undefined;

0 commit comments

Comments
 (0)