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

Fix task instance limit #97011

Merged
merged 1 commit into from May 5, 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
Expand Up @@ -229,6 +229,7 @@ export class TerminalTaskSystem implements ITaskSystem {
}

public run(task: Task, resolver: ITaskResolver, trigger: string = Triggers.command): ITaskExecuteResult {
task = task.clone(); // A small amount of task state is stored in the task (instance) and tasks passed in to run may have that set already.
Copy link
Member

Choose a reason for hiding this comment

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

Should it only do this conditionally if instanceLimit > 1?

Copy link
Member Author

Choose a reason for hiding this comment

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

To fix this bug, yes it only needs to be done if instanceLimit >= 1. However, it would be better to not pollute the original tasks state regardless so I will keep it always cloning.

const recentTaskKey = task.getRecentlyUsedKey() ?? '';
let validInstance = task.runOptions && task.runOptions.instanceLimit && this.instances[recentTaskKey] && this.instances[recentTaskKey].instances < task.runOptions.instanceLimit;
let instance = this.instances[recentTaskKey] ? this.instances[recentTaskKey].instances : 0;
Expand Down
12 changes: 12 additions & 0 deletions src/vs/workbench/contrib/tasks/common/tasks.ts
Expand Up @@ -688,6 +688,10 @@ export class CustomTask extends CommonTask {
}
}

public clone(): CustomTask {
return new CustomTask(this._id, this._source, this._label, this.type, this.command, this.hasDefinedMatchers, this.runOptions, this.configurationProperties);
}

public customizes(): KeyedTaskIdentifier | undefined {
if (this._source && this._source.customizes) {
return this._source.customizes;
Expand Down Expand Up @@ -874,6 +878,10 @@ export class ContributedTask extends CommonTask {
this.command = command;
}

public clone(): ContributedTask {
return new ContributedTask(this._id, this._source, this._label, this.type, this.defines, this.command, this.hasDefinedMatchers, this.runOptions, this.configurationProperties);
}

public getDefinition(): KeyedTaskIdentifier {
return this.defines;
}
Expand Down Expand Up @@ -938,6 +946,10 @@ export class InMemoryTask extends CommonTask {
this._source = source;
}

public clone(): InMemoryTask {
return new InMemoryTask(this._id, this._source, this._label, this.type, this.runOptions, this.configurationProperties);
}

public static is(value: any): value is InMemoryTask {
return value instanceof InMemoryTask;
}
Expand Down