Fixes #24073: Improve task API and adopt gulp extension to it.

This commit is contained in:
Dirk Baeumer
2017-04-06 21:11:47 +02:00
parent 0bcc6fc51c
commit ef2b0a4bfe
12 changed files with 481 additions and 363 deletions

View File

@@ -529,6 +529,7 @@ export function createApiFactory(
FileLocationKind: extHostTypes.FileLocationKind,
ApplyToKind: extHostTypes.ApplyToKind,
RevealKind: extHostTypes.RevealKind,
TaskGroup: extHostTypes.TaskGroup,
ShellTask: extHostTypes.ShellTask,
ProcessTask: extHostTypes.ProcessTask
};

View File

@@ -309,6 +309,7 @@ namespace Tasks {
_id: uuidMap.getUUID(task.identifier),
name: task.name,
identifier: task.identifier,
group: types.TaskGroup.is(task.group) ? task.group : undefined,
command: command,
showOutput: behaviour.showOutput,
isBackground: !!task.isBackground,
@@ -381,57 +382,6 @@ class UUIDMap {
}
}
namespace TaskSet {
const idMaps: Map<string, UUIDMap> = new Map<string, UUIDMap>();
function getUUIDMap(extensionId: string): UUIDMap {
let result = idMaps.get(extensionId);
if (result) {
return result;
}
result = new UUIDMap();
idMaps.set(extensionId, result);
return result;
}
export function from(extension: IExtensionDescription, value: vscode.TaskSet): TaskSystem.TaskSet {
if (value === void 0 || value === null || !Array.isArray(value.tasks)) {
return { tasks: Object.create(null) };
}
let tasks = Tasks.from(value.tasks, getUUIDMap(extension.id));
let buildTasks: string[];
let testTasks: string[];
if (value.buildTasks || value.testTasks) {
let map: Map<string, TaskSystem.Task> = new Map<string, TaskSystem.Task>();
tasks.forEach(task => map.set(task.identifier, task));
if (Array.isArray(value.buildTasks)) {
buildTasks = [];
for (let elem of value.buildTasks) {
if (typeof elem === 'string' && map.has(elem)) {
buildTasks.push(map.get(elem)._id);
}
}
}
if (Array.isArray(value.testTasks)) {
testTasks = [];
for (let elem of value.testTasks) {
if (typeof elem === 'string' && map.has(elem)) {
testTasks.push(map.get(elem)._id);
}
}
}
}
return {
tasks,
buildTasks,
testTasks
};
}
}
interface HandlerData {
provider: vscode.TaskProvider;
extension: IExtensionDescription;
@@ -442,12 +392,14 @@ export class ExtHostTask extends ExtHostTaskShape {
private _proxy: MainThreadTaskShape;
private _handleCounter: number;
private _handlers: Map<number, HandlerData>;
private _idMaps: Map<string, UUIDMap>;
constructor(threadService: IThreadService) {
super();
this._proxy = threadService.get(MainContext.MainThreadTask);
this._handleCounter = 0;
this._handlers = new Map<number, HandlerData>();
this._idMaps = new Map<string, UUIDMap>();
};
public registerTaskProvider(extension: IExtensionDescription, provider: vscode.TaskProvider): vscode.Disposable {
@@ -469,11 +421,24 @@ export class ExtHostTask extends ExtHostTaskShape {
return TPromise.wrapError<TaskSystem.TaskSet>(new Error('no handler found'));
}
return asWinJsPromise(token => handler.provider.provideTasks(token)).then(value => {
return TaskSet.from(handler.extension, value);
return {
tasks: Tasks.from(value, this.getUUIDMap(handler.extension.id)),
extension: handler.extension
};
});
}
private nextHandle(): number {
return this._handleCounter++;
}
private getUUIDMap(extensionId: string): UUIDMap {
let result = this._idMaps.get(extensionId);
if (result) {
return result;
}
result = new UUIDMap();
this._idMaps.set(extensionId, result);
return result;
}
}

View File

@@ -1033,9 +1033,12 @@ export class BaseTask {
}
set identifier(value: string) {
if (typeof name !== 'string') {
if (typeof value !== 'string') {
throw illegalArgument('identifier');
}
if (value.indexOf(':') !== -1) {
throw illegalArgument('identifier must not contain \':\'');
}
this._identifier = value;
}
@@ -1084,11 +1087,37 @@ namespace ProblemMatcher {
}
}
export namespace TaskGroup {
/**
* The clean task group
*/
export const Clean: 'clean' = 'clean';
/**
* The build task group
*/
export const Build: 'build' = 'build';
/**
* The rebuild all task group
*/
export const RebuildAll: 'rebuildAll' = 'rebuildAll';
/**
* The test task group
*/
export const Test: 'test' = 'test';
export function is(value: string): value is vscode.TaskGroup {
return value === Clean || value === Build || value === RebuildAll || value === Test;
}
}
export class ProcessTask extends BaseTask {
private _process: string;
private _args: string[];
private _group: vscode.TaskGroup;
private _options: vscode.ProcessOptions;
private static parseArguments(restArgs: any[]): { args: string[]; options: vscode.ProcessOptions; problemMatchers: vscode.ProblemMatcher[] } {
@@ -1145,6 +1174,17 @@ export class ProcessTask extends BaseTask {
this._args = value;
}
get group(): vscode.TaskGroup {
return this._group;
}
set group(value: vscode.TaskGroup) {
if (!TaskGroup.is(value)) {
throw illegalArgument('group');
}
this._group = value;
}
get options(): vscode.ProcessOptions {
return this._options;
}
@@ -1160,6 +1200,7 @@ export class ProcessTask extends BaseTask {
export class ShellTask extends BaseTask {
private _commandLine: string;
private _group: vscode.TaskGroup;
private _options: vscode.ShellOptions;
private static parseArguments(restArgs: any[]): { options: vscode.ShellOptions; problemMatchers: vscode.ProblemMatcher[] } {
@@ -1197,6 +1238,17 @@ export class ShellTask extends BaseTask {
return this._commandLine;
}
get group(): vscode.TaskGroup {
return this._group;
}
set group(value: vscode.TaskGroup) {
if (!TaskGroup.is(value)) {
throw illegalArgument('group');
}
this._group = value;
}
get options(): vscode.ShellOptions {
return this._options;
}