From 759410cac6f5d7144c30b00871efad9998ec628a Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Mon, 6 Apr 2020 16:39:34 +0200 Subject: [PATCH 1/3] Contributed tasks aren't added to recent #94547 --- .../tasks/browser/abstractTaskService.ts | 33 +++++++++++++------ .../contrib/tasks/common/taskService.ts | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index ad11459555e37..86ae4762d4915 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -761,10 +761,22 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } } - private setRecentlyUsedTask(task: Task): void { - const key = task.getRecentlyUsedKey(); + private async setRecentlyUsedTask(task: Task): Promise { + let key = task.getRecentlyUsedKey(); if (!InMemoryTask.is(task) && key) { - this.getRecentlyUsedTasks().set(key, JSON.stringify(this.createCustomizableTask(task))); + const customizations = this.createCustomizableTask(task); + if (ContributedTask.is(task) && customizations) { + let custom: CustomTask[] = []; + let customized: IStringDictionary = Object.create(null); + await this.computeTasksForSingleConfig(task._source.workspaceFolder ?? this.workspaceFolders[0], { + version: '2.0.0', + tasks: [customizations] + }, TaskRunSource.System, custom, customized, TaskConfig.TaskConfigSource.TasksJson, true); + for (const configuration in customized) { + key = customized[configuration].getRecentlyUsedKey()!; + } + } + this.getRecentlyUsedTasks().set(key, JSON.stringify(customizations)); this.saveRecentlyUsedTasks(); } } @@ -1397,7 +1409,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer }); } - private handleExecuteResult(executeResult: ITaskExecuteResult): Promise { + private async handleExecuteResult(executeResult: ITaskExecuteResult): Promise { if (executeResult.task.taskLoadMessages && executeResult.task.taskLoadMessages.length > 0) { executeResult.task.taskLoadMessages.forEach(loadMessage => { this._outputChannel.append(loadMessage + '\n'); @@ -1405,7 +1417,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer this.showOutput(); } - this.setRecentlyUsedTask(executeResult.task); + await this.setRecentlyUsedTask(executeResult.task); if (executeResult.kind === TaskExecuteKind.Active) { let active = executeResult.active; if (active && active.same) { @@ -1643,7 +1655,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer await Promise.all(customTasksPromises); if (needsRecentTasksMigration) { // At this point we have all the tasks and can migrate the recently used tasks. - this.migrateRecentTasks(result.all()); + await this.migrateRecentTasks(result.all()); } return result; }, () => { @@ -2243,7 +2255,7 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer return (this.getRecentlyUsedTasksV1().size > 0) && (this.getRecentlyUsedTasks().size === 0); } - public migrateRecentTasks(tasks: Task[]) { + public async migrateRecentTasks(tasks: Task[]) { if (!this.needsRecentTasksMigration()) { return; } @@ -2255,12 +2267,13 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer taskMap[key] = task; } }); - recentlyUsedTasks.keys().reverse().forEach(key => { + const reversed = recentlyUsedTasks.keys().reverse(); + for (const key in reversed) { let task = taskMap[key]; if (task) { - this.setRecentlyUsedTask(task); + await this.setRecentlyUsedTask(task); } - }); + } this.storageService.remove(AbstractTaskService.RecentlyUsedTasks_Key, StorageScope.WORKSPACE); } diff --git a/src/vs/workbench/contrib/tasks/common/taskService.ts b/src/vs/workbench/contrib/tasks/common/taskService.ts index 626c7b4b6d45c..38fd29f0995d6 100644 --- a/src/vs/workbench/contrib/tasks/common/taskService.ts +++ b/src/vs/workbench/contrib/tasks/common/taskService.ts @@ -79,7 +79,7 @@ export interface ITaskService { tryResolveTask(configuringTask: ConfiguringTask): Promise; getTasksForGroup(group: string): Promise; getRecentlyUsedTasks(): LinkedMap; - migrateRecentTasks(tasks: Task[]): void; + migrateRecentTasks(tasks: Task[]): Promise; createSorter(): TaskSorter; getTaskDescription(task: Task | ConfiguringTask): string | undefined; From 6fb2a9724750aef970e95110372fba18deb32230 Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 7 Apr 2020 10:20:59 +0200 Subject: [PATCH 2/3] make it clearer that we have only one configuration --- .../workbench/contrib/tasks/browser/abstractTaskService.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index 86ae4762d4915..a120bb62d4f81 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -773,7 +773,10 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer tasks: [customizations] }, TaskRunSource.System, custom, customized, TaskConfig.TaskConfigSource.TasksJson, true); for (const configuration in customized) { - key = customized[configuration].getRecentlyUsedKey()!; + // There should only be one configuration in customized, but check that it matches the original task just to be sure. + if (customized[configuration].configures._key === task.defines._key) { + key = customized[configuration].getRecentlyUsedKey()!; + } } } this.getRecentlyUsedTasks().set(key, JSON.stringify(customizations)); From f5a569f72e745293dd766b70de72b8d48b8261cb Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Tue, 7 Apr 2020 11:21:36 +0200 Subject: [PATCH 3/3] Skip setting recent task if no key --- .../contrib/tasks/browser/abstractTaskService.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts index a120bb62d4f81..d9cb0bb4da468 100644 --- a/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts +++ b/src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts @@ -766,6 +766,8 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer if (!InMemoryTask.is(task) && key) { const customizations = this.createCustomizableTask(task); if (ContributedTask.is(task) && customizations) { + // reset the key so we can ignore this task if we can't make a new key for it + key = undefined; let custom: CustomTask[] = []; let customized: IStringDictionary = Object.create(null); await this.computeTasksForSingleConfig(task._source.workspaceFolder ?? this.workspaceFolders[0], { @@ -779,8 +781,10 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer } } } - this.getRecentlyUsedTasks().set(key, JSON.stringify(customizations)); - this.saveRecentlyUsedTasks(); + if (key) { + this.getRecentlyUsedTasks().set(key, JSON.stringify(customizations)); + this.saveRecentlyUsedTasks(); + } } }