This commit is contained in:
Dirk Baeumer 2017-06-27 21:38:56 +02:00
parent 14d457eeec
commit 19f310a027
17 changed files with 74 additions and 88 deletions

View file

@ -42,7 +42,7 @@
}
}
},
"taskTypes": [
"taskDefinitions": [
{
"type": "grunt",
"required": ["task"],

View file

@ -84,7 +84,7 @@ function getOutputChannel(): vscode.OutputChannel {
return _channel;
}
interface GruntTaskKind extends vscode.TaskKind {
interface GruntTaskDefinition extends vscode.TaskDefinition {
task: string;
file?: string;
}
@ -170,7 +170,7 @@ async function getGruntTasks(): Promise<vscode.Task[]> {
let matches = regExp.exec(line);
if (matches && matches.length === 2) {
let name = matches[1];
let kind: GruntTaskKind = {
let kind: GruntTaskDefinition = {
type: 'grunt',
task: name
};

View file

@ -42,7 +42,7 @@
}
}
},
"taskTypes": [
"taskDefinitions": [
{
"type": "gulp",
"required": ["task"],

View file

@ -84,7 +84,7 @@ function getOutputChannel(): vscode.OutputChannel {
return _channel;
}
interface GulpTaskKind extends vscode.TaskKind {
interface GulpTaskDefinition extends vscode.TaskDefinition {
task: string;
file?: string;
}
@ -147,7 +147,7 @@ async function getGulpTasks(): Promise<vscode.Task[]> {
if (line.length === 0) {
continue;
}
let kind: GulpTaskKind = {
let kind: GulpTaskDefinition = {
type: 'gulp',
task: line
};

View file

@ -42,7 +42,7 @@
}
}
},
"taskTypes": [
"taskDefinitions": [
{
"type": "jake",
"required": ["task"],

View file

@ -84,7 +84,7 @@ function getOutputChannel(): vscode.OutputChannel {
return _channel;
}
interface JakeTaskKind extends vscode.TaskKind {
interface JakeTaskDefinition extends vscode.TaskDefinition {
task: string;
file?: string;
}
@ -151,7 +151,7 @@ async function getJakeTasks(): Promise<vscode.Task[]> {
let matches = regExp.exec(line);
if (matches && matches.length === 2) {
let taskName = matches[1];
let kind: JakeTaskKind = {
let kind: JakeTaskDefinition = {
type: 'jake',
task: taskName
};

View file

@ -42,7 +42,7 @@
}
}
},
"taskTypes": [
"taskDefinitions": [
{
"type": "npm",
"required": ["script"],

View file

@ -62,7 +62,7 @@ async function readFile(file: string): Promise<string> {
});
}
interface NpmTaskKind extends vscode.TaskKind {
interface NpmTaskDefinition extends vscode.TaskDefinition {
script: string;
file?: string;
}
@ -109,7 +109,7 @@ async function getNpmScriptsAsTasks(): Promise<vscode.Task[]> {
const result: vscode.Task[] = [];
Object.keys(json.scripts).forEach(each => {
const kind: NpmTaskKind = {
const kind: NpmTaskDefinition = {
type: 'npm',
script: each
};
@ -123,7 +123,7 @@ async function getNpmScriptsAsTasks(): Promise<vscode.Task[]> {
result.push(task);
});
// add some 'well known' npm tasks
result.push(new vscode.Task({ type: 'npm', script: 'install' } as NpmTaskKind, `install`, 'npm', new vscode.ShellExecution(`npm install`)));
result.push(new vscode.Task({ type: 'npm', script: 'install' } as NpmTaskDefinition, `install`, 'npm', new vscode.ShellExecution(`npm install`)));
return Promise.resolve(result);
} catch (e) {
return Promise.resolve(emptyTasks);

View file

@ -458,7 +458,7 @@
"url": "http://json.schemastore.org/typings"
}
],
"taskTypes": [
"taskDefinitions": [
{
"type": "typescript",
"required": ["tsconfig"],

View file

@ -22,7 +22,7 @@ const exists = (file: string): Promise<boolean> =>
});
interface TypeScriptTaskIdentifier extends vscode.TaskKind {
interface TypeScriptTaskDefinition extends vscode.TaskDefinition {
tsconfig: string;
}
@ -53,7 +53,7 @@ class TscTaskProvider implements vscode.TaskProvider {
return projects.map(configFile => {
const configFileName = path.relative(rootPath, configFile);
const identifier: TypeScriptTaskIdentifier = { type: 'typescript', tsconfig: configFileName };
const identifier: TypeScriptTaskDefinition = { type: 'typescript', tsconfig: configFileName };
const buildTask = new vscode.Task(identifier, `build ${configFileName}`, 'tsc', new vscode.ShellExecution(`${command} -p "${configFile}"`), '$tsc');
buildTask.group = vscode.TaskGroup.Build;
return buildTask;

View file

@ -120,13 +120,18 @@ declare module 'vscode' {
* A structure that defines a task kind in the system.
* The value must be JSON-stringifyable.
*/
export interface TaskKind {
export interface TaskDefinition {
/**
* The task type as defined by the extension implementing a
* task provider. Examples are 'grunt', 'npm' or 'tsc'.
* The task definition descibing the task provided by an extension.
* Usually a task provider defines more properties to identify
* a task. They need to be defined in the package.json of the
* extension under the 'taskKinds' extension point.
* extension under the 'taskDefinitions' extension point. The npm
* task definition for example looks like this
* ```typescript
* interface NpmTaskDefinition extends TaskDefinition {
* script: string;
* }
* ```
*/
readonly type: string;
}
@ -244,30 +249,10 @@ declare module 'vscode' {
*/
export class Task {
/**
* Creates a new task. A task without an exection set is resolved
* before executed.
*
* @param kind The task kind as defined in the 'taskKinds' 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.
*/
constructor(kind: TaskKind, name: string, source: string);
/**
* Creates a new task.
*
* @param kind The task kind as defined in the 'taskKinds' 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.
*/
constructor(kind: TaskKind, name: string, source: string, execution: ProcessExecution | ShellExecution);
/**
* Creates a new task.
*
* @param kind The task kind as defined in the 'taskKinds' extension point.
* @param definition The task definition as defined in the taskDefintions 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.
@ -275,12 +260,12 @@ declare module 'vscode' {
* or '$eslint'. Problem matchers can be contributed by an extension using
* the `problemMatchers` extension point.
*/
constructor(kind: TaskKind, name: string, source: string, execution: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(taskDefinition: TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
/**
* The task's kind.
* The task's definition.
*/
kind: TaskKind;
definition: TaskDefinition;
/**
* The task's name

View file

@ -333,8 +333,8 @@ namespace Tasks {
detail: extension.id
};
let label = nls.localize('task.label', '{0}: {1}', source.label, task.name);
let key = (task as types.Task).kindKey;
let kind = (task as types.Task).kind;
let key = (task as types.Task).definitionKey;
let kind = (task as types.Task).definition;
let id = `${extension.id}.${key}`;
let taskKind: TaskSystem.TaskIdentifier = {
_key: key,

View file

@ -1153,8 +1153,8 @@ export class ShellExecution implements vscode.ShellExecution {
export class Task implements vscode.Task {
private _kind: vscode.TaskKind;
private _kindKey: string;
private _definition: vscode.TaskDefinition;
private _definitionKey: string;
private _name: string;
private _execution: ProcessExecution | ShellExecution;
private _problemMatchers: string[];
@ -1163,13 +1163,8 @@ export class Task implements vscode.Task {
private _group: TaskGroup;
private _presentationOptions: vscode.TaskPresentationOptions;
constructor(kind: vscode.TaskKind, name: string, source: string);
constructor(kind: vscode.TaskKind, name: string, source: string, execution: ProcessExecution | ShellExecution);
constructor(kind: vscode.TaskKind, name: string, source: string, execution: ProcessExecution | ShellExecution, problemMatchers?: string | string[]);
constructor(kind: vscode.TaskKind, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]) {
this.kind = kind;
constructor(definition: vscode.TaskDefinition, name: string, source: string, execution?: ProcessExecution | ShellExecution, problemMatchers?: string | string[]) {
this.definition = definition;
this.name = name;
this.source = source;
this.execution = execution;
@ -1183,25 +1178,25 @@ export class Task implements vscode.Task {
this._isBackground = false;
}
get kind(): vscode.TaskKind {
return this._kind;
get definition(): vscode.TaskDefinition {
return this._definition;
}
set kind(value: vscode.TaskKind) {
set definition(value: vscode.TaskDefinition) {
if (value === void 0 || value === null) {
throw illegalArgument('Kind can\'t be undefined or null');
}
this._kindKey = undefined;
this._kind = value;
this._definitionKey = undefined;
this._definition = value;
}
get kindKey(): string {
if (!this._kindKey) {
get definitionKey(): string {
if (!this._definitionKey) {
const hash = crypto.createHash('md5');
hash.update(JSON.stringify(this._kind));
this._kindKey = hash.digest('hex');
hash.update(JSON.stringify(this._definition));
this._definitionKey = hash.digest('hex');
}
return this._kindKey;
return this._definitionKey;
}
get name(): string {

View file

@ -16,17 +16,23 @@ import { ExtensionsRegistry, ExtensionMessageCollector } from 'vs/platform/exten
import * as Tasks from 'vs/workbench/parts/tasks/common/tasks';
const taskTypeSchema: IJSONSchema = {
const taskDefinitionSchema: IJSONSchema = {
type: 'object',
additionalProperties: false,
properties: {
type: {
type: 'string',
description: nls.localize('TaskType.description', 'The actual task type')
description: nls.localize('TaskDefinition.description', 'The actual task type')
},
required: {
type: 'array',
items: {
type: 'string'
}
},
properties: {
type: 'object',
description: nls.localize('TaskType.properties', 'Additional properties of the task type'),
description: nls.localize('TaskDefinition.properties', 'Additional properties of the task type'),
additionalProperties: {
$ref: 'http://json-schema.org/draft-04/schema#'
}
@ -35,13 +41,13 @@ const taskTypeSchema: IJSONSchema = {
};
namespace Configuration {
export interface TaskTypeDescription {
export interface TaskDefinition {
type?: string;
required?: string[];
properties?: IJSONSchemaMap;
}
export function from(value: TaskTypeDescription, messageCollector: ExtensionMessageCollector): Tasks.TaskTypeDescription {
export function from(value: TaskDefinition, messageCollector: ExtensionMessageCollector): Tasks.TaskDefinition {
if (!value) {
return undefined;
}
@ -63,29 +69,29 @@ namespace Configuration {
}
const taskTypesExtPoint = ExtensionsRegistry.registerExtensionPoint<Configuration.TaskTypeDescription[]>('taskTypes', [], {
description: nls.localize('TaskTypeExtPoint', 'Contributes task kinds'),
const taskDefinitionsExtPoint = ExtensionsRegistry.registerExtensionPoint<Configuration.TaskDefinition[]>('taskDefinitions', [], {
description: nls.localize('TaskDefinitionExtPoint', 'Contributes task kinds'),
type: 'array',
items: taskTypeSchema
items: taskDefinitionSchema
});
export interface ITaskTypeRegistry {
export interface ITaskDefinitionRegistry {
onReady(): TPromise<void>;
exists(key: string): boolean;
get(key: string): Tasks.TaskTypeDescription;
all(): Tasks.TaskTypeDescription[];
get(key: string): Tasks.TaskDefinition;
all(): Tasks.TaskDefinition[];
}
class TaskTypeRegistryImpl implements ITaskTypeRegistry {
class TaskDefinitionRegistryImpl implements ITaskDefinitionRegistry {
private taskTypes: IStringDictionary<Tasks.TaskTypeDescription>;
private taskTypes: IStringDictionary<Tasks.TaskDefinition>;
private readyPromise: TPromise<void>;
constructor() {
this.taskTypes = Object.create(null);
this.readyPromise = new TPromise<void>((resolve, reject) => {
taskTypesExtPoint.setHandler((extensions) => {
taskDefinitionsExtPoint.setHandler((extensions) => {
try {
extensions.forEach(extension => {
let taskTypes = extension.value;
@ -107,7 +113,7 @@ class TaskTypeRegistryImpl implements ITaskTypeRegistry {
return this.readyPromise;
}
public get(key: string): Tasks.TaskTypeDescription {
public get(key: string): Tasks.TaskDefinition {
return this.taskTypes[key];
}
@ -115,9 +121,9 @@ class TaskTypeRegistryImpl implements ITaskTypeRegistry {
return !!this.taskTypes[key];
}
public all(): Tasks.TaskTypeDescription[] {
public all(): Tasks.TaskDefinition[] {
return Object.keys(this.taskTypes).map(key => this.taskTypes[key]);
}
}
export const TaskTypeRegistry: ITaskTypeRegistry = new TaskTypeRegistryImpl();
export const TaskDefinitionRegistry: ITaskDefinitionRegistry = new TaskDefinitionRegistryImpl();

View file

@ -381,7 +381,7 @@ export interface TaskSet {
extension?: IExtensionDescription;
}
export interface TaskTypeDescription {
export interface TaskDefinition {
taskType: string;
required: string[];
properties: IJSONSchemaMap;

View file

@ -11,7 +11,7 @@ import { IJSONSchema } from 'vs/base/common/jsonSchema';
import commonSchema from './jsonSchemaCommon';
import { ProblemMatcherRegistry } from 'vs/platform/markers/common/problemMatcher';
import { TaskTypeRegistry } from '../common/taskTypeRegistry';
import { TaskDefinitionRegistry } from '../common/taskDefinitionRegistry';
function fixReferences(literal: any) {
if (Array.isArray(literal)) {
@ -177,8 +177,8 @@ let taskConfiguration: IJSONSchema = {
};
let taskDefinitions: IJSONSchema[] = [];
TaskTypeRegistry.onReady().then(() => {
for (let taskType of TaskTypeRegistry.all()) {
TaskDefinitionRegistry.onReady().then(() => {
for (let taskType of TaskDefinitionRegistry.all()) {
let schema: IJSONSchema = Objects.deepClone(taskConfiguration);
// Since we do this after the schema is assigned we need to patch the refs.
schema.properties.type = {

View file

@ -21,7 +21,7 @@ import {
} from 'vs/platform/markers/common/problemMatcher';
import * as Tasks from '../common/tasks';
import { TaskTypeRegistry } from '../common/taskTypeRegistry';
import { TaskDefinitionRegistry } from '../common/taskDefinitionRegistry';
/**
* Defines the problem handling strategy
@ -1106,7 +1106,7 @@ namespace ConfiguringTask {
context.problemReporter.fatal(nls.localize('ConfigurationParser.noTaskType', 'Error: tasks configuration must have a type property. The configuration will be ignored.\n{0}\n', JSON.stringify(external, null, 4)));
return undefined;
}
let typeDeclaration = TaskTypeRegistry.get(type);
let typeDeclaration = TaskDefinitionRegistry.get(type);
let identifier: TaskIdentifier;
if (Types.isString(customize)) {
if (customize.indexOf(grunt) === 0) {