Skip to content

Commit

Permalink
Ability to add task subschema
Browse files Browse the repository at this point in the history
Signed-off-by: Roman Nikitenko <[email protected]>
  • Loading branch information
RomanNikitenko committed Nov 18, 2019
1 parent ebe0580 commit 8c0e00c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/task/src/browser/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './task-contribution';
export * from './task-definition-registry';
export * from './task-problem-matcher-registry';
export * from './task-problem-pattern-registry';
export * from './task-schema-updater';
39 changes: 35 additions & 4 deletions packages/task/src/browser/task-schema-updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export class TaskSchemaUpdater {

update(): void {
const taskSchemaUri = new URI(taskSchemaId);

taskConfigurationSchema.oneOf = [processTaskConfigurationSchema, ...customizedDetectedTasks, ...customSchemas];

const schemaContent = this.getStrigifiedTaskSchema();
try {
this.inmemoryResources.update(taskSchemaUri, schemaContent);
Expand All @@ -67,6 +70,36 @@ export class TaskSchemaUpdater {
}
}

/**
* Adds given task schema to `taskConfigurationSchema` as `oneOf` subschema.
* Replaces existed subschema by given schema if the corrresponding `$id` properties are equal.
*
* Note: please provide `$id` property for subschema to have ability remove/replace it.
* @param schema subschema for adding to `taskConfigurationSchema`
*/
addSubschema(schema: IJSONSchema): void {
const schemaId = schema.$id;
if (schemaId) {
this.removeSubschema(schemaId);
}

customSchemas.push(schema);
this.update();
}

/**
* Removes task subschema from `taskConfigurationSchema`.
*
* @param arg `$id` property of subschema
*/
removeSubschema(arg: string): void {
const index = customSchemas.findIndex(existed => !!existed.$id && existed.$id === arg);
if (index > -1) {
customSchemas.splice(index, 1);
this.update();
}
}

/** Returns an array of task types that are registered, including the default types */
async getRegisteredTaskTypes(): Promise<string[]> {
const serverSupportedTypes = await this.taskServer.getRegisteredTaskTypes();
Expand Down Expand Up @@ -103,9 +136,6 @@ export class TaskSchemaUpdater {
customizedDetectedTask.additionalProperties = true;
customizedDetectedTasks.push(customizedDetectedTask);
});

taskConfigurationSchema.oneOf!.length = 1;
taskConfigurationSchema.oneOf!.push(...customizedDetectedTasks);
}

/** Returns the task's JSON schema */
Expand Down Expand Up @@ -301,8 +331,9 @@ const processTaskConfigurationSchema: IJSONSchema = {
};

const customizedDetectedTasks: IJSONSchema[] = [];
const customSchemas: IJSONSchema[] = [];

const taskConfigurationSchema: IJSONSchema = {
$id: taskSchemaId,
oneOf: [processTaskConfigurationSchema, ...customizedDetectedTasks]
oneOf: [processTaskConfigurationSchema, ...customizedDetectedTasks, ...customSchemas]
};

0 comments on commit 8c0e00c

Please sign in to comment.