@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.
Files changed (164) hide show
  1. package/ARCHITECTURE.md +5 -3
  2. package/CHANGELOG.md +41 -0
  3. package/README.md +53 -175
  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 +1799 -98
  10. package/dist/code-lab.d.ts +110 -15
  11. package/dist/code-lab.esm.js +49678 -23253
  12. package/dist/code-lab.js +49648 -23251
  13. package/dist/code-lab.umd.js +75766 -0
  14. package/dist/diagnostics.d.ts +3 -0
  15. package/dist/extensions/cpp.esm.js +19504 -3788
  16. package/dist/extensions/cpp.js +19501 -3785
  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 +19597 -3788
  21. package/dist/extensions/python.js +19597 -3788
  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 +107 -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 +90 -0
  57. package/dist/packages/ui/src/settings-dialog.d.ts +53 -0
  58. package/dist/packages/ui/src/themes.d.ts +40 -0
  59. package/dist/preview-sw.js +53 -12
  60. package/dist/runtime.d.ts +3 -3
  61. package/dist/runtime.esm.js +467 -44
  62. package/dist/runtime.js +465 -44
  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 +92 -11
  67. package/dist/shell.d.ts +1 -1
  68. package/dist/shell.esm.js +1300 -151
  69. package/dist/shell.js +1300 -151
  70. package/dist/storage.d.ts +47 -0
  71. package/dist/terminal.esm.js +62 -3
  72. package/dist/terminal.js +62 -3
  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/package.json +38 -9
  77. package/packages/commands/README.md +7 -0
  78. package/packages/commands/package.json +16 -0
  79. package/packages/commands/src/index.ts +467 -0
  80. package/packages/commands/tsconfig.json +22 -0
  81. package/packages/core/README.md +12 -0
  82. package/packages/core/package.json +13 -0
  83. package/packages/core/src/di.ts +147 -0
  84. package/packages/core/src/disposable.ts +112 -0
  85. package/packages/core/src/errors.ts +205 -0
  86. package/packages/core/src/events.ts +157 -0
  87. package/packages/core/src/index.ts +49 -0
  88. package/packages/core/src/path.ts +118 -0
  89. package/packages/core/src/registry.ts +61 -0
  90. package/packages/core/tsconfig.json +19 -0
  91. package/packages/editor/README.md +9 -0
  92. package/packages/editor/package.json +18 -0
  93. package/packages/editor/src/index.ts +344 -0
  94. package/packages/editor/tsconfig.json +24 -0
  95. package/packages/fs/README.md +7 -0
  96. package/packages/fs/package.json +16 -0
  97. package/packages/fs/src/backends.ts +301 -0
  98. package/packages/fs/src/index.ts +18 -0
  99. package/packages/fs/src/types.ts +44 -0
  100. package/packages/fs/src/vfs-service.ts +257 -0
  101. package/packages/fs/tsconfig.json +22 -0
  102. package/packages/preview/README.md +3 -0
  103. package/packages/preview/package.json +16 -0
  104. package/packages/preview/src/index.ts +125 -0
  105. package/packages/preview/tsconfig.json +22 -0
  106. package/packages/runtime/README.md +3 -0
  107. package/packages/runtime/package.json +17 -0
  108. package/packages/runtime/src/index.ts +134 -0
  109. package/packages/runtime/tsconfig.json +23 -0
  110. package/packages/settings/README.md +7 -0
  111. package/packages/settings/package.json +16 -0
  112. package/packages/settings/src/builtin-schemas.ts +246 -0
  113. package/packages/settings/src/configuration-service.ts +609 -0
  114. package/packages/settings/src/index.ts +38 -0
  115. package/packages/settings/src/jsonc.ts +189 -0
  116. package/packages/settings/src/schema.ts +164 -0
  117. package/packages/settings/tsconfig.json +22 -0
  118. package/packages/sql/README.md +12 -0
  119. package/packages/sql/package.json +13 -0
  120. package/packages/sql/src/completions.ts +359 -0
  121. package/packages/sql/src/diagnostics.ts +200 -0
  122. package/packages/sql/src/formatter.ts +271 -0
  123. package/packages/sql/src/index.ts +54 -0
  124. package/packages/sql/src/sql-editor.ts +802 -0
  125. package/packages/sql/src/styles.ts +501 -0
  126. package/packages/sql/src/tokenizer.ts +457 -0
  127. package/packages/sql/src/types.ts +148 -0
  128. package/packages/sql/tsconfig.json +19 -0
  129. package/packages/terminal/README.md +3 -0
  130. package/packages/terminal/package.json +16 -0
  131. package/packages/terminal/src/index.ts +183 -0
  132. package/packages/terminal/tsconfig.json +22 -0
  133. package/packages/ui/README.md +8 -0
  134. package/packages/ui/package.json +18 -0
  135. package/packages/ui/src/index.ts +40 -0
  136. package/packages/ui/src/observability.ts +175 -0
  137. package/packages/ui/src/plugin-registry.ts +289 -0
  138. package/packages/ui/src/settings-dialog.ts +575 -0
  139. package/packages/ui/src/themes.ts +267 -0
  140. package/packages/ui/tsconfig.json +24 -0
  141. package/src/code-lab.css +1799 -98
  142. package/src/diagnostics.ts +139 -7
  143. package/src/extensions/cpp.ts +88 -45
  144. package/src/extensions/python.ts +186 -53
  145. package/src/extensions/umbrella.ts +5 -0
  146. package/src/index.ts +1 -1
  147. package/src/modular-kernel.ts +11 -0
  148. package/src/preview-sw.js +52 -11
  149. package/src/runtime.ts +466 -46
  150. package/src/schemas.ts +62 -62
  151. package/src/scm.ts +781 -58
  152. package/src/shell.ts +1299 -151
  153. package/src/storage.ts +336 -3
  154. package/src/terminal.ts +60 -2
  155. package/src/workbench/diff-editor.ts +66 -6
  156. package/src/workbench/icons.ts +12 -2
  157. package/src/workbench/styles.ts +25 -19
  158. package/src/workbench.ts +17059 -6673
  159. package/dist/runtime/index.d.ts +0 -4
  160. package/dist/shell/coreutils/compilers-cli.d.ts +0 -24
  161. package/dist/shell/index.d.ts +0 -4
  162. package/src/runtime/index.ts +0 -5
  163. package/src/shell/coreutils/compilers-cli.ts +0 -103
  164. package/src/shell/index.ts +0 -5
