Skip to content

Commit

Permalink
Contributed tasks aren't added to recent (#94549)
Browse files Browse the repository at this point in the history
Fixes #94547
  • Loading branch information
alexr00 authored Apr 7, 2020
1 parent 15297a9 commit ea93548
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
42 changes: 31 additions & 11 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -761,11 +761,30 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
}
}

private setRecentlyUsedTask(task: Task): void {
const key = task.getRecentlyUsedKey();
private async setRecentlyUsedTask(task: Task): Promise<void> {
let key = task.getRecentlyUsedKey();
if (!InMemoryTask.is(task) && key) {
this.getRecentlyUsedTasks().set(key, JSON.stringify(this.createCustomizableTask(task)));
this.saveRecentlyUsedTasks();
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<ConfiguringTask> = 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) {
// 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()!;
}
}
}
if (key) {
this.getRecentlyUsedTasks().set(key, JSON.stringify(customizations));
this.saveRecentlyUsedTasks();
}
}
}

Expand Down Expand Up @@ -1398,15 +1417,15 @@ export abstract class AbstractTaskService extends Disposable implements ITaskSer
});
}

private handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {
private async handleExecuteResult(executeResult: ITaskExecuteResult): Promise<ITaskSummary> {
if (executeResult.task.taskLoadMessages && executeResult.task.taskLoadMessages.length > 0) {
executeResult.task.taskLoadMessages.forEach(loadMessage => {
this._outputChannel.append(loadMessage + '\n');
});
this.showOutput();
}

this.setRecentlyUsedTask(executeResult.task);
await this.setRecentlyUsedTask(executeResult.task);
if (executeResult.kind === TaskExecuteKind.Active) {
let active = executeResult.active;
if (active && active.same) {
Expand Down Expand Up @@ -1644,7 +1663,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;
}, () => {
Expand Down Expand Up @@ -2244,7 +2263,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;
}
Expand All @@ -2256,12 +2275,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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/tasks/common/taskService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export interface ITaskService {
tryResolveTask(configuringTask: ConfiguringTask): Promise<Task | undefined>;
getTasksForGroup(group: string): Promise<Task[]>;
getRecentlyUsedTasks(): LinkedMap<string, string>;
migrateRecentTasks(tasks: Task[]): void;
migrateRecentTasks(tasks: Task[]): Promise<void>;
createSorter(): TaskSorter;

getTaskDescription(task: Task | ConfiguringTask): string | undefined;
Expand Down

0 comments on commit ea93548

Please sign in to comment.