-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathdebug-schema-updater.ts
144 lines (136 loc) · 6.09 KB
/
debug-schema-updater.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/********************************************************************************
* Copyright (C) 2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* This Source Code may also be made available under the following Secondary
* Licenses when the conditions for such availability set forth in the Eclipse
* Public License v. 2.0 are satisfied: GNU General Public License, version 2
* with the GNU Classpath Exception which is available at
* https://www.gnu.org/software/classpath/license.html.
*
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
********************************************************************************/
import { injectable, inject } from 'inversify';
import { JsonSchemaStore } from '@theia/core/lib/browser/json-schema-store';
import { InMemoryResources, deepClone } from '@theia/core/lib/common';
import { IJSONSchema } from '@theia/core/lib/common/json-schema';
import URI from '@theia/core/lib/common/uri';
import { DebugService } from '../common/debug-service';
@injectable()
export class DebugSchemaUpdater {
@inject(JsonSchemaStore) protected readonly jsonSchemaStore: JsonSchemaStore;
@inject(InMemoryResources) protected readonly inmemoryResources: InMemoryResources;
@inject(DebugService) protected readonly debug: DebugService;
async update(): Promise<void> {
const types = await this.debug.debugTypes();
const launchSchemaUrl = new URI('vscode://debug/launch.json');
const schema = { ...deepClone(launchSchema) };
const items = (<IJSONSchema>schema!.properties!['configurations'].items);
const attributePromises = types.map(type => this.debug.getSchemaAttributes(type));
for (const attributes of await Promise.all(attributePromises)) {
for (const attribute of attributes) {
attribute.properties = {
'debugViewLocation': {
enum: ['default', 'left', 'right', 'bottom'],
default: 'default',
description: 'Controls the location of the debug view.'
},
'openDebug': {
enum: ['neverOpen', 'openOnSessionStart', 'openOnFirstSessionStart', 'openOnDebugBreak'],
default: 'openOnSessionStart',
description: 'Controls when the debug view should open.'
},
'internalConsoleOptions': {
enum: ['neverOpen', 'openOnSessionStart', 'openOnFirstSessionStart'],
default: 'openOnFirstSessionStart',
description: 'Controls when the internal debug console should open.'
},
...attribute.properties
};
items.oneOf!.push(attribute);
}
}
items.defaultSnippets!.push(...await this.debug.getConfigurationSnippets());
const contents = JSON.stringify(schema);
try {
await this.inmemoryResources.update(launchSchemaUrl, contents);
} catch (e) {
this.inmemoryResources.add(launchSchemaUrl, contents);
this.jsonSchemaStore.registerSchema({
fileMatch: ['launch.json'],
url: launchSchemaUrl.toString()
});
}
}
}
// debug general schema
const defaultCompound = { name: 'Compound', configurations: [] };
const launchSchemaId = 'vscode://schemas/launch';
const launchSchema: IJSONSchema = {
id: launchSchemaId,
type: 'object',
title: 'Launch',
required: [],
default: { version: '0.2.0', configurations: [], compounds: [] },
properties: {
version: {
type: 'string',
description: 'Version of this file format.',
default: '0.2.0'
},
configurations: {
type: 'array',
description: 'List of configurations. Add new configurations or edit existing ones by using IntelliSense.',
items: {
defaultSnippets: [],
'type': 'object',
oneOf: []
}
},
compounds: {
type: 'array',
description: 'List of compounds. Each compound references multiple configurations which will get launched together.',
items: {
type: 'object',
required: ['name', 'configurations'],
properties: {
name: {
type: 'string',
description: 'Name of compound. Appears in the launch configuration drop down menu.'
},
configurations: {
type: 'array',
default: [],
items: {
oneOf: [{
enum: [],
description: 'Please use unique configuration names.'
}, {
type: 'object',
required: ['name'],
properties: {
name: {
enum: [],
description: 'Name of compound. Appears in the launch configuration drop down menu.'
},
folder: {
enum: [],
description: 'Name of folder in which the compound is located.'
}
}
}]
},
description: 'Names of configurations that will be started as part of this compound.'
}
},
default: defaultCompound
},
default: [
defaultCompound
]
}
}
};