src/vs/workbench/contrib/tasks/common/taskDefinitionRegistry.ts

191 LOC · 108 covered · 83 uncovered · 9 ranges · 131 concepts · 2 introducers · 59 tests

File neighbourhood

The centred file is linked to every concept that introduces one of its ranges, every test that runs code from the file, and the gray connector concepts standing between those tests and the file's own introducer concepts. Undirected links join concepts to every file where they introduce source and concepts to the tests they introduce; arrows show specialization between the displayed concepts and bridge only concepts omitted from this view. Concept colors match the source ranges below; connector concepts have no source color and are shown in gray.

Focused file, its introducer and connector concepts, their introduced files, and tests that run code from the file

In the embedded map, ordinary wheel input scrolls the page; use the visible controls to zoom and drag to pan. Open the full-screen map for canvas navigation: wheel pans, Ctrl/Command plus wheel zooms, and arrow keys pan when this region is focused. On touch screens, open the full-screen map to pan or pinch. If JavaScript or WebGL is unavailable, use the related-file, concept, and source links on this page.

Graph controls are ready.

Interactive rendering requires JavaScript and WebGL. Use the related-file, concept, and source links on this page while the interactive map is unavailable.

1 > /*--------------------------------------------------------------------------------------------- taskConfiguration.ts ×80
2 > * Copyright (c) Microsoft Corporation. All rights reserved.
3 > * Licensed under the MIT License. See License.txt in the project root for license information.
4 > *--------------------------------------------------------------------------------------------*/
5 >
6 > import * as nls from '../../../../nls.js';
7 > import { IJSONSchema, IJSONSchemaMap } from '../../../../base/common/jsonSchema.js';
8 > import { IStringDictionary } from '../../../../base/common/collections.js';
9 > import * as Types from '../../../../base/common/types.js';
10 > import * as Objects from '../../../../base/common/objects.js';
11 >
12 > import { ExtensionsRegistry, ExtensionMessageCollector } from '../../../services/extensions/common/extensionsRegistry.js';
13 >
14 > import * as Tasks from './tasks.js';
15 > import { ExtensionIdentifier } from '../../../../platform/extensions/common/extensions.js';
16 > import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
17 > import { Emitter, Event } from '../../../../base/common/event.js';
18 >
19 >
20 > const taskDefinitionSchema: IJSONSchema = {
21 > type: 'object',
22 > additionalProperties: false,
23 > properties: {
24 > type: {
25 > type: 'string',
26 > description: nls.localize('TaskDefinition.description', 'The actual task type. Please note that types starting with a \'$\' are reserved for internal usage.')
27 > },
28 > required: {
29 > type: 'array',
30 > markdownDescription: nls.localize('TaskDefinition.required', 'The names of the properties from the `properties` object that must be provided for a task of this type to be considered a match. Used by VS Code to associate a `tasks.json` entry with a registered task provider.'),
31 > items: {
32 > type: 'string'
33 > }
34 > },
35 > properties: {
36 > type: 'object',
37 > description: nls.localize('TaskDefinition.properties', 'Additional properties of the task type'),
38 > additionalProperties: {
39 > $ref: 'http://json-schema.org/draft-07/schema#'
40 > }
41 > },
42 > when: {
43 > type: 'string',
44 > markdownDescription: nls.localize('TaskDefinition.when', 'Condition which must be true to enable this type of task. Consider using `shellExecutionSupported`, `processExecutionSupported`, and `customExecutionSupported` as appropriate for this task definition. See the [API documentation](https://code.visualstudio.com/api/extension-guides/task-provider#when-clause) for more information.'),
45 > default: ''
46 > }
47 > }
48 > };
49 >
50 > namespace Configuration {
51 > export interface ITaskDefinition {
52 > type?: string;
53 > required?: string[];
54 > properties?: IJSONSchemaMap;
55 > when?: string;
56 > }
57 >
58 > export function from(value: ITaskDefinition, extensionId: ExtensionIdentifier, messageCollector: ExtensionMessageCollector): Tasks.ITaskDefinition | undefined {
59 if (!value) {
60 return undefined;
61 }
62 const taskType = Types.isString(value.type) ? value.type : undefined;
63 if (!taskType || taskType.length === 0) {
64 messageCollector.error(nls.localize('TaskTypeConfiguration.noType', 'The task type configuration is missing the required \'taskType\' property'));
65 return undefined;
66 }
67 const required: string[] = [];
68 if (Array.isArray(value.required)) {
69 for (const element of value.required) {
70 if (Types.isString(element)) {
71 required.push(element);
72 }
73 }
74 }
75 return {
76 extensionId: extensionId.value,
77 taskType, required: required,
78 properties: value.properties ? Objects.deepClone(value.properties) : {},
79 when: value.when ? ContextKeyExpr.deserialize(value.when) : undefined
80 };
81 }
83 >
84 >
85 > const taskDefinitionsExtPoint = ExtensionsRegistry.registerExtensionPoint<Configuration.ITaskDefinition[]>({
86 > extensionPoint: 'taskDefinitions',
87 > activationEventsGenerator: function* (contributions: readonly Configuration.ITaskDefinition[]) {
88 for (const task of contributions) {
89 if (task.type) {
90 yield `onTaskType:${task.type}`;
91 }
92 }
93 },
94 > jsonSchema: { taskConfiguration.ts ×80
95 > description: nls.localize('TaskDefinitionExtPoint', 'Contributes task kinds'),
96 > type: 'array',
97 > items: taskDefinitionSchema
98 > }
99 > });
100 >
101 > export interface ITaskDefinitionRegistry {
102 > onReady(): Promise<void>;
103 >
104 > get(key: string): Tasks.ITaskDefinition;
105 > all(): Tasks.ITaskDefinition[];
106 > getJsonSchema(): IJSONSchema;
107 > readonly onDefinitionsChanged: Event<void>;
108 > }
109 >
110 > class TaskDefinitionRegistryImpl implements ITaskDefinitionRegistry {
111 >
112 > private taskTypes: IStringDictionary<Tasks.ITaskDefinition>;
113 > private readyPromise: Promise<void>;
114 > private _schema: IJSONSchema | undefined;
115 > private _onDefinitionsChanged: Emitter<void> = new Emitter();
116 > public onDefinitionsChanged: Event<void> = this._onDefinitionsChanged.event;
117 >
118 > constructor() {
119 > this.taskTypes = Object.create(null);
120 > this.readyPromise = new Promise<void>((resolve, reject) => {
121 > taskDefinitionsExtPoint.setHandler((extensions, delta) => {
122 this._schema = undefined;
123 try {
124 for (const extension of delta.removed) {
125 const taskTypes = extension.value;
126 for (const taskType of taskTypes) {
127 if (this.taskTypes && taskType.type && this.taskTypes[taskType.type]) {
128 delete this.taskTypes[taskType.type];
129 }
130 }
131 }
132 for (const extension of delta.added) {
133 const taskTypes = extension.value;
134 for (const taskType of taskTypes) {
135 const type = Configuration.from(taskType, extension.description.identifier, extension.collector);
136 if (type) {
137 this.taskTypes[type.taskType] = type;
138 }
139 }
140 }
141 if ((delta.removed.length > 0) || (delta.added.length > 0)) {
142 this._onDefinitionsChanged.fire();
143 }
144 } catch (error) {
145 }
146 resolve(undefined);
148 > });
149 > }
150 >
151 > public onReady(): Promise<void> {
152 return this.readyPromise;
153 }
155 > public get(key: string): Tasks.ITaskDefinition {
156 > return this.taskTypes[key]; taskDefinitionRegistry.ts ×1
157 > }
159 > public all(): Tasks.ITaskDefinition[] {
160 return Object.keys(this.taskTypes).map(key => this.taskTypes[key]);
161 }
163 > public getJsonSchema(): IJSONSchema {
164 if (this._schema === undefined) {
165 const schemas: IJSONSchema[] = [];
166 for (const definition of this.all()) {
167 const schema: IJSONSchema = {
168 type: 'object',
169 additionalProperties: false
170 };
171 if (definition.required.length > 0) {
172 schema.required = definition.required.slice(0);
173 }
174 if (definition.properties !== undefined) {
175 schema.properties = Objects.deepClone(definition.properties);
176 } else {
177 schema.properties = Object.create(null);
178 }
179 schema.properties!.type = {
180 type: 'string',
181 enum: [definition.taskType]
182 };
183 schemas.push(schema);
184 }
185 this._schema = { oneOf: schemas };
186 }
187 return this._schema;
188 }
190 >
191 > export const TaskDefinitionRegistry: ITaskDefinitionRegistry = new TaskDefinitionRegistryImpl();