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