Skip to content

Commit

Permalink
Configure plugin provided workspace tasks under a root folder
Browse files Browse the repository at this point in the history
Signed-off-by: Alvaro Sanchez-Leon <alvaro.sanchez-leon@ericsson.com>
  • Loading branch information
alvsan09 committed Mar 9, 2021
1 parent 14574ba commit 493f088
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions packages/task/src/browser/task-configuration-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,11 @@ export class TaskConfigurationManager {
return this.models.get(scope);
}

findFirstWorkSpaceFolder(): string | undefined {
const firstWorkSpaceFolder = Array.from(this.models.keys()).find(mScope => typeof mScope === 'string');
return typeof firstWorkSpaceFolder === 'string' ? firstWorkSpaceFolder : undefined;
}

protected async doOpen(model: TaskConfigurationModel, configURI: URI): Promise<EditorWidget | undefined> {
if (!model.uri) {
// The file has not yet been created.
Expand Down
16 changes: 15 additions & 1 deletion packages/task/src/browser/task-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
TaskInfo,
TaskOutputPresentation,
TaskOutputProcessedEvent,
TaskScope,
TaskServer
} from '../common';
import { TaskWatcher } from '../common/task-watcher';
Expand Down Expand Up @@ -1105,7 +1106,20 @@ export class TaskService implements TaskConfigurationClient {
* @param task The task to configure
*/
async configure(token: number, task: TaskConfiguration): Promise<void> {
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 && task.scope === TaskScope.Workspace) {
const firstWorkspaceFolder = this.taskConfigurationManager.findFirstWorkSpaceFolder();
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);
}

Expand Down

0 comments on commit 493f088

Please sign in to comment.