jsonSchema_v1.ts 3.6 KB
Newer Older
D
Dirk Baeumer 已提交
1 2 3 4 5 6 7 8 9
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import * as nls from 'vs/nls';
import * as Objects from 'vs/base/common/objects';
import { IJSONSchema } from 'vs/base/common/jsonSchema';

10
import { ProblemMatcherRegistry } from 'vs/workbench/contrib/tasks/common/problemMatcher';
11

D
Dirk Baeumer 已提交
12 13 14 15 16
import commonSchema from './jsonSchemaCommon';

const schema: IJSONSchema = {
	oneOf: [
		{
17
			allOf: [
D
Dirk Baeumer 已提交
18
				{
19 20 21 22 23 24
					type: 'object',
					required: ['version'],
					properties: {
						version: {
							type: 'string',
							enum: ['0.1.0'],
D
Dirk Baeumer 已提交
25
							deprecationMessage: nls.localize('JsonSchema.version.deprecated', 'Task version 0.1.0 is deprecated. Please use 2.0.0'),
26
							description: nls.localize('JsonSchema.version', 'The config\'s version number')
D
Dirk Baeumer 已提交
27
						},
28 29
						_runner: {
							deprecationMessage: nls.localize('JsonSchema._runner', 'The runner has graduated. Use the offical runner property')
D
Dirk Baeumer 已提交
30
						},
31 32 33 34 35
						runner: {
							type: 'string',
							enum: ['process', 'terminal'],
							default: 'process',
							description: nls.localize('JsonSchema.runner', 'Defines whether the task is executed as a process and the output is shown in the output window or inside the terminal.')
D
Dirk Baeumer 已提交
36
						},
37 38 39 40 41 42 43 44 45 46 47
						windows: {
							$ref: '#/definitions/taskRunnerConfiguration',
							description: nls.localize('JsonSchema.windows', 'Windows specific command configuration')
						},
						osx: {
							$ref: '#/definitions/taskRunnerConfiguration',
							description: nls.localize('JsonSchema.mac', 'Mac specific command configuration')
						},
						linux: {
							$ref: '#/definitions/taskRunnerConfiguration',
							description: nls.localize('JsonSchema.linux', 'Linux specific command configuration')
D
Dirk Baeumer 已提交
48 49 50 51
						}
					}
				},
				{
52
					$ref: '#/definitions/taskRunnerConfiguration'
D
Dirk Baeumer 已提交
53 54 55 56 57 58 59 60 61 62 63 64
				}
			]
		}
	]
};

const shellCommand: IJSONSchema = {
	type: 'boolean',
	default: true,
	description: nls.localize('JsonSchema.shell', 'Specifies whether the command is a shell command or an external program. Defaults to false if omitted.')
};

J
Johannes Rieken 已提交
65
schema.definitions = Objects.deepClone(commonSchema.definitions);
A
Alex Ross 已提交
66 67 68 69
let definitions = schema.definitions!;
definitions['commandConfiguration']['properties']!['isShellCommand'] = Objects.deepClone(shellCommand);
definitions['taskDescription']['properties']!['isShellCommand'] = Objects.deepClone(shellCommand);
definitions['taskRunnerConfiguration']['properties']!['isShellCommand'] = Objects.deepClone(shellCommand);
D
Dirk Baeumer 已提交
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93

Object.getOwnPropertyNames(definitions).forEach(key => {
	let newKey = key + '1';
	definitions[newKey] = definitions[key];
	delete definitions[key];
});

function fixReferences(literal: any) {
	if (Array.isArray(literal)) {
		literal.forEach(fixReferences);
	} else if (typeof literal === 'object') {
		if (literal['$ref']) {
			literal['$ref'] = literal['$ref'] + '1';
		}
		Object.getOwnPropertyNames(literal).forEach(property => {
			let value = literal[property];
			if (Array.isArray(value) || typeof value === 'object') {
				fixReferences(value);
			}
		});
	}
}
fixReferences(schema);

94 95 96
ProblemMatcherRegistry.onReady().then(() => {
	try {
		let matcherIds = ProblemMatcherRegistry.keys().map(key => '$' + key);
A
Alex Ross 已提交
97 98
		definitions.problemMatcherType1.oneOf![0].enum = matcherIds;
		(definitions.problemMatcherType1.oneOf![2].items as IJSONSchema).anyOf![1].enum = matcherIds;
99 100 101 102 103
	} catch (err) {
		console.log('Installing problem matcher ids failed');
	}
});

J
Johannes Rieken 已提交
104
export default schema;