@innovatorved/code-lab 0.3.1 → 0.4.0

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.
Files changed (171) hide show
  1. package/ARCHITECTURE.md +8 -4
  2. package/CHANGELOG.md +45 -0
  3. package/README.md +70 -158
  4. package/dist/apps/web/src/index.d.ts +34 -0
  5. package/dist/code-lab-sql.css +482 -0
  6. package/dist/code-lab-sql.d.ts +179 -0
  7. package/dist/code-lab-sql.esm.js +542 -0
  8. package/dist/code-lab-sql.umd.js +531 -0
  9. package/dist/code-lab.css +298 -2
  10. package/dist/code-lab.d.ts +110 -15
  11. package/dist/code-lab.esm.js +35284 -18253
  12. package/dist/code-lab.js +40434 -23431
  13. package/dist/code-lab.umd.js +65502 -0
  14. package/dist/diagnostics.d.ts +5 -0
  15. package/dist/extensions/cpp.esm.js +19532 -3772
  16. package/dist/extensions/cpp.js +19529 -3769
  17. package/dist/extensions/guided-lab.esm.js +19401 -3725
  18. package/dist/extensions/guided-lab.js +19400 -3724
  19. package/dist/extensions/python.d.ts +1 -0
  20. package/dist/extensions/python.esm.js +19666 -3843
  21. package/dist/extensions/python.js +19668 -3845
  22. package/dist/extensions/umbrella.d.ts +5 -0
  23. package/dist/index.d.ts +1 -1
  24. package/dist/modular-kernel.d.ts +11 -0
  25. package/dist/packages/commands/src/index.d.ts +96 -0
  26. package/dist/packages/core/src/di.d.ts +36 -0
  27. package/dist/packages/core/src/disposable.d.ts +27 -0
  28. package/dist/packages/core/src/errors.d.ts +69 -0
  29. package/dist/packages/core/src/events.d.ts +38 -0
  30. package/dist/packages/core/src/index.d.ts +6 -0
  31. package/dist/packages/core/src/path.d.ts +14 -0
  32. package/dist/packages/core/src/registry.d.ts +23 -0
  33. package/dist/packages/editor/src/index.d.ts +118 -0
  34. package/dist/packages/fs/src/backends.d.ts +37 -0
  35. package/dist/packages/fs/src/index.d.ts +3 -0
  36. package/dist/packages/fs/src/types.d.ts +40 -0
  37. package/dist/packages/fs/src/vfs-service.d.ts +33 -0
  38. package/dist/packages/preview/src/index.d.ts +34 -0
  39. package/dist/packages/runtime/src/index.d.ts +47 -0
  40. package/dist/packages/settings/src/builtin-schemas.d.ts +15 -0
  41. package/dist/packages/settings/src/configuration-service.d.ts +100 -0
  42. package/dist/packages/settings/src/index.d.ts +4 -0
  43. package/dist/packages/settings/src/jsonc.d.ts +20 -0
  44. package/dist/packages/settings/src/schema.d.ts +28 -0
  45. package/dist/packages/sql/src/completions.d.ts +8 -0
  46. package/dist/packages/sql/src/diagnostics.d.ts +2 -0
  47. package/dist/packages/sql/src/formatter.d.ts +2 -0
  48. package/dist/packages/sql/src/index.d.ts +7 -0
  49. package/dist/packages/sql/src/sql-editor.d.ts +2 -0
  50. package/dist/packages/sql/src/styles.d.ts +2 -0
  51. package/dist/packages/sql/src/tokenizer.d.ts +13 -0
  52. package/dist/packages/sql/src/types.d.ts +130 -0
  53. package/dist/packages/terminal/src/index.d.ts +54 -0
  54. package/dist/packages/ui/src/index.d.ts +4 -0
  55. package/dist/packages/ui/src/observability.d.ts +22 -0
  56. package/dist/packages/ui/src/plugin-registry.d.ts +89 -0
  57. package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
  58. package/dist/packages/ui/src/themes.d.ts +35 -0
  59. package/dist/preview-sw.js +82 -24
  60. package/dist/runtime.d.ts +3 -3
  61. package/dist/runtime.esm.js +503 -73
  62. package/dist/runtime.js +501 -73
  63. package/dist/schemas.d.ts +234 -814
  64. package/dist/schemas.esm.js +19401 -3725
  65. package/dist/schemas.js +19404 -3728
  66. package/dist/scm.d.ts +13 -2
  67. package/dist/search.d.ts +5 -1
  68. package/dist/shell.d.ts +1 -1
  69. package/dist/shell.esm.js +435 -54
  70. package/dist/shell.js +435 -54
  71. package/dist/terminal.esm.js +242 -54
  72. package/dist/terminal.js +242 -54
  73. package/dist/workbench/diff-editor.d.ts +1 -0
  74. package/dist/workbench/index.d.ts +1 -1
  75. package/dist/workbench/styles.d.ts +1 -1
  76. package/dist/zip.d.ts +4 -3
  77. package/package.json +37 -8
  78. package/packages/commands/README.md +7 -0
  79. package/packages/commands/package.json +16 -0
  80. package/packages/commands/src/index.ts +467 -0
  81. package/packages/commands/tsconfig.json +22 -0
  82. package/packages/core/README.md +12 -0
  83. package/packages/core/package.json +13 -0
  84. package/packages/core/src/di.ts +147 -0
  85. package/packages/core/src/disposable.ts +112 -0
  86. package/packages/core/src/errors.ts +205 -0
  87. package/packages/core/src/events.ts +157 -0
  88. package/packages/core/src/index.ts +49 -0
  89. package/packages/core/src/path.ts +118 -0
  90. package/packages/core/src/registry.ts +61 -0
  91. package/packages/core/tsconfig.json +19 -0
  92. package/packages/editor/README.md +9 -0
  93. package/packages/editor/package.json +18 -0
  94. package/packages/editor/src/index.ts +344 -0
  95. package/packages/editor/tsconfig.json +24 -0
  96. package/packages/fs/README.md +7 -0
  97. package/packages/fs/package.json +16 -0
  98. package/packages/fs/src/backends.ts +301 -0
  99. package/packages/fs/src/index.ts +18 -0
  100. package/packages/fs/src/types.ts +44 -0
  101. package/packages/fs/src/vfs-service.ts +257 -0
  102. package/packages/fs/tsconfig.json +22 -0
  103. package/packages/preview/README.md +3 -0
  104. package/packages/preview/package.json +16 -0
  105. package/packages/preview/src/index.ts +125 -0
  106. package/packages/preview/tsconfig.json +22 -0
  107. package/packages/runtime/README.md +3 -0
  108. package/packages/runtime/package.json +17 -0
  109. package/packages/runtime/src/index.ts +134 -0
  110. package/packages/runtime/tsconfig.json +23 -0
  111. package/packages/settings/README.md +7 -0
  112. package/packages/settings/package.json +16 -0
  113. package/packages/settings/src/builtin-schemas.ts +235 -0
  114. package/packages/settings/src/configuration-service.ts +543 -0
  115. package/packages/settings/src/index.ts +37 -0
  116. package/packages/settings/src/jsonc.ts +189 -0
  117. package/packages/settings/src/schema.ts +164 -0
  118. package/packages/settings/tsconfig.json +22 -0
  119. package/packages/sql/README.md +12 -0
  120. package/packages/sql/package.json +13 -0
  121. package/packages/sql/src/completions.ts +359 -0
  122. package/packages/sql/src/diagnostics.ts +200 -0
  123. package/packages/sql/src/formatter.ts +271 -0
  124. package/packages/sql/src/index.ts +54 -0
  125. package/packages/sql/src/sql-editor.ts +802 -0
  126. package/packages/sql/src/styles.ts +501 -0
  127. package/packages/sql/src/tokenizer.ts +457 -0
  128. package/packages/sql/src/types.ts +148 -0
  129. package/packages/sql/tsconfig.json +19 -0
  130. package/packages/terminal/README.md +3 -0
  131. package/packages/terminal/package.json +16 -0
  132. package/packages/terminal/src/index.ts +183 -0
  133. package/packages/terminal/tsconfig.json +22 -0
  134. package/packages/ui/README.md +8 -0
  135. package/packages/ui/package.json +18 -0
  136. package/packages/ui/src/index.ts +36 -0
  137. package/packages/ui/src/observability.ts +175 -0
  138. package/packages/ui/src/plugin-registry.ts +274 -0
  139. package/packages/ui/src/settings-dialog.ts +293 -0
  140. package/packages/ui/src/themes.ts +174 -0
  141. package/packages/ui/tsconfig.json +24 -0
  142. package/src/code-lab.css +298 -2
  143. package/src/csp.ts +7 -10
  144. package/src/diagnostics.ts +42 -3
  145. package/src/extensions/cpp.ts +105 -24
  146. package/src/extensions/python.ts +260 -116
  147. package/src/extensions/umbrella.ts +5 -0
  148. package/src/index.ts +1 -1
  149. package/src/modular-kernel.ts +11 -0
  150. package/src/preview-sw.js +73 -12
  151. package/src/runtime.ts +501 -74
  152. package/src/schemas.ts +62 -62
  153. package/src/scm.ts +106 -19
  154. package/src/search.ts +71 -27
  155. package/src/shell.ts +433 -53
  156. package/src/terminal.ts +239 -52
  157. package/src/workbench/diff-editor.ts +106 -18
  158. package/src/workbench/drawer.ts +17 -4
  159. package/src/workbench/guided-pane.ts +12 -2
  160. package/src/workbench/icons.ts +5 -2
  161. package/src/workbench/share.ts +37 -8
  162. package/src/workbench/styles.ts +2 -1
  163. package/src/workbench/toolbar.ts +15 -4
  164. package/src/workbench.ts +2877 -284
  165. package/src/zip.ts +29 -7
  166. package/dist/runtime/index.d.ts +0 -4
  167. package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
  168. package/dist/shell/index.d.ts +0 -4
  169. package/src/runtime/index.ts +0 -5
  170. package/src/shell/coreutils/compilers-cli.ts +0 -103
  171. package/src/shell/index.ts +0 -5
