From 37ff92b187b46d5b0d2373be0d1bdd91d59fe9c7 Mon Sep 17 00:00:00 2001 From: Alvaro Sanchez-Leon Date: Tue, 9 Mar 2021 13:17:48 -0500 Subject: [PATCH] Configure plugin provided workspace tasks under a root folder Signed-off-by: Alvaro Sanchez-Leon --- packages/task/src/browser/task-service.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/task/src/browser/task-service.ts b/packages/task/src/browser/task-service.ts index 9d9b57b5cf816..26e8f0877f64d 100644 --- a/packages/task/src/browser/task-service.ts +++ b/packages/task/src/browser/task-service.ts @@ -49,6 +49,7 @@ import { TaskInfo, TaskOutputPresentation, TaskOutputProcessedEvent, + TaskScope, TaskServer } from '../common'; import { TaskWatcher } from '../common/task-watcher'; @@ -1105,7 +1106,20 @@ export class TaskService implements TaskConfigurationClient { * @param task The task to configure */ async configure(token: number, task: TaskConfiguration): Promise { - Object.assign(task, { label: this.taskNameResolver.resolve(task) }); + const adaptedProperties: {label: string, _scope?: string} = {label: this.taskNameResolver.resolve(task)}; + + // Configure plugin provided tasks of workspace scope in the first root folder + // we identify provided workspace tasks by the presence of the "scope" property. + if (task.scope === TaskScope.Workspace) { + const firstWorkspaceFolder = (await this.workspaceService.roots)[0]?.resource.toString(); + if (firstWorkspaceFolder === undefined) { + console.log('Unable to save configuration as no workspace root folder exist'); + return; + } + adaptedProperties._scope = firstWorkspaceFolder; + } + + Object.assign(task, adaptedProperties); await this.taskConfigurations.configure(token, task); }