Skip to content

Commit

Permalink
GH-4814 Looking at Gulp/Jake/Grunt plugins extensions.
Browse files Browse the repository at this point in the history
It is possible to have tasks with the same type, so we need to
differentiate them.
Using the handle available with the task to create a unique provider.
This allow to have following plugins within the same workspace:
- grunt
- gulp
- jake

Signed-off-by: Jacques Bouthillier <jacques.bouthillier@ericsson.com>
  • Loading branch information
lmcbout committed Apr 16, 2019
1 parent a388fc5 commit 1c6bf35
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 28 deletions.
2 changes: 1 addition & 1 deletion packages/plugin-ext/src/main/browser/tasks-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class TasksMainImpl implements TasksMain {
const taskResolver = this.createTaskResolver(handle);

const disposable = new DisposableCollection();
disposable.push(this.taskProviderRegistry.register(type, taskProvider));
disposable.push(this.taskProviderRegistry.register(type, taskProvider, handle));
disposable.push(this.taskResolverRegistry.register(type, taskResolver));
this.disposables.set(handle, disposable);
}
Expand Down
49 changes: 45 additions & 4 deletions packages/plugin-ext/src/plugin/types-impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1541,7 +1541,7 @@ export enum TaskScope {

export class Task {
private taskDefinition: theia.TaskDefinition | undefined;
private taskScope: theia.TaskScope.Global | theia.TaskScope.Workspace | theia.WorkspaceFolder | undefined;
private taskScope?: theia.TaskScope.Global | theia.TaskScope.Workspace | theia.WorkspaceFolder | undefined;
private taskName: string;
private taskExecution: ProcessExecution | ShellExecution | undefined;
private taskProblemMatchers: string[];
Expand All @@ -1550,13 +1550,51 @@ export class Task {
private taskSource: string;
private taskGroup: TaskGroup | undefined;
private taskPresentationOptions: theia.TaskPresentationOptions | undefined;

constructor(taskDefinition: theia.TaskDefinition,
constructor(
taskDefinition: theia.TaskDefinition,
scope: theia.WorkspaceFolder | theia.TaskScope.Global | theia.TaskScope.Workspace,
name: string,
source: string,
execution?: ProcessExecution | ShellExecution,
problemMatchers?: string | string[]) {
problemMatchers?: string | string[]
);

// Deprecated constructor used by Jake vscode built-in
constructor(
taskDefinition: theia.TaskDefinition,
name: string,
source: string,
execution?: ProcessExecution | ShellExecution,
problemMatchers?: string | string[],
);

// tslint:disable-next-line:no-any
constructor(...args: any[]) {
let taskDefinition: theia.TaskDefinition;
let scope: theia.WorkspaceFolder | theia.TaskScope.Global | theia.TaskScope.Workspace | undefined;
let name: string;
let source: string;
let execution: ProcessExecution | ShellExecution | undefined;
let problemMatchers: string | string[] | undefined;

if (typeof args[1] === 'string') {
[
taskDefinition,
name,
source,
execution,
problemMatchers,
] = args;
} else {
[
taskDefinition,
scope,
name,
source,
execution,
problemMatchers,
] = args;
}

this.definition = taskDefinition;
this.scope = scope;
Expand Down Expand Up @@ -1593,6 +1631,9 @@ export class Task {
}

set scope(value: theia.TaskScope.Global | theia.TaskScope.Workspace | theia.WorkspaceFolder | undefined) {
if (value === null) {
value = undefined;
}
this.taskScope = value;
}

Expand Down
47 changes: 32 additions & 15 deletions packages/plugin/src/theia.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ declare module '@theia/plugin' {
export let all: Plugin<any>[];
}


/**
* A command is a unique identifier of a function
* which can be executed by a user via a keyboard shortcut,
Expand Down Expand Up @@ -3672,53 +3671,53 @@ declare module '@theia/plugin' {
size: number;
}

/**
/**
* A type that filesystem providers should use to signal errors.
*
* This class has factory methods for common error-cases, like `EntryNotFound` when
* a file or folder doesn't exist, use them like so: `throw vscode.FileSystemError.EntryNotFound(someUri);`
*/
export class FileSystemError extends Error {

/**
/**
* Create an error to signal that a file or folder wasn't found.
* @param messageOrUri Message or uri.
*/
static FileNotFound(messageOrUri?: string | Uri): FileSystemError;

/**
/**
* Create an error to signal that a file or folder already exists, e.g. when
* creating but not overwriting a file.
* @param messageOrUri Message or uri.
*/
static FileExists(messageOrUri?: string | Uri): FileSystemError;

/**
/**
* Create an error to signal that a file is not a folder.
* @param messageOrUri Message or uri.
*/
static FileNotADirectory(messageOrUri?: string | Uri): FileSystemError;

/**
/**
* Create an error to signal that a file is a folder.
* @param messageOrUri Message or uri.
*/
static FileIsADirectory(messageOrUri?: string | Uri): FileSystemError;

/**
/**
* Create an error to signal that an operation lacks required permissions.
* @param messageOrUri Message or uri.
*/
static NoPermissions(messageOrUri?: string | Uri): FileSystemError;

/**
/**
* Create an error to signal that the file system is unavailable or too busy to
* complete a request.
* @param messageOrUri Message or uri.
*/
static Unavailable(messageOrUri?: string | Uri): FileSystemError;

/**
/**
* Creates a new filesystem error.
*
* @param messageOrUri Message or uri.
Expand Down Expand Up @@ -4121,7 +4120,6 @@ declare module '@theia/plugin' {
*/
export function applyEdit(edit: WorkspaceEdit): PromiseLike<boolean>;


/**
* Register a filesystem provider for a given scheme, e.g. `ftp`.
*
Expand Down Expand Up @@ -5060,7 +5058,6 @@ declare module '@theia/plugin' {
constructor(range: Range, newText: string);
}


/**
* Completion item kinds.
*/
Expand Down Expand Up @@ -5773,9 +5770,9 @@ declare module '@theia/plugin' {

/**
* Check if this code action kind intersects `other`.
* The kind "refactor.extract" for example intersects refactor, "refactor.extract" and
* The kind "refactor.extract" for example intersects refactor, "refactor.extract" and
* `"refactor.extract.function", but not "unicorn.refactor.extract", or "refactor.extractAll".
*
*
* @param other Kind to check.
*/
intersects(other: CodeActionKind): boolean;
Expand Down Expand Up @@ -6050,7 +6047,6 @@ declare module '@theia/plugin' {
resolveDocumentLink?(link: DocumentLink, token: CancellationToken | undefined): ProviderResult<DocumentLink>;
}


/**
* The rename provider interface defines the contract between extensions and
* the [rename](https://code.visualstudio.com/docs/editor/editingevolved#_rename-symbol)-feature.
Expand Down Expand Up @@ -7160,13 +7156,34 @@ declare module '@theia/plugin' {
* or '$eslint'. Problem matchers can be contributed by an extension using
* the `problemMatchers` extension point.
*/
constructor(taskDefinition: TaskDefinition,
constructor(
taskDefinition: TaskDefinition,
scope: WorkspaceFolder | TaskScope.Global | TaskScope.Workspace,
name: string,
source?: string,
execution?: ProcessExecution | ShellExecution,
problemMatchers?: string | string[]);

/**
* ~~Creates a new task.~~
*
* @deprecated Use the new constructors that allow specifying a scope for the task.
*
* @param definition The task definition as defined in the taskDefinitions extension point.
* @param name The task's name. Is presented in the user interface.
* @param source The task's source (e.g. 'gulp', 'npm', ...). Is presented in the user interface.
* @param execution The process or shell execution.
* @param problemMatchers the names of problem matchers to use, like '$tsc'
* or '$eslint'. Problem matchers can be contributed by an extension using
* the `problemMatchers` extension point.
*/
constructor(
taskDefinition: TaskDefinition,
name: string,
source: string,
execution?: ProcessExecution | ShellExecution,
problemMatchers?: string | string[]);

/** The task's name */
name: string;

Expand Down
9 changes: 6 additions & 3 deletions packages/task/src/browser/provided-task-configurations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,12 @@ export class ProvidedTaskConfigurations {
if (task) {
return task;
} else {
const provider = this.taskProviderRegistry.getProvider(source);
if (provider) {
const tasks = await provider.provideTasks();
const providers = this.taskProviderRegistry.getProvider(source);
if (providers.length > 0) {
const tasks: TaskConfiguration[] = [];
for (const provider of providers) {
tasks.push(...await provider.provideTasks());
}
this.cacheTasks(tasks);
return this.getCachedTask(source, taskLabel);
}
Expand Down
17 changes: 12 additions & 5 deletions packages/task/src/browser/task-contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,22 @@ export class TaskProviderRegistry {
}

/** Registers the given Task Provider to return Task Configurations of the specified type. */
register(type: string, provider: TaskProvider): Disposable {
this.providers.set(type, provider);
register(type: string, provider: TaskProvider, handle?: number): Disposable {
const key = handle === undefined ? type : `${type}::${handle}`;
this.providers.set(key, provider);
return {
dispose: () => this.providers.delete(type)
dispose: () => this.providers.delete(key)
};
}

getProvider(type: string): TaskProvider | undefined {
return this.providers.get(type);
getProvider(type: string): TaskProvider[] {
const providerArray: TaskProvider[] = [];
this.providers.forEach((provider, key) => {
if (key.startsWith(type)) {
providerArray.push(provider);
}
});
return providerArray;
}

/** Returns all registered Task Providers. */
Expand Down

0 comments on commit 1c6bf35

Please sign in to comment.