From 92b08e56f332050b797af61e79925c440c65ea8f Mon Sep 17 00:00:00 2001 From: Alex Ross Date: Fri, 27 Mar 2020 15:58:34 +0100 Subject: [PATCH] Fix tasks with same ID but different folders Fixes #93398 --- .../tasks/browser/terminalTaskSystem.ts | 25 +++++++++++-------- .../workbench/contrib/tasks/common/tasks.ts | 18 +++++++++++++ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts index 647119d0166..b4f3b48e151 100644 --- a/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts +++ b/src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts @@ -228,11 +228,12 @@ export class TerminalTaskSystem implements ITaskSystem { } public run(task: Task, resolver: ITaskResolver, trigger: string = Triggers.command): ITaskExecuteResult { - let validInstance = task.runOptions && task.runOptions.instanceLimit && this.instances[task._id] && this.instances[task._id].instances < task.runOptions.instanceLimit; - let instance = this.instances[task._id] ? this.instances[task._id].instances : 0; + 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; this.currentTask = new VerifiedTask(task, resolver, trigger); if (instance > 0) { - task.instance = this.instances[task._id].counter; + task.instance = this.instances[recentTaskKey].counter; } let lastTaskInstance = this.getLastInstance(task); let terminalData = lastTaskInstance ? this.activeTasks[lastTaskInstance.getMapKey()] : undefined; @@ -247,10 +248,10 @@ export class TerminalTaskSystem implements ITaskSystem { this.lastTask = this.currentTask; }); if (InMemoryTask.is(task) || !this.isTaskEmpty(task)) { - if (!this.instances[task._id]) { - this.instances[task._id] = new InstanceManager(); + if (!this.instances[recentTaskKey]) { + this.instances[recentTaskKey] = new InstanceManager(); } - this.instances[task._id].addInstance(); + this.instances[recentTaskKey].addInstance(); } return executeResult; } catch (error) { @@ -339,8 +340,9 @@ export class TerminalTaskSystem implements ITaskSystem { public getLastInstance(task: Task): Task | undefined { let lastInstance = undefined; + const recentKey = task.getRecentlyUsedKey(); Object.keys(this.activeTasks).forEach((key) => { - if (task._id === this.activeTasks[key].task._id) { + if (recentKey && recentKey === this.activeTasks[key].task.getRecentlyUsedKey()) { lastInstance = this.activeTasks[key].task; } }); @@ -364,10 +366,11 @@ export class TerminalTaskSystem implements ITaskSystem { } private removeInstances(task: Task) { - if (this.instances[task._id]) { - this.instances[task._id].removeInstance(); - if (this.instances[task._id].instances === 0) { - delete this.instances[task._id]; + const recentTaskKey = task.getRecentlyUsedKey() ?? ''; + if (this.instances[recentTaskKey]) { + this.instances[recentTaskKey].removeInstance(); + if (this.instances[recentTaskKey].instances === 0) { + delete this.instances[recentTaskKey]; } } } diff --git a/src/vs/workbench/contrib/tasks/common/tasks.ts b/src/vs/workbench/contrib/tasks/common/tasks.ts index 833f7e98eda..e6ebd8eef18 100644 --- a/src/vs/workbench/contrib/tasks/common/tasks.ts +++ b/src/vs/workbench/contrib/tasks/common/tasks.ts @@ -802,6 +802,24 @@ export class ConfiguringTask extends CommonTask { public getWorkspaceFolder(): IWorkspaceFolder | undefined { return this._source.config.workspaceFolder; } + + public getRecentlyUsedKey(): string | undefined { + interface CustomKey { + type: string; + folder: string; + id: string; + } + let workspaceFolder = this._source.kind === TaskSourceKind.User ? USER_TASKS_GROUP_KEY : this._source.config.workspaceFolder?.uri.toString(); + if (!workspaceFolder) { + return undefined; + } + let id: string = this.configurationProperties.identifier!; + if (this._source.kind !== TaskSourceKind.Workspace) { + id += this._source.kind; + } + let key: CustomKey = { type: CUSTOMIZED_TASK_TYPE, folder: workspaceFolder, id }; + return JSON.stringify(key); + } } export class ContributedTask extends CommonTask { -- GitLab