@innovatorved/code-lab 0.4.0 → 0.6.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 (82) hide show
  1. package/ARCHITECTURE.md +4 -4
  2. package/CHANGELOG.md +36 -0
  3. package/README.md +6 -30
  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 +32 -5818
  7. package/dist/code-lab.d.ts +1 -1
  8. package/dist/code-lab.esm.js +4655 -64400
  9. package/dist/code-lab.js +4540 -64286
  10. package/dist/code-lab.umd.js +4540 -64286
  11. package/dist/diagnostics.d.ts +3 -0
  12. package/dist/extensions/cpp.d.ts +2 -2
  13. package/dist/extensions/cpp.esm.js +1804 -14725
  14. package/dist/extensions/cpp.js +1804 -14725
  15. package/dist/extensions/guided-lab.esm.js +2938 -16127
  16. package/dist/extensions/guided-lab.js +2938 -16127
  17. package/dist/extensions/python.d.ts +2 -2
  18. package/dist/extensions/python.esm.js +1765 -14698
  19. package/dist/extensions/python.js +1765 -14698
  20. package/dist/index.d.ts +1 -1
  21. package/dist/packages/settings/src/configuration-service.d.ts +7 -0
  22. package/dist/packages/settings/src/index.d.ts +1 -1
  23. package/dist/packages/ui/src/index.d.ts +2 -2
  24. package/dist/packages/ui/src/plugin-registry.d.ts +1 -0
  25. package/dist/packages/ui/src/settings-dialog.d.ts +31 -3
  26. package/dist/packages/ui/src/themes.d.ts +5 -0
  27. package/dist/preview-sw.js +4 -188
  28. package/dist/runtime.esm.js +109 -10284
  29. package/dist/runtime.js +107 -10284
  30. package/dist/schemas.d.ts +2 -2
  31. package/dist/schemas.esm.js +2938 -16127
  32. package/dist/schemas.js +2941 -16130
  33. package/dist/scm.d.ts +296 -14
  34. package/dist/shell.esm.js +811 -9178
  35. package/dist/shell.js +811 -9178
  36. package/dist/storage.d.ts +56 -0
  37. package/dist/terminal.esm.js +20 -1347
  38. package/dist/terminal.js +20 -1347
  39. package/dist/workbench/command-palette.d.ts +16 -1
  40. package/dist/workbench/diff-editor.d.ts +27 -1
  41. package/dist/workbench/icons.d.ts +6 -2
  42. package/dist/workbench/index.d.ts +33 -1
  43. package/dist/workbench/intellisense.d.ts +194 -0
  44. package/dist/workbench/styles.d.ts +1 -1
  45. package/dist/workbench/xterm-adapter.d.ts +122 -0
  46. package/package.json +8 -2
  47. package/packages/commands/package.json +1 -1
  48. package/packages/core/package.json +1 -1
  49. package/packages/editor/package.json +1 -1
  50. package/packages/fs/package.json +1 -1
  51. package/packages/preview/package.json +1 -1
  52. package/packages/runtime/package.json +1 -1
  53. package/packages/settings/package.json +1 -1
  54. package/packages/settings/src/builtin-schemas.ts +17 -6
  55. package/packages/settings/src/configuration-service.ts +72 -6
  56. package/packages/settings/src/index.ts +1 -0
  57. package/packages/sql/package.json +1 -1
  58. package/packages/terminal/package.json +1 -1
  59. package/packages/ui/package.json +1 -1
  60. package/packages/ui/src/index.ts +4 -0
  61. package/packages/ui/src/plugin-registry.ts +17 -2
  62. package/packages/ui/src/settings-dialog.ts +393 -99
  63. package/packages/ui/src/themes.ts +183 -24
  64. package/src/code-lab.css +2763 -444
  65. package/src/diagnostics.ts +139 -7
  66. package/src/extensions/cpp.ts +337 -71
  67. package/src/extensions/python.ts +375 -75
  68. package/src/index.ts +1 -1
  69. package/src/runtime.ts +272 -43
  70. package/src/schemas.ts +2 -2
  71. package/src/scm.ts +2172 -74
  72. package/src/shell.ts +1999 -193
  73. package/src/storage.ts +401 -5
  74. package/src/terminal.ts +148 -12
  75. package/src/workbench/command-palette.ts +289 -48
  76. package/src/workbench/diff-editor.ts +240 -78
  77. package/src/workbench/icons.ts +250 -46
  78. package/src/workbench/index.ts +7 -1
  79. package/src/workbench/intellisense.ts +1859 -0
  80. package/src/workbench/styles.ts +25 -19
  81. package/src/workbench/xterm-adapter.ts +1566 -0
  82. package/src/workbench.ts +13446 -3881