@@ -0,0 +1,289 @@
1
+ import {
2
+ type CommandDescriptor,
3
+ type ICommandRegistry,
4
+ type IKeybindingService,
5
+ type KeybindingRule
6
+ } from '@code-lab/commands';
7
+ import {
8
+ CodeLabError,
9
+ ContributionRegistry,
10
+ createServiceId,
11
+ DisposableStore,
12
+ Emitter,
13
+ type Event,
14
+ type IDisposable,
15
+ type ILogger
16
+ } from '@code-lab/core';
17
+ import type { IConfigurationService, SettingDescriptor } from '@code-lab/settings';
18
+ import type { IThemeService, ThemeDefinition } from './themes';
19
+
20
+ export interface PanelContribution {
21
+ readonly id: string;
22
+ readonly title: string;
23
+ readonly location: 'drawer' | 'sidebar';
24
+ readonly icon?: string;
25
+ readonly render: (container: HTMLElement) => void | IDisposable;
26
+ }
27
+
28
+ export interface LanguageContribution {
29
+ readonly id: string;
30
+ readonly extensions: readonly string[];
31
+ readonly aliases?: readonly string[];
32
+ readonly runFile?: (filePath: string, source: string) => Promise<{ ok: boolean; stdout: string; stderr: string }>;
33
+ }
34
+
35
+ export interface PluginContributions {
36
+ readonly commands?: readonly CommandDescriptor[];
37
+ readonly settings?: readonly SettingDescriptor[];
38
+ readonly keybindings?: readonly KeybindingRule[];
39
+ readonly themes?: readonly ThemeDefinition[];
40
+ readonly panels?: readonly PanelContribution[];
41
+ readonly languages?: readonly LanguageContribution[];
42
+ }
43
+
44
+ export interface PluginActivationContext {
45
+ readonly subscriptions: DisposableStore;
46
+ readonly commands: ICommandRegistry;
47
+ readonly configuration: IConfigurationService;
48
+ readonly keybindings: IKeybindingService;
49
+ readonly themes: IThemeService;
50
+ readonly logger: ILogger;
51
+ readonly registerPanel?: (panel: PanelContribution) => IDisposable;
52
+ }
53
+
54
+ export interface CodeLabPluginManifest {
55
+ readonly id: string;
56
+ readonly name: string;
57
+ readonly version: string;
58
+ readonly description?: string;
59
+ readonly activationEvents?: readonly string[];
60
+ readonly contributes?: PluginContributions;
61
+ readonly activate?: (ctx: PluginActivationContext) => void | Promise<void> | IDisposable;
62
+ readonly deactivate?: () => void | Promise<void>;
63
+ }
64
+
65
+ export interface RegisteredPluginInfo {
66
+ readonly manifest: CodeLabPluginManifest;
67
+ readonly active: boolean;
68
+ }
69
+
70
+ export interface IPluginRegistry extends IDisposable {
71
+ readonly panels: ContributionRegistry<string, PanelContribution>;
72
+ readonly languages: ContributionRegistry<string, LanguageContribution>;
73
+ readonly onDidChangePlugins: Event<string>;
74
+ registerPlugin(manifest: CodeLabPluginManifest): IDisposable;
75
+ activatePlugin(id: string): Promise<void>;
76
+ deactivatePlugin(id: string): Promise<void>;
77
+ fireActivationEvent(eventName: string): Promise<void>;
78
+ getPlugins(): RegisteredPluginInfo[];
79
+ resolveLanguageForFile(filePath: string): LanguageContribution | undefined;
80
+ }
81
+
82
+ export const IPluginRegistryId = createServiceId<IPluginRegistry>('code-lab.plugins');
83
+
84
+ interface PluginRecord {
85
+ manifest: CodeLabPluginManifest;
86
+ active: boolean;
87
+ manifestDisposables: DisposableStore;
88
+ runtimeDisposables: DisposableStore;
89
+ }
90
+
91
+ export class PluginRegistry implements IPluginRegistry {
92
+ public readonly panels = new ContributionRegistry<string, PanelContribution>('panels');
93
+ public readonly languages = new ContributionRegistry<string, LanguageContribution>('languages');
94
+ private readonly records = new Map<string, PluginRecord>();
95
+ private readonly changeEmitter = new Emitter<string>({ name: 'plugins.change' });
96
+ private readonly commands: ICommandRegistry;
97
+ private readonly configuration: IConfigurationService;
98
+ private readonly keybindings: IKeybindingService;
99
+ private readonly themes: IThemeService;
100
+ private readonly logger: ILogger;
101
+
102
+ public constructor(deps: {
103
+ commands: ICommandRegistry;
104
+ configuration: IConfigurationService;
105
+ keybindings: IKeybindingService;
106
+ themes: IThemeService;
107
+ logger: ILogger;
108
+ }) {
109
+ this.commands = deps.commands;
110
+ this.configuration = deps.configuration;
111
+ this.keybindings = deps.keybindings;
112
+ this.themes = deps.themes;
113
+ this.logger = deps.logger.child('plugins');
114
+ }
115
+
116
+ public get onDidChangePlugins(): Event<string> {
117
+ return this.changeEmitter.event;
118
+ }
119
+
120
+ public registerPlugin(manifest: CodeLabPluginManifest): IDisposable {
121
+ if (!manifest.id || !manifest.name) {
122
+ throw new CodeLabError('ERR_PLUGIN_INVALID', 'Plugin manifest requires non-empty id and name');
123
+ }
124
+ if (this.records.has(manifest.id)) {
125
+ void this.deactivatePlugin(manifest.id);
126
+ this.records.get(manifest.id)?.manifestDisposables.dispose();
127
+ }
128
+
129
+ const manifestDisposables = new DisposableStore();
130
+ const contributes = manifest.contributes;
131
+
132
+ // Declarative contributions are registered immediately without running plugin code
133
+ if (contributes?.settings) {
134
+ for (const s of contributes.settings) {
135
+ manifestDisposables.add(this.configuration.registerSetting(s));
136
+ }
137
+ }
138
+ if (contributes?.themes) {
139
+ for (const t of contributes.themes) {
140
+ manifestDisposables.add(this.themes.registerTheme(t));
141
+ }
142
+ }
143
+ if (contributes?.commands) {
144
+ for (const cmd of contributes.commands) {
145
+ manifestDisposables.add(
146
+ this.commands.registerCommand({
147
+ ...cmd,
148
+ handler: async (...args: unknown[]) => {
149
+ await this.activatePlugin(manifest.id);
150
+ return cmd.handler(...args);
151
+ }
152
+ })
153
+ );
154
+ }
155
+ }
156
+ if (contributes?.keybindings) {
157
+ for (const kb of contributes.keybindings) {
158
+ manifestDisposables.add(this.keybindings.registerKeybinding({ ...kb, source: 'plugin' }));
159
+ }
160
+ }
161
+ if (contributes?.panels) {
162
+ for (const panel of contributes.panels) {
163
+ manifestDisposables.add(this.panels.register(panel.id, panel));
164
+ }
165
+ }
166
+ if (contributes?.languages) {
167
+ for (const lang of contributes.languages) {
168
+ manifestDisposables.add(this.languages.register(lang.id, lang));
169
+ }
170
+ }
171
+
172
+ const record: PluginRecord = {
173
+ manifest,
174
+ active: false,
175
+ manifestDisposables,
176
+ runtimeDisposables: new DisposableStore()
177
+ };
178
+ this.records.set(manifest.id, record);
179
+ this.changeEmitter.fire(manifest.id);
180
+
181
+ const events = manifest.activationEvents ?? ['*'];
182
+ if (events.includes('*') || events.includes('onStartupFinished')) {
183
+ void this.activatePlugin(manifest.id);
184
+ }
185
+
186
+ return {
187
+ dispose: (): void => {
188
+ if (record.active) {
189
+ record.active = false;
190
+ try {
191
+ record.manifest.deactivate?.();
192
+ } catch (err) {
193
+ this.logger.warn(`Plugin "${manifest.id}" threw during deactivate`, err);
194
+ }
195
+ record.runtimeDisposables.dispose();
196
+ }
197
+ record.manifestDisposables.dispose();
198
+ this.records.delete(manifest.id);
199
+ this.changeEmitter.fire(manifest.id);
200
+ }
201
+ };
202
+ }
203
+
204
+ public async activatePlugin(id: string): Promise<void> {
205
+ const record = this.records.get(id);
206
+ if (!record || record.active) return;
207
+ record.active = true;
208
+ record.runtimeDisposables = new DisposableStore();
209
+ if (record.manifest.activate) {
210
+ try {
211
+ const ret = await record.manifest.activate({
212
+ subscriptions: record.runtimeDisposables,
213
+ commands: this.commands,
214
+ configuration: this.configuration,
215
+ keybindings: this.keybindings,
216
+ themes: this.themes,
217
+ logger: this.logger.child(id),
218
+ registerPanel: (panel: PanelContribution): IDisposable => {
219
+ const d = this.panels.register(panel.id, panel);
220
+ record.runtimeDisposables.add(d);
221
+ this.changeEmitter.fire(id);
222
+ return d;
223
+ }
224
+ });
225
+ if (ret && typeof ret.dispose === 'function') {
226
+ record.runtimeDisposables.add(ret);
227
+ }
228
+ } catch (err) {
229
+ record.active = false;
230
+ this.logger.error(`Plugin "${id}" failed to activate`, err);
231
+ throw err;
232
+ }
233
+ }
234
+ this.changeEmitter.fire(id);
235
+ }
236
+
237
+ public async deactivatePlugin(id: string): Promise<void> {
238
+ const record = this.records.get(id);
239
+ if (!record || !record.active) return;
240
+ record.active = false;
241
+ try {
242
+ await record.manifest.deactivate?.();
243
+ } catch (err) {
244
+ this.logger.warn(`Plugin "${id}" threw during deactivate`, err);
245
+ }
246
+ record.runtimeDisposables.dispose();
247
+ this.changeEmitter.fire(id);
248
+ }
249
+
250
+ public async fireActivationEvent(eventName: string): Promise<void> {
251
+ for (const [id, rec] of this.records.entries()) {
252
+ if (rec.active) continue;
253
+ const events = rec.manifest.activationEvents ?? [];
254
+ if (events.includes(eventName) || events.includes('*')) {
255
+ await this.activatePlugin(id);
256
+ }
257
+ }
258
+ }
259
+
260
+ public getPlugins(): RegisteredPluginInfo[] {
261
+ return Array.from(this.records.values()).map((r) => ({
262
+ manifest: r.manifest,
263
+ active: r.active
264
+ }));
265
+ }
266
+
267
+ public resolveLanguageForFile(filePath: string): LanguageContribution | undefined {
268
+ const dotIdx = filePath.lastIndexOf('.');
269
+ const ext = dotIdx !== -1 ? filePath.slice(dotIdx).toLowerCase() : '';
270
+ if (!ext) return undefined;
271
+ for (const lang of this.languages.values()) {
272
+ if (lang.extensions.some((e) => e.toLowerCase() === ext)) {
273
+ return lang;
274
+ }
275
+ }
276
+ return undefined;
277
+ }
278
+
279
+ public dispose(): void {
280
+ for (const rec of this.records.values()) {
281
+ rec.runtimeDisposables.dispose();
282
+ rec.manifestDisposables.dispose();
283
+ }
284
+ this.records.clear();
285
+ this.panels.dispose();
286
+ this.languages.dispose();
287
+ this.changeEmitter.dispose();
288
+ }
289
+ }