Skip to content

Commit ea93548

Browse files
authored
Contributed tasks aren't added to recent (microsoft#94549)
Fixes microsoft#94547
1 parent 15297a9 commit ea93548

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

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

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,30 @@ 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)));
768-
this.saveRecentlyUsedTasks();
767+
const customizations = this.createCustomizableTask(task);
768+
if (ContributedTask.is(task) && customizations) {
769+
// reset the key so we can ignore this task if we can't make a new key for it
770+
key = undefined;
771+
let custom: CustomTask[] = [];
772+
let customized: IStringDictionary<ConfiguringTask> = Object.create(null);
773+
await this.computeTasksForSingleConfig(task._source.workspaceFolder ?? this.workspaceFolders[0], {
774+
version: '2.0.0',
775+
tasks: [customizations]
776+
}, TaskRunSource.System, custom, customized, TaskConfig.TaskConfigSource.TasksJson, true);
777+
for (const configuration in customized) {
778+
// There should only be one configuration in customized, but check that it matches the original task just to be sure.
779+
if (customized[configuration].configures._key === task.defines._key) {
780+
key = customized[configuration].getRecentlyUsedKey()!;
781+
}
782+
}
783+
}
784+
if (key) {
785+
this.getRecentlyUsedTasks().set(key, JSON.stringify(customizations));
786+
this.saveRecentlyUsedTasks();
787+
}
769788
}
770789
}
771790

@@ -1398,15 +1417,15 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
13981417
});
13991418
}
14001419

1401-
private handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {
1420+
private async handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {
14021421
if (executeResult.task.taskLoadMessages && executeResult.task.taskLoadMessages.length > 0) {
14031422
executeResult.task.taskLoadMessages.forEach(loadMessage => {
14041423
this._outputChannel.append(loadMessage + '\n');
14051424
});
14061425
this.showOutput();
14071426
}
14081427

1409-
this.setRecentlyUsedTask(executeResult.task);
1428+
await this.setRecentlyUsedTask(executeResult.task);
14101429
if (executeResult.kind === TaskExecuteKind.Active) {
14111430
let active = executeResult.active;
14121431
if (active && active.same) {
@@ -1644,7 +1663,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
16441663
await Promise.all(customTasksPromises);
16451664
if (needsRecentTasksMigration) {
16461665
// At this point we have all the tasks and can migrate the recently used tasks.
1647-
this.migrateRecentTasks(result.all());
1666+
await this.migrateRecentTasks(result.all());
16481667
}
16491668
return result;
16501669
}, () => {
@@ -2244,7 +2263,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
22442263
return (this.getRecentlyUsedTasksV1().size > 0) && (this.getRecentlyUsedTasks().size === 0);
22452264
}
22462265

2247-
public migrateRecentTasks(tasks: Task[]) {
2266+
public async migrateRecentTasks(tasks: Task[]) {
22482267
if (!this.needsRecentTasksMigration()) {
22492268
return;
22502269
}
@@ -2256,12 +2275,13 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
22562275
taskMap[key] = task;
22572276
}
22582277
});
2259-
recentlyUsedTasks.keys().reverse().forEach(key => {
2278+
const reversed = recentlyUsedTasks.keys().reverse();
2279+
for (const key in reversed) {
22602280
let task = taskMap[key];
22612281
if (task) {
2262-
this.setRecentlyUsedTask(task);
2282+
await this.setRecentlyUsedTask(task);
22632283
}
2264-
});
2284+
}
22652285
this.storageService.remove(AbstractTaskService.RecentlyUsedTasks_Key, StorageScope.WORKSPACE);
22662286
}
22672287

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)