@innovatorved/code-lab 0.4.0 → 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 (64) hide show
  1. package/ARCHITECTURE.md +2 -2
  2. package/CHANGELOG.md +21 -0
  3. package/README.md +4 -28
  4. package/dist/code-lab-sql.esm.js +1 -1
  5. package/dist/code-lab-sql.umd.js +2 -2
  6. package/dist/code-lab.css +1553 -98
  7. package/dist/code-lab.d.ts +1 -1
  8. package/dist/code-lab.esm.js +11883 -1619
  9. package/dist/code-lab.js +11882 -1618
  10. package/dist/code-lab.umd.js +11882 -1618
  11. package/dist/diagnostics.d.ts +3 -0
  12. package/dist/extensions/cpp.esm.js +27 -29
  13. package/dist/extensions/cpp.js +27 -29
  14. package/dist/extensions/python.esm.js +27 -28
  15. package/dist/extensions/python.js +27 -28
  16. package/dist/index.d.ts +1 -1
  17. package/dist/packages/settings/src/configuration-service.d.ts +7 -0
  18. package/dist/packages/settings/src/index.d.ts +1 -1
  19. package/dist/packages/ui/src/index.d.ts +2 -2
  20. package/dist/packages/ui/src/plugin-registry.d.ts +1 -0
  21. package/dist/packages/ui/src/settings-dialog.d.ts +31 -3
  22. package/dist/packages/ui/src/themes.d.ts +5 -0
  23. package/dist/preview-sw.js +1 -1
  24. package/dist/runtime.esm.js +1 -1
  25. package/dist/runtime.js +1 -1
  26. package/dist/schemas.d.ts +1 -1
  27. package/dist/scm.d.ts +92 -11
  28. package/dist/shell.esm.js +937 -113
  29. package/dist/shell.js +937 -113
  30. package/dist/storage.d.ts +47 -0
  31. package/dist/terminal.esm.js +1 -1
  32. package/dist/terminal.js +1 -1
  33. package/dist/workbench/index.d.ts +1 -1
  34. package/dist/workbench/styles.d.ts +1 -1
  35. package/package.json +2 -2
  36. package/packages/commands/package.json +1 -1
  37. package/packages/core/package.json +1 -1
  38. package/packages/editor/package.json +1 -1
  39. package/packages/fs/package.json +1 -1
  40. package/packages/preview/package.json +1 -1
  41. package/packages/runtime/package.json +1 -1
  42. package/packages/settings/package.json +1 -1
  43. package/packages/settings/src/builtin-schemas.ts +17 -6
  44. package/packages/settings/src/configuration-service.ts +72 -6
  45. package/packages/settings/src/index.ts +1 -0
  46. package/packages/sql/package.json +1 -1
  47. package/packages/terminal/package.json +1 -1
  48. package/packages/ui/package.json +1 -1
  49. package/packages/ui/src/index.ts +4 -0
  50. package/packages/ui/src/plugin-registry.ts +17 -2
  51. package/packages/ui/src/settings-dialog.ts +374 -92
  52. package/packages/ui/src/themes.ts +105 -12
  53. package/src/code-lab.css +1553 -98
  54. package/src/diagnostics.ts +139 -7
  55. package/src/extensions/cpp.ts +33 -33
  56. package/src/extensions/python.ts +33 -32
  57. package/src/index.ts +1 -1
  58. package/src/schemas.ts +1 -1
  59. package/src/scm.ts +781 -58
  60. package/src/shell.ts +936 -112
  61. package/src/storage.ts +336 -3
  62. package/src/workbench/icons.ts +8 -1
  63. package/src/workbench/styles.ts +25 -19
  64. package/src/workbench.ts +12010 -3814
