diff --git a/packages/task/src/browser/task-schema-updater.ts b/packages/task/src/browser/task-schema-updater.ts index b65316f1200a8..14cd65977fd6f 100644 --- a/packages/task/src/browser/task-schema-updater.ts +++ b/packages/task/src/browser/task-schema-updater.ts @@ -99,6 +99,7 @@ export class TaskSchemaUpdater { }); customizedDetectedTask.properties!.problemMatcher = problemMatcher; customizedDetectedTask.properties!.options = commandOptionsSchema; + customizedDetectedTask.additionalProperties = true; customizedDetectedTasks.push(customizedDetectedTask); }); @@ -118,7 +119,8 @@ export class TaskSchemaUpdater { } }, inputs: inputsSchema.definitions!.inputs - } + }, + additionalProperties: false }; } @@ -251,7 +253,8 @@ const processTaskConfigurationSchema: IJSONSchema = { properties: commandAndArgs }, problemMatcher - } + }, + additionalProperties: true }; const customizedDetectedTasks: IJSONSchema[] = []; diff --git a/packages/task/src/browser/task-service.ts b/packages/task/src/browser/task-service.ts index 9d692b0a391bb..7c996444ddc8d 100644 --- a/packages/task/src/browser/task-service.ts +++ b/packages/task/src/browser/task-service.ts @@ -58,7 +58,6 @@ export interface QuickPickProblemMatcherItem { @injectable() export class TaskService implements TaskConfigurationClient { - /** * The last executed task. */ @@ -233,9 +232,26 @@ export class TaskService implements TaskConfigurationClient { return [...configuredTasks, ...notCustomizedProvidedTasks]; } - /** Returns an array of the task configurations which are configured in tasks.json files */ - getConfiguredTasks(): Promise { - return this.taskConfigurations.getTasks(); + /** Returns an array of the valid task configurations which are configured in tasks.json files */ + async getConfiguredTasks(): Promise { + const taskConfigs = await this.taskConfigurations.getTasks(); + const validTaskConfigs = taskConfigs.filter(t => this.isTaskConfigValid(t)); + if (validTaskConfigs.length !== taskConfigs.length) { + this.messageService.warn('Invalid task configurations are found. Open tasks.json and find details in the Problems view.'); + } + return validTaskConfigs; + } + + /** + * Returns `true` if the given task configuration is valid as per the task schema defined in Theia + * or contributed by Theia extensions and plugins, `false` otherwise. + */ + isTaskConfigValid(task: TaskConfiguration): boolean { + const schema = this.taskSchemaUpdater.getTaskSchema(); + const ajv = new Ajv(); + const validateSchema = ajv.compile(schema); + const isValid = !!validateSchema({ tasks: [task] }); + return isValid; } /** Returns an array of the task configurations which are provided by the extensions. */