@@ -1,23 +1,113 @@
1
1
  /**
2
- * @innovatorved/code-lab — Fuzzy-Searchable Command Palette (Cmd+Shift+P / Cmd+K)
2
+ * @innovatorved/code-lab — VS Code Quick Open & Fuzzy Command Palette (Cmd+P / Cmd+Shift+P / F1)
3
3
  */
4
4
 
5
- import { CL_ICONS } from './icons';
6
-
7
5
  export interface CommandPaletteItem {
8
6
  id: string;
9
7
  label: string;
8
+ category?: string;
9
+ detail?: string;
10
10
  shortcut?: string;
11
11
  action: () => void;
12
12
  }
13
13
 
14
+ export interface FuzzyMatchResult {
15
+ score: number;
16
+ indices: number[];
17
+ }
18
+
19
+ function escapeHtml(str: unknown): string {
20
+ return String(str ?? '')
21
+ .replace(/&/g, '&')
22
+ .replace(/</g, '&lt;')
23
+ .replace(/>/g, '&gt;')
24
+ .replace(/"/g, '&quot;')
25
+ .replace(/'/g, '&#39;');
26
+ }
27
+
28
+ /**
29
+ * VS Code-style subsequence fuzzy matcher with bonuses for consecutive matches,
30
+ * word-boundary / camelCase transitions, and prefix alignment.
31
+ */
32
+ export function fuzzyScoreText(query: string, candidate: string): FuzzyMatchResult | null {
33
+ const q = String(query || '').trim();
34
+ const text = String(candidate || '');
35
+ if (!q) return { score: 1, indices: [] };
36
+ if (!text) return null;
37
+
38
+ const qLower = q.toLowerCase();
39
+ const tLower = text.toLowerCase();
40
+
41
+ const indices: number[] = [];
42
+ let qi = 0;
43
+ let score = 0;
44
+ let prevMatchIdx = -2;
45
+
46
+ for (let ti = 0; ti < text.length && qi < qLower.length; ti++) {
47
+ if (tLower[ti] === qLower[qi]) {
48
+ indices.push(ti);
49
+ score += 10;
50
+
51
+ // Consecutive match bonus
52
+ if (ti === prevMatchIdx + 1) {
53
+ score += 14;
54
+ }
55
+ // Prefix match bonus
56
+ if (ti === 0) {
57
+ score += 18;
58
+ } else {
59
+ const prev = text[ti - 1];
60
+ const curr = text[ti];
61
+ // Path separator / word boundary / camelCase transition bonus
62
+ if (prev === '/' || prev === '-' || prev === '_' || prev === ' ' || prev === ':' || prev === '.') {
63
+ score += 12;
64
+ } else if (prev >= 'a' && prev <= 'z' && curr >= 'A' && curr <= 'Z') {
65
+ score += 10;
66
+ }
67
+ }
68
+
69
+ prevMatchIdx = ti;
70
+ qi++;
71
+ }
72
+ }
73
+
74
+ if (qi < qLower.length) return null;
75
+
76
+ // Slightly prefer shorter, tighter matches
77
+ score -= Math.min(20, Math.floor((text.length - q.length) * 0.25));
78
+ return { score, indices };
79
+ }
80
+
81
+ /**
82
+ * Renders HTML with `<mark class="codelab-palette-hl">` around matched subsequence characters.
83
+ */
84
+ export function renderHighlightedText(text: string, indices: number[]): string {
85
+ if (!indices || indices.length === 0) return escapeHtml(text);
86
+ const matchSet = new Set(indices);
87
+ let html = '';
88
+ let inMark = false;
89
+ for (let i = 0; i < text.length; i++) {
90
+ const isHit = matchSet.has(i);
91
+ if (isHit && !inMark) {
92
+ html += '<mark class="codelab-palette-hl">';
93
+ inMark = true;
94
+ } else if (!isHit && inMark) {
95
+ html += '</mark>';
96
+ inMark = false;
97
+ }
98
+ html += escapeHtml(text[i]);
99
+ }
100
+ if (inMark) html += '</mark>';
101
+ return html;
102
+ }
103
+
14
104
  export function getStandardWorkbenchCommands(workbench: any): CommandPaletteItem[] {
15
105
  const isGuided = Boolean(workbench.hasGuidedLab && workbench.mode === 'guided');
16
106
 
17
- return [
107
+ const commands: CommandPaletteItem[] = [
18
108
  {
19
109
  id: 'run-code',
20
- label: isGuided ? 'CodeLab: Verify Current Guided Step' : 'CodeLab: Run Active Code / Demo',
110
+ label: isGuided ? 'CodeLab: Verify Current Guided Step' : 'Run: Run Active File',
21
111
  shortcut: '⌘↵',
22
112
  action: () => {
23
113
  if (isGuided) workbench.verifyCurrentStep();
@@ -32,49 +122,83 @@ export function getStandardWorkbenchCommands(workbench: any): CommandPaletteItem
32
122
  },
33
123
  {
34
124
  id: 'run-tests',
35
- label: 'CodeLab: Run Unit Tests',
125
+ label: 'Test: Run Unit Tests',
36
126
  shortcut: '⌘↵',
37
127
  action: () => workbench.runTests()
38
128
  },
39
129
  {
40
130
  id: 'format-document',
41
- label: 'Format: Format Active Document',
131
+ label: 'Format Document',
132
+ category: 'Editor',
42
133
  shortcut: '⇧⌥F',
43
134
  action: () => workbench.formatActiveDocument()
44
135
  },
45
136
  {
46
- id: 'share-snapshot',
47
- label: 'Share: Copy URL Snapshot to Clipboard (#codelab=...)',
48
- action: () => workbench.shareSnapshot()
137
+ id: 'view-toggle-panel',
138
+ label: 'View: Toggle Panel',
139
+ shortcut: '⌘J',
140
+ action: () => {
141
+ if (typeof workbench.togglePanel === 'function') workbench.togglePanel();
142
+ else if (typeof workbench.setPanelVisible === 'function') workbench.setPanelVisible(Boolean(workbench._panelCollapsed));
143
+ }
49
144
  },
50
145
  {
51
- id: 'compare-solution',
52
- label: 'Diff: Compare Active File with Reference Solution',
53
- action: () => workbench.showDiffModal(workbench.activeFile || workbench._pickDefaultFile(), 'solution')
146
+ id: 'view-toggle-terminal',
147
+ label: 'View: Toggle Terminal',
148
+ shortcut: '⌃`',
149
+ action: () => {
150
+ if (typeof workbench.toggleTerminalPanel === 'function') workbench.toggleTerminalPanel();
151
+ else if (typeof workbench.togglePanel === 'function') workbench.togglePanel('terminal');
152
+ }
54
153
  },
55
154
  {
56
- id: 'compare-starter',
57
- label: 'Diff: Compare Active File with Starter Template',
58
- action: () => workbench.showDiffModal(workbench.activeFile || workbench._pickDefaultFile(), 'starter')
155
+ id: 'view-toggle-sidebar',
156
+ label: 'View: Toggle Primary Side Bar',
157
+ shortcut: '⌘B',
158
+ action: () => {
159
+ if (typeof workbench.togglePrimarySidebar === 'function') workbench.togglePrimarySidebar();
160
+ }
59
161
  },
60
162
  {
61
- id: 'open-stdin',
62
- label: 'View: Open Stdin / Custom Input Panel',
163
+ id: 'terminal-new',
164
+ label: 'Terminal: Create New Terminal',
165
+ shortcut: '⌃⇧`',
63
166
  action: () => {
64
- workbench.drawerTab = 'stdin';
65
- if (typeof workbench._renderDrawerBody === 'function') workbench._renderDrawerBody();
66
- const drawer = workbench.container?.querySelector('#cl-drawer');
67
- if (drawer) drawer.classList.remove('is-minimized');
167
+ if (typeof workbench.createNewTerminalSession === 'function') workbench.createNewTerminalSession();
168
+ }
169
+ },
170
+ {
171
+ id: 'terminal-split',
172
+ label: 'Terminal: Split Terminal',
173
+ shortcut: '⌘\\',
174
+ action: () => {
175
+ if (typeof workbench.splitTerminalSession === 'function') workbench.splitTerminalSession();
176
+ }
177
+ },
178
+ {
179
+ id: 'terminal-clear',
180
+ label: 'Terminal: Clear',
181
+ action: () => {
182
+ if (typeof workbench.clearTerminal === 'function') workbench.clearTerminal();
68
183
  }
69
184
  },
70
185
  {
71
186
  id: 'open-problems',
72
- label: 'View: Show Problems & Diagnostics',
187
+ label: 'View: Focus Problems (Errors, Warnings)',
188
+ shortcut: '⇧⌘M',
73
189
  action: () => {
74
190
  workbench.drawerTab = 'problems';
191
+ if (typeof workbench.setPanelVisible === 'function') workbench.setPanelVisible(true);
192
+ if (typeof workbench._renderDrawerBody === 'function') workbench._renderDrawerBody();
193
+ }
194
+ },
195
+ {
196
+ id: 'open-stdin',
197
+ label: 'View: Open Output / Stdin Panel',
198
+ action: () => {
199
+ workbench.drawerTab = 'stdin';
200
+ if (typeof workbench.setPanelVisible === 'function') workbench.setPanelVisible(true);
75
201
  if (typeof workbench._renderDrawerBody === 'function') workbench._renderDrawerBody();
76
- const drawer = workbench.container?.querySelector('#cl-drawer');
77
- if (drawer) drawer.classList.remove('is-minimized');
78
202
  }
79
203
  },
80
204
  {
@@ -91,50 +215,167 @@ export function getStandardWorkbenchCommands(workbench: any): CommandPaletteItem
91
215
  id: 'rename-active',
92
216
  label: 'File: Rename Active File...',
93
217
  shortcut: 'F2',
94
- action: () => { if (workbench.activeFile) workbench.startInlineRename('file', workbench.activeFile); }
218
+ action: () => {
219
+ if (workbench.activeFile && workbench.activeFile !== '__welcome__') {
220
+ workbench.startInlineRename('file', workbench.activeFile);
221
+ }
222
+ }
95
223
  },
96
224
  {
97
225
  id: 'delete-active',
98
226
  label: 'File: Delete Active File',
99
- action: () => { if (workbench.activeFile) workbench.deleteFile(workbench.activeFile); }
100
- },
101
- {
102
- id: 'export-workspace-zip',
103
- label: 'Workspace: Export Project as ZIP Archive',
104
- action: () => workbench.exportProjectZip({ download: true })
227
+ action: () => {
228
+ if (workbench.activeFile && workbench.activeFile !== '__welcome__') {
229
+ workbench.deleteFile(workbench.activeFile);
230
+ }
231
+ }
105
232
  },
106
233
  {
107
- id: 'export-workspace-json',
108
- label: 'Workspace: Export Workspace as JSON',
109
- action: () => workbench.exportWorkspace({ download: true })
234
+ id: 'open-welcome',
235
+ label: 'Help: Welcome',
236
+ action: () => {
237
+ if (typeof workbench.openWelcomeTab === 'function') workbench.openWelcomeTab();
238
+ }
110
239
  },
111
240
  {
112
- id: 'switch-lang',
113
- label: 'Language: Cycle Active Language (JS / TS / C++ / PY)',
241
+ id: 'open-settings',
242
+ label: 'Preferences: Open Settings (UI)',
243
+ shortcut: '⌘,',
114
244
  action: () => {
115
- const order = ['js'];
116
- if (workbench.enabledLanguages?.has('ts')) order.push('ts');
117
- if (workbench.enabledLanguages?.has('cpp')) order.push('cpp');
118
- if (workbench.enabledLanguages?.has('py')) order.push('py');
119
- const next = order[(order.indexOf(workbench.lang) + 1) % order.length] || 'js';
120
- workbench.setLanguage(next);
245
+ if (typeof workbench.openSettingsView === 'function') workbench.openSettingsView();
246
+ else if (typeof workbench.showSettingsModal === 'function') workbench.showSettingsModal();
121
247
  }
122
248
  },
123
249
  {
124
- id: 'toggle-fullscreen',
125
- label: 'View: Toggle Fullscreen Workbench',
126
- action: () => workbench.toggleFullscreen()
250
+ id: 'toggle-theme',
251
+ label: 'Preferences: Cycle Color Theme (Dark Modern / Light Modern / High Contrast)',
252
+ action: () => {
253
+ const order = ['dark', 'light', 'high-contrast'];
254
+ const cur = typeof workbench._resolvedTheme === 'function' ? workbench._resolvedTheme() : workbench.theme;
255
+ const next = order[(order.indexOf(cur) + 1) % order.length] || 'dark';
256
+ if (typeof workbench.setTheme === 'function') workbench.setTheme(next);
257
+ }
127
258
  },
128
259
  {
129
260
  id: 'search-workspace',
130
- label: 'Search: Find & Replace Across Files...',
261
+ label: 'Search: Find in Files',
131
262
  shortcut: '⇧⌘F',
132
263
  action: () => workbench.showSearchModal()
133
264
  },
134
265
  {
135
266
  id: 'open-scm',
136
- label: 'Git: Source Control (Status, Stage & Commit)...',
267
+ label: 'Source Control: Focus on Source Control View',
268
+ shortcut: '⌃⇧G',
137
269
  action: () => workbench.showScmModal()
270
+ },
271
+ {
272
+ id: 'git-clone',
273
+ label: 'Git: Clone Repository...',
274
+ action: () => {
275
+ if (typeof workbench.showCloneModal === 'function') workbench.showCloneModal();
276
+ }
277
+ },
278
+ {
279
+ id: 'git-stash',
280
+ label: 'Git: Stash Changes',
281
+ action: () => {
282
+ if (workbench.shell && typeof workbench.shell.execute === 'function') {
283
+ void workbench.shell.execute('git stash push').then(() => {
284
+ if (typeof workbench._refreshGitDecorations === 'function') workbench._refreshGitDecorations();
285
+ });
286
+ }
287
+ }
288
+ },
289
+ {
290
+ id: 'git-stash-pop',
291
+ label: 'Git: Pop Latest Stash',
292
+ action: () => {
293
+ if (workbench.shell && typeof workbench.shell.execute === 'function') {
294
+ void workbench.shell.execute('git stash pop').then(() => {
295
+ if (typeof workbench._syncFilesFromVfs === 'function') workbench._syncFilesFromVfs();
296
+ if (typeof workbench._refreshGitDecorations === 'function') workbench._refreshGitDecorations();
297
+ });
298
+ }
299
+ }
300
+ },
301
+ {
302
+ id: 'share-snapshot',
303
+ label: 'Share: Copy URL Snapshot to Clipboard (#codelab=...)',
304
+ action: () => workbench.shareSnapshot()
305
+ },
306
+ {
307
+ id: 'export-workspace-zip',
308
+ label: 'File: Download Workspace as ZIP Archive',
309
+ action: () => workbench.exportProjectZip({ download: true })
310
+ },
311
+ {
312
+ id: 'export-workspace-json',
313
+ label: 'File: Export Workspace as JSON',
314
+ action: () => workbench.exportWorkspace({ download: true })
315
+ },
316
+ {
317
+ id: 'toggle-fullscreen',
318
+ label: 'View: Toggle Full Screen',
319
+ action: () => workbench.toggleFullscreen()
138
320
  }
139
321
  ];
322
+
323
+ if (workbench.hasGuidedLab) {
324
+ commands.push(
325
+ {
326
+ id: 'compare-solution',
327
+ label: 'Diff: Compare Active File with Reference Solution',
328
+ action: () => workbench.showDiffModal(workbench.activeFile || workbench._pickDefaultFile(), 'solution')
329
+ },
330
+ {
331
+ id: 'compare-starter',
332
+ label: 'Diff: Compare Active File with Starter Template',
333
+ action: () => workbench.showDiffModal(workbench.activeFile || workbench._pickDefaultFile(), 'starter')
334
+ },
335
+ {
336
+ id: 'switch-lang',
337
+ label: 'Language: Cycle Active Lab Language (JS / TS / C++ / PY)',
338
+ action: () => {
339
+ const order = ['js'];
340
+ if (workbench.enabledLanguages?.has('ts')) order.push('ts');
341
+ if (workbench.enabledLanguages?.has('cpp')) order.push('cpp');
342
+ if (workbench.enabledLanguages?.has('py')) order.push('py');
343
+ const next = order[(order.indexOf(workbench.lang) + 1) % order.length] || 'js';
344
+ workbench.setLanguage(next);
345
+ }
346
+ }
347
+ );
348
+ }
349
+
350
+ // Merge live Monaco editor actions (`Rename Symbol`, `Go to References`, `Change All Occurrences`, `Fold All`, etc.)
351
+ const editor = workbench.editor;
352
+ if (editor && typeof editor.getSupportedActions === 'function') {
353
+ try {
354
+ const existingLabels = new Set(commands.map((c) => c.label.toLowerCase()));
355
+ const actions = editor.getSupportedActions() || [];
356
+ for (const act of actions) {
357
+ if (!act || !act.id || !act.label) continue;
358
+ if (typeof act.isSupported === 'function' && !act.isSupported()) continue;
359
+ const label = `Editor: ${act.label}`;
360
+ if (existingLabels.has(label.toLowerCase()) || existingLabels.has(String(act.label).toLowerCase())) continue;
361
+ existingLabels.add(label.toLowerCase());
362
+ commands.push({
363
+ id: `monaco:${act.id}`,
364
+ label,
365
+ action: () => {
366
+ try {
367
+ editor.focus?.();
368
+ void act.run();
369
+ } catch (_err) {
370
+ void _err;
371
+ }
372
+ }
373
+ });
374
+ }
375
+ } catch (_err) {
376
+ void _err;
377
+ }
378
+ }
379
+
380
+ return commands;
140
381
  }