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

Support plugin tasks using 'TaskScope.Workspace' #9032

Merged
merged 1 commit into from
Mar 19, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9722,7 +9722,7 @@ declare module '@theia/plugin' {
}

export enum TaskScope {
/** The task is a global task */
/** The task is a global task. Global tasks are currently not supported. */
Global = 1,

/** The task is a workspace task */
Expand Down
13 changes: 9 additions & 4 deletions packages/task/src/browser/provided-task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { inject, injectable } from 'inversify';
import { TaskProviderRegistry } from './task-contribution';
import { TaskDefinitionRegistry } from './task-definition-registry';
import { TaskConfiguration, TaskCustomization, TaskOutputPresentation, TaskConfigurationScope } from '../common';
import { TaskConfiguration, TaskCustomization, TaskOutputPresentation, TaskConfigurationScope, TaskScope } from '../common';

@injectable()
export class ProvidedTaskConfigurations {
Expand Down Expand Up @@ -61,6 +61,8 @@ export class ProvidedTaskConfigurations {
const providers = await this.taskProviderRegistry.getProviders();
const providedTasks: TaskConfiguration[] = (await Promise.all(providers.map(p => p.provideTasks())))
.reduce((acc, taskArray) => acc.concat(taskArray), [])
// Global/User tasks from providers are not supported.
.filter(task => task.scope !== TaskScope.Global)
.map(providedTask => {
const originalPresentation = providedTask.presentation || {};
return {
Expand Down Expand Up @@ -116,12 +118,15 @@ export class ProvidedTaskConfigurations {
}
}

// Tasks with scope set to 'Workspace' can be customized in a workspace root, and will not match
// providers scope 'TaskScope.Workspace' unless specifically included as below.
const scopes = [scope, TaskScope.Workspace];
// find the task that matches the `customization`.
// The scenario where more than one match is found should not happen unless users manually enter multiple customizations for one type of task
// If this does happen, return the first match
const matchedTask = matchedTasks.filter(t =>
scope === t._scope && definition.properties.all.every(p => t[p] === customization[p])
)[0];
const matchedTask = matchedTasks.find(t =>
scopes.some(scp => scp === t._scope) && definition.properties.all.every(p => t[p] === customization[p])
);
return matchedTask;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/task/src/browser/quick-open-task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ export class QuickOpenTask implements QuickOpenModel, QuickOpenHandler {
if (this.workspaceService.opened) {
const roots = await this.workspaceService.roots;
scopes.push(...roots.map(rootStat => rootStat.resource.toString()));
if (this.workspaceService.saved) {
if (this.workspaceService.saved || groupedTasks.get(TaskScope.Workspace.toString())?.length) {
scopes.push(TaskScope.Workspace);
}
}
Expand Down
8 changes: 2 additions & 6 deletions packages/task/src/browser/task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,12 +302,8 @@ export class TaskConfigurations implements Disposable {
/** Adds given task to a config file and opens the file to provide ability to edit task configuration. */
async configure(token: number, task: TaskConfiguration): Promise<void> {
const scope = task._scope;
if (scope === TaskScope.Global || scope === TaskScope.Workspace) {
return this.taskConfigurationManager.openConfiguration(scope);
} else if (typeof scope !== 'string') {
console.error('Global task cannot be customized');
// TODO detected tasks of scope workspace or user could be customized in those preferences.
return;
if (scope === TaskScope.Global) {
colin-grant-work marked this conversation as resolved.
Show resolved Hide resolved
return this.openUserTasks();
}

const workspace = this.workspaceService.workspace;
Expand Down
9 changes: 7 additions & 2 deletions packages/task/src/browser/task-definition-registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ export class TaskDefinitionRegistry {
}
const def = this.getDefinition(one);
if (def) {
// scope is either a string or an enum value. Anyway...the must exactly match
return def.properties.all.every(p => p === 'type' || one[p] === other[p]) && one._scope === other._scope;
// scope is either a string or an enum value. Anyway...they must exactly match
// "_scope" may hold the Uri to the associated workspace whereas
// "scope" reflects the original TaskConfigurationScope as provided by plugins,
// Matching "_scope" or "scope" are both accepted in order to correlate provided task
// configurations (e.g. TaskScope.Workspace) against already configured tasks.
return def.properties.all.every(p => p === 'type' || one[p] === other[p])
&& (one._scope === other._scope || one.scope === other.scope);
}
return one.label === other.label && one._source === other._source;
}
Expand Down
8 changes: 6 additions & 2 deletions packages/task/src/common/task-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,14 @@ export namespace TaskCustomization {
}

export enum TaskScope {
Workspace,
Global
Global = 1,
Workspace = 2
}

/**
* The task configuration scopes.
* - `string` represents the associated workspace folder uri.
*/
export type TaskConfigurationScope = string | TaskScope.Workspace | TaskScope.Global;

export interface TaskConfiguration extends TaskCustomization {
Expand Down