Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contributed tasks aren't added to recent #94549

Merged
merged 3 commits into from Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 31 additions & 11 deletions src/vs/workbench/contrib/tasks/browser/abstractTaskService.ts
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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens now if we do have a programming error somewhere and the keys are not the same. The we use the key from the beginning which to my understanding would be wrong. So shouldn't we simply assert this or ignore the task if something goes wrong.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is effectively ignored later when the recents are read. However it would be better to ignore earlier (here) instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. That makes sense now to me. Are you planning to do any changes or do we go with the ignore later approach?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made the change for ignoring here since it is better not to defer the problem.

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 @@ -1397,15 +1416,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 @@ -1643,7 +1662,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 @@ -2243,7 +2262,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 @@ -2255,12 +2274,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
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