@@ -0,0 +1,543 @@
1
+ import {
2
+ createServiceId,
3
+ Emitter,
4
+ type Event,
5
+ type IDisposable,
6
+ toDisposable
7
+ } from '@code-lab/core';
8
+ import {
9
+ BUILTIN_SETTINGS,
10
+ buildSettingsJsonSchema,
11
+ EXTENSIONS_JSON_SCHEMA,
12
+ TASKS_JSON_SCHEMA,
13
+ type SettingDescriptor
14
+ } from './builtin-schemas';
15
+ import { parseJsonc } from './jsonc';
16
+ import { type JsonSchema, validateJsonSchema } from './schema';
17
+
18
+ export type ConfigurationTarget = 'default' | 'user' | 'workspace' | 'override';
19
+
20
+ export interface SettingDiagnostic {
21
+ readonly file: string;
22
+ readonly key?: string;
23
+ readonly message: string;
24
+ readonly line: number;
25
+ readonly column: number;
26
+ readonly severity: 'error' | 'warning';
27
+ }
28
+
29
+ export interface ConfigurationChangeEvent {
30
+ readonly affectedKeys: ReadonlySet<string>;
31
+ readonly source: ConfigurationTarget;
32
+ readonly affectsConfiguration: (prefixOrKey: string) => boolean;
33
+ }
34
+
35
+ export interface SettingInspection<T = unknown> {
36
+ readonly key: string;
37
+ readonly defaultValue: T | undefined;
38
+ readonly userValue: T | undefined;
39
+ readonly workspaceValue: T | undefined;
40
+ readonly overrideValue: T | undefined;
41
+ readonly effectiveValue: T | undefined;
42
+ readonly effectiveSource: ConfigurationTarget;
43
+ }
44
+
45
+ export interface WorkspaceTaskDefinition {
46
+ readonly id: string;
47
+ readonly label: string;
48
+ readonly command: string;
49
+ readonly group?: 'run' | 'build' | 'test' | 'dev';
50
+ readonly runOn?: 'manual' | 'folderOpen';
51
+ readonly cwd?: string;
52
+ readonly env?: Readonly<Record<string, string>>;
53
+ }
54
+
55
+ export interface WorkspaceExtensionsConfig {
56
+ readonly recommendations: readonly string[];
57
+ readonly autoActivate: readonly string[];
58
+ }
59
+
60
+ export interface IConfigurationService extends IDisposable {
61
+ readonly onDidChangeConfiguration: Event<ConfigurationChangeEvent>;
62
+ readonly onDidChangeDiagnostics: Event<readonly SettingDiagnostic[]>;
63
+ registerSetting(descriptor: SettingDescriptor): IDisposable;
64
+ getDescriptors(): SettingDescriptor[];
65
+ getJsonSchema(): JsonSchema;
66
+ get<T = unknown>(key: string, fallback?: T): T;
67
+ inspect<T = unknown>(key: string): SettingInspection<T>;
68
+ getDiagnostics(): readonly SettingDiagnostic[];
69
+ setUserSetting(key: string, value: unknown): boolean;
70
+ resetSetting(key: string): void;
71
+ setWorkspaceSetting(key: string, value: unknown): boolean;
72
+ loadWorkspaceSettingsJson(rawJsonc: string, filePath?: string): readonly SettingDiagnostic[];
73
+ setOverrides(overrides: Readonly<Record<string, unknown>>): void;
74
+ toWorkspaceJsonString(): string;
75
+ exportProfile(): string;
76
+ importProfile(rawJsonc: string): readonly SettingDiagnostic[];
77
+ toUrlParam(): string;
78
+ applyUrlParam(encoded: string): readonly SettingDiagnostic[];
79
+ }
80
+
81
+ export const IConfigurationServiceId = createServiceId<IConfigurationService>('code-lab.configuration');
82
+
83
+ function findKeyLine(raw: string, key: string): number {
84
+ const escaped = key.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
85
+ const match = new RegExp(`"${escaped}"\\s*:`).exec(raw);
86
+ if (!match) return 1;
87
+ return raw.slice(0, match.index).split('\n').length;
88
+ }
89
+
90
+ export class ConfigurationService implements IConfigurationService {
91
+ private readonly descriptors = new Map<string, SettingDescriptor>();
92
+ private readonly userValues = new Map<string, unknown>();
93
+ private readonly workspaceValues = new Map<string, unknown>();
94
+ private readonly overrideValues = new Map<string, unknown>();
95
+ private diagnostics: SettingDiagnostic[] = [];
96
+ private readonly changeEmitter = new Emitter<ConfigurationChangeEvent>({ name: 'config.change' });
97
+ private readonly diagEmitter = new Emitter<readonly SettingDiagnostic[]>({ name: 'config.diagnostics' });
98
+
99
+ public constructor(includeBuiltins = true) {
100
+ if (includeBuiltins) {
101
+ for (const d of BUILTIN_SETTINGS) {
102
+ this.descriptors.set(d.key, d);
103
+ }
104
+ }
105
+ }
106
+
107
+ public get onDidChangeConfiguration(): Event<ConfigurationChangeEvent> {
108
+ return this.changeEmitter.event;
109
+ }
110
+
111
+ public get onDidChangeDiagnostics(): Event<readonly SettingDiagnostic[]> {
112
+ return this.diagEmitter.event;
113
+ }
114
+
115
+ public registerSetting(descriptor: SettingDescriptor): IDisposable {
116
+ this.descriptors.set(descriptor.key, descriptor);
117
+ this.fireChange([descriptor.key], 'default');
118
+ return toDisposable(() => {
119
+ if (this.descriptors.get(descriptor.key) === descriptor) {
120
+ this.descriptors.delete(descriptor.key);
121
+ this.fireChange([descriptor.key], 'default');
122
+ }
123
+ });
124
+ }
125
+
126
+ public getDescriptors(): SettingDescriptor[] {
127
+ return Array.from(this.descriptors.values());
128
+ }
129
+
130
+ public getJsonSchema(): JsonSchema {
131
+ return buildSettingsJsonSchema(this.getDescriptors());
132
+ }
133
+
134
+ public getDiagnostics(): readonly SettingDiagnostic[] {
135
+ return this.diagnostics;
136
+ }
137
+
138
+ public inspect<T = unknown>(key: string): SettingInspection<T> {
139
+ const defaultValue = this.descriptors.get(key)?.defaultValue as T | undefined;
140
+ const userValue = this.userValues.get(key) as T | undefined;
141
+ const workspaceValue = this.workspaceValues.get(key) as T | undefined;
142
+ const overrideValue = this.overrideValues.get(key) as T | undefined;
143
+
144
+ if (overrideValue !== undefined) {
145
+ return {
146
+ key,
147
+ defaultValue,
148
+ userValue,
149
+ workspaceValue,
150
+ overrideValue,
151
+ effectiveValue: overrideValue,
152
+ effectiveSource: 'override'
153
+ };
154
+ }
155
+ if (workspaceValue !== undefined) {
156
+ return {
157
+ key,
158
+ defaultValue,
159
+ userValue,
160
+ workspaceValue,
161
+ overrideValue,
162
+ effectiveValue: workspaceValue,
163
+ effectiveSource: 'workspace'
164
+ };
165
+ }
166
+ if (userValue !== undefined) {
167
+ return {
168
+ key,
169
+ defaultValue,
170
+ userValue,
171
+ workspaceValue,
172
+ overrideValue,
173
+ effectiveValue: userValue,
174
+ effectiveSource: 'user'
175
+ };
176
+ }
177
+ return {
178
+ key,
179
+ defaultValue,
180
+ userValue,
181
+ workspaceValue,
182
+ overrideValue,
183
+ effectiveValue: defaultValue,
184
+ effectiveSource: 'default'
185
+ };
186
+ }
187
+
188
+ public get<T = unknown>(key: string, fallback?: T): T {
189
+ const inspected = this.inspect<T>(key);
190
+ if (inspected.effectiveValue !== undefined) {
191
+ return inspected.effectiveValue;
192
+ }
193
+ return fallback as T;
194
+ }
195
+
196
+ private validateKeyValue(key: string, value: unknown): string | null {
197
+ const desc = this.descriptors.get(key);
198
+ if (!desc) return null; // allow plugin keys not yet registered
199
+ const issues = validateJsonSchema(value, desc.schema, key);
200
+ return issues.length > 0 ? issues[0].message : null;
201
+ }
202
+
203
+ public setUserSetting(key: string, value: unknown): boolean {
204
+ const err = this.validateKeyValue(key, value);
205
+ if (err) return false;
206
+ this.userValues.set(key, value);
207
+ this.fireChange([key], 'user');
208
+ return true;
209
+ }
210
+
211
+ public setWorkspaceSetting(key: string, value: unknown): boolean {
212
+ const err = this.validateKeyValue(key, value);
213
+ if (err) return false;
214
+ this.workspaceValues.set(key, value);
215
+ this.fireChange([key], 'workspace');
216
+ return true;
217
+ }
218
+
219
+ public resetSetting(key: string): void {
220
+ const hadUser = this.userValues.delete(key);
221
+ const hadWs = this.workspaceValues.delete(key);
222
+ const hadOv = this.overrideValues.delete(key);
223
+ if (hadUser || hadWs || hadOv) {
224
+ this.fireChange([key], 'user');
225
+ }
226
+ }
227
+
228
+ public loadWorkspaceSettingsJson(
229
+ rawJsonc: string,
230
+ filePath = '.codelab/settings.json'
231
+ ): readonly SettingDiagnostic[] {
232
+ const nextDiags: SettingDiagnostic[] = [];
233
+ const affected = new Set<string>(this.workspaceValues.keys());
234
+
235
+ if (!rawJsonc || !rawJsonc.trim()) {
236
+ this.workspaceValues.clear();
237
+ this.updateDiagnostics([]);
238
+ if (affected.size > 0) this.fireChange(affected, 'workspace');
239
+ return [];
240
+ }
241
+
242
+ const parsed = parseJsonc<Record<string, unknown>>(rawJsonc);
243
+ for (const pe of parsed.errors) {
244
+ nextDiags.push({
245
+ file: filePath,
246
+ message: `Invalid settings JSONC: ${pe.message}`,
247
+ line: pe.line,
248
+ column: pe.column,
249
+ severity: 'error'
250
+ });
251
+ }
252
+
253
+ if (parsed.value === undefined || typeof parsed.value !== 'object' || parsed.value === null || Array.isArray(parsed.value)) {
254
+ if (parsed.errors.length === 0) {
255
+ nextDiags.push({
256
+ file: filePath,
257
+ message: 'Settings root must be a JSON object',
258
+ line: 1,
259
+ column: 1,
260
+ severity: 'error'
261
+ });
262
+ }
263
+ // Keep safe defaults by clearing invalid workspace overrides
264
+ this.workspaceValues.clear();
265
+ this.updateDiagnostics(nextDiags);
266
+ if (affected.size > 0) this.fireChange(affected, 'workspace');
267
+ return nextDiags;
268
+ }
269
+
270
+ this.workspaceValues.clear();
271
+ for (const [key, val] of Object.entries(parsed.value)) {
272
+ affected.add(key);
273
+ const schemaError = this.validateKeyValue(key, val);
274
+ if (schemaError) {
275
+ const fallback = this.userValues.has(key)
276
+ ? this.userValues.get(key)
277
+ : this.descriptors.get(key)?.defaultValue;
278
+ nextDiags.push({
279
+ file: filePath,
280
+ key,
281
+ message: `Invalid "${key}": ${schemaError}. Falling back to ${JSON.stringify(fallback)}.`,
282
+ line: findKeyLine(rawJsonc, key),
283
+ column: 3,
284
+ severity: 'warning'
285
+ });
286
+ } else {
287
+ this.workspaceValues.set(key, val);
288
+ }
289
+ }
290
+
291
+ this.updateDiagnostics(nextDiags);
292
+ if (affected.size > 0) {
293
+ this.fireChange(affected, 'workspace');
294
+ }
295
+ return nextDiags;
296
+ }
297
+
298
+ public setOverrides(overrides: Readonly<Record<string, unknown>>): void {
299
+ const affected = new Set<string>(this.overrideValues.keys());
300
+ this.overrideValues.clear();
301
+ for (const [key, val] of Object.entries(overrides)) {
302
+ if (this.validateKeyValue(key, val) === null) {
303
+ this.overrideValues.set(key, val);
304
+ affected.add(key);
305
+ }
306
+ }
307
+ if (affected.size > 0) {
308
+ this.fireChange(affected, 'override');
309
+ }
310
+ }
311
+
312
+ public toWorkspaceJsonString(): string {
313
+ const out: Record<string, unknown> = {};
314
+ const keys = Array.from(this.workspaceValues.keys()).sort();
315
+ for (const k of keys) {
316
+ out[k] = this.workspaceValues.get(k);
317
+ }
318
+ return JSON.stringify(out, null, 2) + '\n';
319
+ }
320
+
321
+ public exportProfile(): string {
322
+ const userObj: Record<string, unknown> = {};
323
+ for (const [k, v] of this.userValues.entries()) userObj[k] = v;
324
+ const wsObj: Record<string, unknown> = {};
325
+ for (const [k, v] of this.workspaceValues.entries()) wsObj[k] = v;
326
+ return JSON.stringify(
327
+ {
328
+ version: 1,
329
+ user: userObj,
330
+ workspace: wsObj
331
+ },
332
+ null,
333
+ 2
334
+ );
335
+ }
336
+
337
+ public importProfile(rawJsonc: string): readonly SettingDiagnostic[] {
338
+ const parsed = parseJsonc<{ user?: Record<string, unknown>; workspace?: Record<string, unknown> }>(rawJsonc);
339
+ if (!parsed.value || typeof parsed.value !== 'object') {
340
+ return [
341
+ {
342
+ file: 'settings-profile.json',
343
+ message: parsed.errors[0]?.message ?? 'Invalid settings profile JSON',
344
+ line: 1,
345
+ column: 1,
346
+ severity: 'error'
347
+ }
348
+ ];
349
+ }
350
+ const diags: SettingDiagnostic[] = [];
351
+ const affected = new Set<string>();
352
+ const userIn = parsed.value.user ?? (
353
+ !('workspace' in parsed.value) ? (parsed.value as unknown as Record<string, unknown>) : undefined
354
+ );
355
+ if (userIn && typeof userIn === 'object') {
356
+ for (const [k, v] of Object.entries(userIn)) {
357
+ const err = this.validateKeyValue(k, v);
358
+ if (err) {
359
+ diags.push({
360
+ file: 'settings-profile.json',
361
+ key: k,
362
+ message: `Invalid "${k}": ${err}`,
363
+ line: 1,
364
+ column: 1,
365
+ severity: 'warning'
366
+ });
367
+ } else {
368
+ this.userValues.set(k, v);
369
+ affected.add(k);
370
+ }
371
+ }
372
+ }
373
+ if (parsed.value.workspace && typeof parsed.value.workspace === 'object') {
374
+ for (const [k, v] of Object.entries(parsed.value.workspace)) {
375
+ const err = this.validateKeyValue(k, v);
376
+ if (!err) {
377
+ this.workspaceValues.set(k, v);
378
+ affected.add(k);
379
+ }
380
+ }
381
+ }
382
+ if (affected.size > 0) this.fireChange(affected, 'user');
383
+ return diags;
384
+ }
385
+
386
+ public toUrlParam(): string {
387
+ const effectiveDiff: Record<string, unknown> = {};
388
+ for (const desc of this.descriptors.values()) {
389
+ const val = this.get(desc.key);
390
+ if (JSON.stringify(val) !== JSON.stringify(desc.defaultValue)) {
391
+ effectiveDiff[desc.key] = val;
392
+ }
393
+ }
394
+ const json = JSON.stringify(effectiveDiff);
395
+ if (typeof btoa === 'function') {
396
+ return btoa(encodeURIComponent(json));
397
+ }
398
+ return encodeURIComponent(json);
399
+ }
400
+
401
+ public applyUrlParam(encoded: string): readonly SettingDiagnostic[] {
402
+ if (!encoded) return [];
403
+ let json = '';
404
+ try {
405
+ json = typeof atob === 'function' ? decodeURIComponent(atob(encoded)) : decodeURIComponent(encoded);
406
+ } catch {
407
+ try {
408
+ json = decodeURIComponent(encoded);
409
+ } catch {
410
+ return [{ file: 'url', message: 'Invalid encoded URL settings', line: 1, column: 1, severity: 'warning' }];
411
+ }
412
+ }
413
+ const parsed = parseJsonc<Record<string, unknown>>(json);
414
+ if (!parsed.value || typeof parsed.value !== 'object' || Array.isArray(parsed.value)) {
415
+ return [{ file: 'url', message: 'URL settings must decode to an object', line: 1, column: 1, severity: 'warning' }];
416
+ }
417
+ this.setOverrides(parsed.value);
418
+ return [];
419
+ }
420
+
421
+ private updateDiagnostics(next: SettingDiagnostic[]): void {
422
+ this.diagnostics = next;
423
+ this.diagEmitter.fire(this.diagnostics);
424
+ }
425
+
426
+ private fireChange(keys: Iterable<string>, source: ConfigurationTarget): void {
427
+ const affectedKeys = new Set<string>(keys);
428
+ this.changeEmitter.fire({
429
+ affectedKeys,
430
+ source,
431
+ affectsConfiguration: (prefixOrKey: string) => {
432
+ if (affectedKeys.has(prefixOrKey)) return true;
433
+ const prefix = prefixOrKey.endsWith('.') ? prefixOrKey : `${prefixOrKey}.`;
434
+ for (const k of affectedKeys) {
435
+ if (k.startsWith(prefix)) return true;
436
+ }
437
+ return false;
438
+ }
439
+ });
440
+ }
441
+
442
+ public dispose(): void {
443
+ this.descriptors.clear();
444
+ this.userValues.clear();
445
+ this.workspaceValues.clear();
446
+ this.overrideValues.clear();
447
+ this.changeEmitter.dispose();
448
+ this.diagEmitter.dispose();
449
+ }
450
+ }
451
+
452
+ export function parseTasksConfig(
453
+ rawJsonc: string,
454
+ filePath = '.codelab/tasks.json'
455
+ ): { tasks: WorkspaceTaskDefinition[]; diagnostics: SettingDiagnostic[] } {
456
+ const diagnostics: SettingDiagnostic[] = [];
457
+ if (!rawJsonc || !rawJsonc.trim()) return { tasks: [], diagnostics };
458
+ const parsed = parseJsonc<{ version?: string; tasks?: unknown[] }>(rawJsonc);
459
+ for (const err of parsed.errors) {
460
+ diagnostics.push({
461
+ file: filePath,
462
+ message: `Invalid tasks.json: ${err.message}`,
463
+ line: err.line,
464
+ column: err.column,
465
+ severity: 'error'
466
+ });
467
+ }
468
+ if (!parsed.value) return { tasks: [], diagnostics };
469
+ const schemaIssues = validateJsonSchema(parsed.value, TASKS_JSON_SCHEMA, 'tasks');
470
+ for (const issue of schemaIssues) {
471
+ diagnostics.push({
472
+ file: filePath,
473
+ message: `${issue.path}: ${issue.message}`,
474
+ line: 1,
475
+ column: 1,
476
+ severity: 'warning'
477
+ });
478
+ }
479
+ const rawTasks = Array.isArray(parsed.value.tasks) ? parsed.value.tasks : [];
480
+ const tasks: WorkspaceTaskDefinition[] = [];
481
+ for (let i = 0; i < rawTasks.length; i++) {
482
+ const item = rawTasks[i];
483
+ if (typeof item === 'object' && item !== null) {
484
+ const rec = item as Record<string, unknown>;
485
+ if (typeof rec.label === 'string' && typeof rec.command === 'string' && rec.command.trim()) {
486
+ tasks.push({
487
+ id: typeof rec.id === 'string' && rec.id ? rec.id : `task-${i + 1}`,
488
+ label: rec.label,
489
+ command: rec.command,
490
+ group:
491
+ rec.group === 'run' || rec.group === 'build' || rec.group === 'test' || rec.group === 'dev'
492
+ ? rec.group
493
+ : undefined,
494
+ runOn: rec.runOn === 'folderOpen' ? 'folderOpen' : 'manual',
495
+ cwd: typeof rec.cwd === 'string' ? rec.cwd : undefined,
496
+ env:
497
+ typeof rec.env === 'object' && rec.env !== null && !Array.isArray(rec.env)
498
+ ? (rec.env as Record<string, string>)
499
+ : undefined
500
+ });
501
+ }
502
+ }
503
+ }
504
+ return { tasks, diagnostics };
505
+ }
506
+
507
+ export function parseExtensionsConfig(
508
+ rawJsonc: string,
509
+ filePath = '.codelab/extensions.json'
510
+ ): { config: WorkspaceExtensionsConfig; diagnostics: SettingDiagnostic[] } {
511
+ const diagnostics: SettingDiagnostic[] = [];
512
+ const empty: WorkspaceExtensionsConfig = { recommendations: [], autoActivate: [] };
513
+ if (!rawJsonc || !rawJsonc.trim()) return { config: empty, diagnostics };
514
+ const parsed = parseJsonc<Record<string, unknown>>(rawJsonc);
515
+ for (const err of parsed.errors) {
516
+ diagnostics.push({
517
+ file: filePath,
518
+ message: `Invalid extensions.json: ${err.message}`,
519
+ line: err.line,
520
+ column: err.column,
521
+ severity: 'error'
522
+ });
523
+ }
524
+ if (!parsed.value || typeof parsed.value !== 'object' || Array.isArray(parsed.value)) {
525
+ return { config: empty, diagnostics };
526
+ }
527
+ for (const issue of validateJsonSchema(parsed.value, EXTENSIONS_JSON_SCHEMA, 'extensions')) {
528
+ diagnostics.push({
529
+ file: filePath,
530
+ message: `${issue.path}: ${issue.message}`,
531
+ line: 1,
532
+ column: 1,
533
+ severity: 'warning'
534
+ });
535
+ }
536
+ const recs = Array.isArray(parsed.value.recommendations)
537
+ ? parsed.value.recommendations.filter((x): x is string => typeof x === 'string')
538
+ : [];
539
+ const auto = Array.isArray(parsed.value.autoActivate)
540
+ ? parsed.value.autoActivate.filter((x): x is string => typeof x === 'string')
541
+ : [];
542
+ return { config: { recommendations: recs, autoActivate: auto }, diagnostics };
543
+ }
@@ -0,0 +1,37 @@
1
+ export {
2
+ type JsoncParseError,
3
+ type JsoncParseResult,
4
+ stripJsonCommentsAndTrailingCommas,
5
+ parseJsonc
6
+ } from './jsonc';
7
+
8
+ export {
9
+ type JsonSchemaType,
10
+ type JsonSchema,
11
+ type SchemaValidationIssue,
12
+ validateJsonSchema
13
+ } from './schema';
14
+
15
+ export {
16
+ type SettingCategory,
17
+ type SettingDescriptor,
18
+ BUILTIN_SETTINGS,
19
+ buildSettingsJsonSchema,
20
+ KEYBINDINGS_JSON_SCHEMA,
21
+ TASKS_JSON_SCHEMA,
22
+ EXTENSIONS_JSON_SCHEMA
23
+ } from './builtin-schemas';
24
+
25
+ export {
26
+ type ConfigurationTarget,
27
+ type SettingDiagnostic,
28
+ type ConfigurationChangeEvent,
29
+ type SettingInspection,
30
+ type WorkspaceTaskDefinition,
31
+ type WorkspaceExtensionsConfig,
32
+ type IConfigurationService,
33
+ IConfigurationServiceId,
34
+ ConfigurationService,
35
+ parseTasksConfig,
36
+ parseExtensionsConfig
37
+ } from './configuration-service';