@@ -28,6 +28,24 @@ export interface DiagnosticItem {
28
28
 
29
29
  export type DiagnosticListener = (items: DiagnosticItem[]) => void;
30
30
 
31
+ export function normalizeDiagnosticFilePath(rawFile: string): string {
32
+ let p = String(rawFile || '').trim().replace(/\\/g, '/');
33
+ while (p.startsWith('./')) {
34
+ p = p.slice(2);
35
+ }
36
+ if (!p || p === '/workspace' || p === '/workspace/') return '';
37
+ if (p.startsWith('/workspace/')) {
38
+ p = p.slice('/workspace/'.length);
39
+ }
40
+ while (p.startsWith('./')) {
41
+ p = p.slice(2);
42
+ }
43
+ if (p.startsWith('/')) {
44
+ p = p.replace(/^\/+/, '');
45
+ }
46
+ return p;
47
+ }
48
+
31
49
  export class DiagnosticsStore {
32
50
  private readonly items: Map<string, DiagnosticItem> = new Map();
33
51
  private readonly listeners: Set<DiagnosticListener> = new Set();
@@ -36,13 +54,28 @@ export class DiagnosticsStore {
36
54
 
37
55
  private normalizeItem(item: DiagnosticItem): DiagnosticItem | null {
38
56
  if (!item || typeof item.id !== 'string' || !item.id) return null;
57
+ const col = typeof item.col === 'number' && Number.isFinite(item.col) && item.col > 0
58
+ ? Math.floor(item.col)
59
+ : (typeof item.column === 'number' && Number.isFinite(item.column) && item.column > 0
60
+ ? Math.floor(item.column)
61
+ : 1);
62
+ const endLine = typeof item.endLine === 'number' && Number.isFinite(item.endLine) && item.endLine > 0
63
+ ? Math.floor(item.endLine)
64
+ : undefined;
65
+ const endCol = typeof item.endCol === 'number' && Number.isFinite(item.endCol) && item.endCol > 0
66
+ ? Math.floor(item.endCol)
67
+ : (typeof item.endColumn === 'number' && Number.isFinite(item.endColumn) && item.endColumn > 0
68
+ ? Math.floor(item.endColumn)
69
+ : undefined);
39
70
  return {
40
71
  ...item,
41
- file: String(item.file || ''),
42
- line: typeof item.line === 'number' && item.line > 0 ? Math.floor(item.line) : 1,
43
- col: typeof item.col === 'number' && item.col > 0
44
- ? Math.floor(item.col)
45
- : (typeof item.column === 'number' && item.column > 0 ? Math.floor(item.column) : 1),
72
+ file: normalizeDiagnosticFilePath(item.file || ''),
73
+ line: typeof item.line === 'number' && Number.isFinite(item.line) && item.line > 0
74
+ ? Math.floor(item.line)
75
+ : 1,
76
+ col,
77
+ ...(endLine !== undefined ? { endLine } : {}),
78
+ ...(endCol !== undefined ? { endCol } : {}),
46
79
  message: String(item.message || ''),
47
80
  severity: item.severity || 'error'
48
81
  };
@@ -55,6 +88,103 @@ export class DiagnosticsStore {
55
88
  this.notify();
56
89
  }
57
90
 
91
+ public setFileDiagnostics(
92
+ file: string,
93
+ sourceOrDiags: string | ReadonlyArray<Partial<DiagnosticItem>>,
94
+ diagsOrSource?: ReadonlyArray<Partial<DiagnosticItem>> | string
95
+ ): DiagnosticItem[] {
96
+ const normalizedFile = normalizeDiagnosticFilePath(file);
97
+ let resolvedSource: string;
98
+ let rawDiags: ReadonlyArray<Partial<DiagnosticItem>>;
99
+
100
+ if (typeof sourceOrDiags === 'string') {
101
+ resolvedSource = sourceOrDiags || 'diagnostics';
102
+ rawDiags = Array.isArray(diagsOrSource) ? diagsOrSource : [];
103
+ } else if (Array.isArray(sourceOrDiags)) {
104
+ rawDiags = sourceOrDiags;
105
+ resolvedSource =
106
+ typeof diagsOrSource === 'string' && diagsOrSource ? diagsOrSource : 'diagnostics';
107
+ } else {
108
+ resolvedSource =
109
+ typeof diagsOrSource === 'string' && diagsOrSource ? diagsOrSource : 'diagnostics';
110
+ rawDiags = [];
111
+ }
112
+
113
+ let changed = false;
114
+ for (const [existingId, existingItem] of this.items.entries()) {
115
+ if (existingItem.file === normalizedFile && existingItem.source === resolvedSource) {
116
+ this.items.delete(existingId);
117
+ changed = true;
118
+ }
119
+ }
120
+
121
+ const inserted: DiagnosticItem[] = [];
122
+ for (let idx = 0; idx < rawDiags.length; idx++) {
123
+ const d = rawDiags[idx];
124
+ if (!d || typeof d !== 'object') continue;
125
+
126
+ const line =
127
+ typeof d.line === 'number' && Number.isFinite(d.line) && d.line > 0
128
+ ? Math.floor(d.line)
129
+ : 1;
130
+ const col =
131
+ typeof d.col === 'number' && Number.isFinite(d.col) && d.col > 0
132
+ ? Math.floor(d.col)
133
+ : (typeof d.column === 'number' && Number.isFinite(d.column) && d.column > 0
134
+ ? Math.floor(d.column)
135
+ : 1);
136
+ const endLine =
137
+ typeof d.endLine === 'number' && Number.isFinite(d.endLine) && d.endLine > 0
138
+ ? Math.floor(d.endLine)
139
+ : undefined;
140
+ const rawEndCol =
141
+ typeof d.endCol === 'number' && Number.isFinite(d.endCol) && d.endCol > 0
142
+ ? Math.floor(d.endCol)
143
+ : (typeof d.endColumn === 'number' && Number.isFinite(d.endColumn) && d.endColumn > 0
144
+ ? Math.floor(d.endColumn)
145
+ : undefined);
146
+ const severity: DiagnosticSeverity =
147
+ d.severity === 'error' ||
148
+ d.severity === 'warning' ||
149
+ d.severity === 'info' ||
150
+ d.severity === 'hint'
151
+ ? d.severity
152
+ : 'error';
153
+ const message = String(d.message ?? '');
154
+ const candidateId = typeof d.id === 'string' && d.id.trim() ? d.id.trim() : '';
155
+ const id =
156
+ candidateId && !this.items.has(candidateId)
157
+ ? candidateId
158
+ : `${resolvedSource}:${normalizedFile}:${candidateId || `${line}:${col}`}:${idx}`;
159
+
160
+ const normalized: DiagnosticItem = {
161
+ id,
162
+ file: normalizedFile,
163
+ source: resolvedSource,
164
+ severity,
165
+ message,
166
+ line,
167
+ col,
168
+ ...(d.column !== undefined ? { column: col } : {}),
169
+ ...(endLine !== undefined ? { endLine } : {}),
170
+ ...(rawEndCol !== undefined ? { endCol: rawEndCol } : {}),
171
+ ...(d.endColumn !== undefined && rawEndCol !== undefined ? { endColumn: rawEndCol } : {}),
172
+ ...(d.code !== undefined ? { code: d.code } : {}),
173
+ ...(Array.isArray(d.tags) ? { tags: [...d.tags] } : {})
174
+ };
175
+
176
+ this.items.set(id, normalized);
177
+ inserted.push(normalized);
178
+ changed = true;
179
+ }
180
+
181
+ if (changed) {
182
+ this.notify();
183
+ }
184
+
185
+ return inserted;
186
+ }
187
+
58
188
  public setMany(items: ReadonlyArray<DiagnosticItem>, clearSource?: string): void {
59
189
  this.batch(() => {
60
190
  if (clearSource !== undefined) {
@@ -112,9 +242,10 @@ export class DiagnosticsStore {
112
242
  }
113
243
 
114
244
  public getByFile(file: string): DiagnosticItem[] {
245
+ const normalizedTarget = normalizeDiagnosticFilePath(file);
115
246
  const out: DiagnosticItem[] = [];
116
247
  for (const item of this.items.values()) {
117
- if (item.file === file) {
248
+ if (item.file === normalizedTarget || item.file === file) {
118
249
  out.push(item);
119
250
  }
120
251
  }
@@ -151,5 +282,6 @@ export function createDiagnosticsStore(): DiagnosticsStore {
151
282
 
152
283
  export default {
153
284
  DiagnosticsStore,
154
- createDiagnosticsStore
285
+ createDiagnosticsStore,
286
+ normalizeDiagnosticFilePath
155
287
  };
@@ -2036,39 +2036,39 @@ export function installCppExtension(workbench: any, options: ExtendedCppExtensio
2036
2036
 
2037
2037
  workbench.hasMultipleLanguages = workbench.enabledLanguages.size > 1;
2038
2038
 
2039
- // Wire up debounced static linter if workbench has diagnostics store
2040
- if (workbench._diagnosticsStore) {
2041
- let lintTimer: any = null;
2042
- const originalOnCodeChange = workbench.options?.onCodeChange;
2043
- workbench._cppLintHandler = (file: string, code: string) => {
2044
- if (!file || !/\.(?:cpp|cc|cxx|hpp|h)$/.test(file)) return;
2045
- if (lintTimer) clearTimeout(lintTimer);
2046
- lintTimer = setTimeout(() => {
2047
- const diags = analyzeCppSource(code, file, workbench.vfs);
2048
- workbench._diagnosticsStore.clear('cpp-linter');
2049
- for (const d of diags) {
2050
- workbench._diagnosticsStore.add(d);
2051
- }
2052
- if (typeof window !== 'undefined' && (window as any).monaco) {
2053
- const model = (workbench.models && typeof workbench.models.get === 'function' && workbench.models.get(file))
2054
- || (workbench.activeFile === file && workbench.editor ? workbench.editor.getModel() : null);
2055
- if (model) {
2056
- const markers = diags.map((d) => ({
2057
- startLineNumber: d.line,
2058
- startColumn: d.col || 1,
2059
- endLineNumber: d.line,
2060
- endColumn: (d.col || 1) + 20,
2061
- message: d.message,
2062
- severity: d.severity === 'error'
2063
- ? (window as any).monaco.MarkerSeverity.Error
2064
- : (window as any).monaco.MarkerSeverity.Warning
2065
- }));
2066
- (window as any).monaco.editor.setModelMarkers(model, 'cpp-linter', markers);
2067
- }
2068
- }
2069
- }, 180);
2070
- };
2071
- }
2039
+ // Synchronous static C++ linter (resolves _diagnosticsStore dynamically)
2040
+ workbench._cppLintHandler = (file: string, code: string) => {
2041
+ if (!file || !/\.(?:cpp|cc|cxx|hpp|h)$/i.test(file)) return;
2042
+ const diags = analyzeCppSource(String(code ?? ''), file, workbench ? workbench.vfs : undefined);
2043
+ const store = workbench ? workbench._diagnosticsStore : null;
2044
+ if (store && typeof store.setFileDiagnostics === 'function') {
2045
+ store.setFileDiagnostics(file, 'cpp-linter', diags);
2046
+ } else if (store && typeof store.clear === 'function' && typeof store.add === 'function') {
2047
+ store.clear('cpp-linter');
2048
+ for (const d of diags) {
2049
+ store.add(d);
2050
+ }
2051
+ }
2052
+ if (typeof window !== 'undefined' && (window as any).monaco) {
2053
+ const model =
2054
+ (workbench.models && typeof workbench.models.get === 'function' && workbench.models.get(file)) ||
2055
+ (workbench.activeFile === file && workbench.editor ? workbench.editor.getModel() : null);
2056
+ if (model) {
2057
+ const markers = diags.map((d) => ({
2058
+ startLineNumber: d.line,
2059
+ startColumn: d.col || 1,
2060
+ endLineNumber: d.endLine || d.line,
2061
+ endColumn: d.endCol || (d.col || 1) + 20,
2062
+ message: d.message,
2063
+ severity:
2064
+ d.severity === 'error'
2065
+ ? (window as any).monaco.MarkerSeverity.Error
2066
+ : (window as any).monaco.MarkerSeverity.Warning
2067
+ }));
2068
+ (window as any).monaco.editor.setModelMarkers(model, 'cpp-linter', markers);
2069
+ }
2070
+ }
2071
+ };
2072
2072
 
2073
2073
  if (options.preload) {
2074
2074
  toolchain.ensureLoaded().catch((err) => {
@@ -1348,38 +1348,39 @@ function installPythonExtension(workbench: any, options: ExtendedPythonExtension
1348
1348
 
1349
1349
  workbench.hasMultipleLanguages = workbench.enabledLanguages.size > 1;
1350
1350
 
1351
- // Debounced static syntax & traceback linter
1352
- if (workbench._diagnosticsStore) {
1353
- let pyLintTimer: any = null;
1354
- workbench._pyLintHandler = (file: string, code: string) => {
1355
- if (!file || !file.endsWith('.py')) return;
1356
- if (pyLintTimer) clearTimeout(pyLintTimer);
1357
- pyLintTimer = setTimeout(() => {
1358
- const diags = analyzePythonSource(code, file);
1359
- workbench._diagnosticsStore.clear('python-linter');
1360
- for (const d of diags) {
1361
- workbench._diagnosticsStore.add(d);
1362
- }
1363
- if (typeof window !== 'undefined' && (window as any).monaco) {
1364
- const model = (workbench.models && typeof workbench.models.get === 'function' && workbench.models.get(file))
1365
- || (workbench.activeFile === file && workbench.editor ? workbench.editor.getModel() : null);
1366
- if (model) {
1367
- const markers = diags.map((d) => ({
1368
- startLineNumber: d.line,
1369
- startColumn: d.col || 1,
1370
- endLineNumber: d.line,
1371
- endColumn: (d.col || 1) + 20,
1372
- message: d.message,
1373
- severity: d.severity === 'error'
1374
- ? (window as any).monaco.MarkerSeverity.Error
1375
- : (window as any).monaco.MarkerSeverity.Warning
1376
- }));
1377
- (window as any).monaco.editor.setModelMarkers(model, 'python-linter', markers);
1378
- }
1379
- }
1380
- }, 180);
1381
- };
1382
- }
1351
+ // Synchronous static syntax & traceback linter (resolves _diagnosticsStore dynamically)
1352
+ workbench._pyLintHandler = (file: string, code: string) => {
1353
+ if (!file || !/\.py$/i.test(file)) return;
1354
+ const diags = analyzePythonSource(String(code ?? ''), file);
1355
+ const store = workbench ? workbench._diagnosticsStore : null;
1356
+ if (store && typeof store.setFileDiagnostics === 'function') {
1357
+ store.setFileDiagnostics(file, 'python-linter', diags);
1358
+ } else if (store && typeof store.clear === 'function' && typeof store.add === 'function') {
1359
+ store.clear('python-linter');
1360
+ for (const d of diags) {
1361
+ store.add(d);
1362
+ }
1363
+ }
1364
+ if (typeof window !== 'undefined' && (window as any).monaco) {
1365
+ const model =
1366
+ (workbench.models && typeof workbench.models.get === 'function' && workbench.models.get(file)) ||
1367
+ (workbench.activeFile === file && workbench.editor ? workbench.editor.getModel() : null);
1368
+ if (model) {
1369
+ const markers = diags.map((d) => ({
1370
+ startLineNumber: d.line,
1371
+ startColumn: d.col || 1,
1372
+ endLineNumber: d.endLine || d.line,
1373
+ endColumn: d.endCol || (d.col || 1) + 20,
1374
+ message: d.message,
1375
+ severity:
1376
+ d.severity === 'error'
1377
+ ? (window as any).monaco.MarkerSeverity.Error
1378
+ : (window as any).monaco.MarkerSeverity.Warning
1379
+ }));
1380
+ (window as any).monaco.editor.setModelMarkers(model, 'python-linter', markers);
1381
+ }
1382
+ }
1383
+ };
1383
1384
 
1384
1385
  if (options.preload) {
1385
1386
  toolchain.ensureLoaded().catch((err) => {
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @innovatorved/code-lab v0.4.0
2
+ * @innovatorved/code-lab v0.5.0
3
3
  * Browser-native IDE, POSIX Shell, Web Worker Node.js/Bun Runtime, WASI C++20 Toolchain, Python 3.12 WebAssembly, and Git Engine.
4
4
  */
5
5
 
package/src/schemas.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { z } from 'zod';
2
2
 
3
3
  /**
4
- * Zod Schemas and Inferred TypeScript Types for code-lab v0.4.0
4
+ * Zod Schemas and Inferred TypeScript Types for code-lab v0.5.0
5
5
  */
6
6
 
7
7
  // ── 1. Guided Step ──────────────────────────────────────────────────────────