@codingame/monaco-vscode-theme-service-override 1.82.4 → 1.82.5-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,256 @@
1
+ import * as nls from 'monaco-editor/esm/vs/nls.js';
2
+ import * as types from 'monaco-editor/esm/vs/base/common/types.js';
3
+ import * as resources from 'monaco-editor/esm/vs/base/common/resources.js';
4
+ import { ExtensionsRegistry } from 'vscode/vscode/vs/workbench/services/extensions/common/extensionsRegistry';
5
+ import { VS_DARK_THEME, VS_LIGHT_THEME, VS_HC_THEME, VS_HC_LIGHT_THEME, ExtensionData } from 'vscode/vscode/vs/workbench/services/themes/common/workbenchThemeService';
6
+ import { Emitter } from 'monaco-editor/esm/vs/base/common/event.js';
7
+
8
+ function registerColorThemeExtensionPoint() {
9
+ return ( ExtensionsRegistry.registerExtensionPoint({
10
+ extensionPoint: 'themes',
11
+ jsonSchema: {
12
+ description: ( nls.localize(
13
+ 'vscode.extension.contributes.themes',
14
+ 'Contributes textmate color themes.'
15
+ )),
16
+ type: 'array',
17
+ items: {
18
+ type: 'object',
19
+ defaultSnippets: [{ body: { label: '${1:label}', id: '${2:id}', uiTheme: VS_DARK_THEME, path: './themes/${3:id}.tmTheme.' } }],
20
+ properties: {
21
+ id: {
22
+ description: ( nls.localize(
23
+ 'vscode.extension.contributes.themes.id',
24
+ 'Id of the color theme as used in the user settings.'
25
+ )),
26
+ type: 'string'
27
+ },
28
+ label: {
29
+ description: ( nls.localize(
30
+ 'vscode.extension.contributes.themes.label',
31
+ 'Label of the color theme as shown in the UI.'
32
+ )),
33
+ type: 'string'
34
+ },
35
+ uiTheme: {
36
+ description: ( nls.localize(
37
+ 'vscode.extension.contributes.themes.uiTheme',
38
+ 'Base theme defining the colors around the editor: \'vs\' is the light color theme, \'vs-dark\' is the dark color theme. \'hc-black\' is the dark high contrast theme, \'hc-light\' is the light high contrast theme.'
39
+ )),
40
+ enum: [VS_LIGHT_THEME, VS_DARK_THEME, VS_HC_THEME, VS_HC_LIGHT_THEME]
41
+ },
42
+ path: {
43
+ description: ( nls.localize(
44
+ 'vscode.extension.contributes.themes.path',
45
+ 'Path of the tmTheme file. The path is relative to the extension folder and is typically \'./colorthemes/awesome-color-theme.json\'.'
46
+ )),
47
+ type: 'string'
48
+ }
49
+ },
50
+ required: ['path', 'uiTheme']
51
+ }
52
+ }
53
+ }));
54
+ }
55
+ function registerFileIconThemeExtensionPoint() {
56
+ return ( ExtensionsRegistry.registerExtensionPoint({
57
+ extensionPoint: 'iconThemes',
58
+ jsonSchema: {
59
+ description: ( nls.localize('vscode.extension.contributes.iconThemes', 'Contributes file icon themes.')),
60
+ type: 'array',
61
+ items: {
62
+ type: 'object',
63
+ defaultSnippets: [{ body: { id: '${1:id}', label: '${2:label}', path: './fileicons/${3:id}-icon-theme.json' } }],
64
+ properties: {
65
+ id: {
66
+ description: ( nls.localize(
67
+ 'vscode.extension.contributes.iconThemes.id',
68
+ 'Id of the file icon theme as used in the user settings.'
69
+ )),
70
+ type: 'string'
71
+ },
72
+ label: {
73
+ description: ( nls.localize(
74
+ 'vscode.extension.contributes.iconThemes.label',
75
+ 'Label of the file icon theme as shown in the UI.'
76
+ )),
77
+ type: 'string'
78
+ },
79
+ path: {
80
+ description: ( nls.localize(
81
+ 'vscode.extension.contributes.iconThemes.path',
82
+ 'Path of the file icon theme definition file. The path is relative to the extension folder and is typically \'./fileicons/awesome-icon-theme.json\'.'
83
+ )),
84
+ type: 'string'
85
+ }
86
+ },
87
+ required: ['path', 'id']
88
+ }
89
+ }
90
+ }));
91
+ }
92
+ function registerProductIconThemeExtensionPoint() {
93
+ return ( ExtensionsRegistry.registerExtensionPoint({
94
+ extensionPoint: 'productIconThemes',
95
+ jsonSchema: {
96
+ description: ( nls.localize(
97
+ 'vscode.extension.contributes.productIconThemes',
98
+ 'Contributes product icon themes.'
99
+ )),
100
+ type: 'array',
101
+ items: {
102
+ type: 'object',
103
+ defaultSnippets: [{ body: { id: '${1:id}', label: '${2:label}', path: './producticons/${3:id}-product-icon-theme.json' } }],
104
+ properties: {
105
+ id: {
106
+ description: ( nls.localize(
107
+ 'vscode.extension.contributes.productIconThemes.id',
108
+ 'Id of the product icon theme as used in the user settings.'
109
+ )),
110
+ type: 'string'
111
+ },
112
+ label: {
113
+ description: ( nls.localize(
114
+ 'vscode.extension.contributes.productIconThemes.label',
115
+ 'Label of the product icon theme as shown in the UI.'
116
+ )),
117
+ type: 'string'
118
+ },
119
+ path: {
120
+ description: ( nls.localize(
121
+ 'vscode.extension.contributes.productIconThemes.path',
122
+ 'Path of the product icon theme definition file. The path is relative to the extension folder and is typically \'./producticons/awesome-product-icon-theme.json\'.'
123
+ )),
124
+ type: 'string'
125
+ }
126
+ },
127
+ required: ['path', 'id']
128
+ }
129
+ }
130
+ }));
131
+ }
132
+ class ThemeRegistry {
133
+ constructor(themesExtPoint, create, idRequired = false, builtInTheme = undefined) {
134
+ this.themesExtPoint = themesExtPoint;
135
+ this.create = create;
136
+ this.idRequired = idRequired;
137
+ this.builtInTheme = builtInTheme;
138
+ this.onDidChangeEmitter = ( new Emitter());
139
+ this.onDidChange = this.onDidChangeEmitter.event;
140
+ this.extensionThemes = [];
141
+ this.initialize();
142
+ }
143
+ initialize() {
144
+ this.themesExtPoint.setHandler((extensions, delta) => {
145
+ const previousIds = {};
146
+ const added = [];
147
+ for (const theme of this.extensionThemes) {
148
+ previousIds[theme.id] = theme;
149
+ }
150
+ this.extensionThemes.length = 0;
151
+ for (const ext of extensions) {
152
+ const extensionData = ExtensionData.fromName(ext.description.publisher, ext.description.name, ext.description.isBuiltin);
153
+ this.onThemes(extensionData, ext.description.extensionLocation, ext.value, this.extensionThemes, ext.collector);
154
+ }
155
+ for (const theme of this.extensionThemes) {
156
+ if (!previousIds[theme.id]) {
157
+ added.push(theme);
158
+ }
159
+ else {
160
+ delete previousIds[theme.id];
161
+ }
162
+ }
163
+ const removed = ( Object.values(previousIds));
164
+ this.onDidChangeEmitter.fire({ themes: this.extensionThemes, added, removed });
165
+ });
166
+ }
167
+ onThemes(extensionData, extensionLocation, themeContributions, resultingThemes = [], log) {
168
+ if (!Array.isArray(themeContributions)) {
169
+ log?.error(( nls.localize(
170
+ 'reqarray',
171
+ "Extension point `{0}` must be an array.",
172
+ this.themesExtPoint.name
173
+ )));
174
+ return resultingThemes;
175
+ }
176
+ themeContributions.forEach(theme => {
177
+ if (!theme.path || !types.isString(theme.path)) {
178
+ log?.error(( nls.localize(
179
+ 'reqpath',
180
+ "Expected string in `contributes.{0}.path`. Provided value: {1}",
181
+ this.themesExtPoint.name,
182
+ String(theme.path)
183
+ )));
184
+ return;
185
+ }
186
+ if (this.idRequired && (!theme.id || !types.isString(theme.id))) {
187
+ log?.error(( nls.localize(
188
+ 'reqid',
189
+ "Expected string in `contributes.{0}.id`. Provided value: {1}",
190
+ this.themesExtPoint.name,
191
+ String(theme.id)
192
+ )));
193
+ return;
194
+ }
195
+ const themeLocation = resources.joinPath(extensionLocation, theme.path);
196
+ if (!resources.isEqualOrParent(themeLocation, extensionLocation)) {
197
+ log?.warn(( nls.localize(
198
+ 'invalid.path.1',
199
+ "Expected `contributes.{0}.path` ({1}) to be included inside extension's folder ({2}). This might make the extension non-portable.",
200
+ this.themesExtPoint.name,
201
+ themeLocation.path,
202
+ extensionLocation.path
203
+ )));
204
+ }
205
+ const themeData = this.create(theme, themeLocation, extensionData);
206
+ resultingThemes.push(themeData);
207
+ });
208
+ return resultingThemes;
209
+ }
210
+ findThemeById(themeId) {
211
+ if (this.builtInTheme && this.builtInTheme.id === themeId) {
212
+ return this.builtInTheme;
213
+ }
214
+ const allThemes = this.getThemes();
215
+ for (const t of allThemes) {
216
+ if (t.id === themeId) {
217
+ return t;
218
+ }
219
+ }
220
+ return undefined;
221
+ }
222
+ findThemeBySettingsId(settingsId, defaultSettingsId) {
223
+ if (this.builtInTheme && this.builtInTheme.settingsId === settingsId) {
224
+ return this.builtInTheme;
225
+ }
226
+ const allThemes = this.getThemes();
227
+ let defaultTheme = undefined;
228
+ for (const t of allThemes) {
229
+ if (t.settingsId === settingsId) {
230
+ return t;
231
+ }
232
+ if (t.settingsId === defaultSettingsId) {
233
+ defaultTheme = t;
234
+ }
235
+ }
236
+ return defaultTheme;
237
+ }
238
+ findThemeByExtensionLocation(extLocation) {
239
+ if (extLocation) {
240
+ return this.getThemes().filter(t => t.location && resources.isEqualOrParent(t.location, extLocation));
241
+ }
242
+ return [];
243
+ }
244
+ getThemes() {
245
+ return this.extensionThemes;
246
+ }
247
+ getMarketplaceThemes(manifest, extensionLocation, extensionData) {
248
+ const themes = manifest?.contributes?.[this.themesExtPoint.name];
249
+ if (Array.isArray(themes)) {
250
+ return this.onThemes(extensionData, extensionLocation, themes);
251
+ }
252
+ return [];
253
+ }
254
+ }
255
+
256
+ export { ThemeRegistry, registerColorThemeExtensionPoint, registerFileIconThemeExtensionPoint, registerProductIconThemeExtensionPoint };