@innovatorved/code-lab 0.3.2 → 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.
- package/ARCHITECTURE.md +5 -3
- package/CHANGELOG.md +20 -0
- package/README.md +70 -168
- 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 +246 -0
- package/dist/code-lab.d.ts +110 -15
- package/dist/code-lab.esm.js +34265 -18104
- package/dist/code-lab.js +33186 -17053
- package/dist/code-lab.umd.js +65502 -0
- package/dist/extensions/cpp.esm.js +19478 -3760
- package/dist/extensions/cpp.js +19475 -3757
- 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 +19576 -3766
- package/dist/extensions/python.js +19576 -3766
- 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 +100 -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 +89 -0
- package/dist/packages/ui/src/settings-dialog.d.ts +25 -0
- package/dist/packages/ui/src/themes.d.ts +35 -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/shell.d.ts +1 -1
- package/dist/shell.esm.js +364 -39
- package/dist/shell.js +364 -39
- package/dist/terminal.esm.js +62 -3
- package/dist/terminal.js +62 -3
- package/dist/workbench/diff-editor.d.ts +1 -0
- package/package.json +37 -8
- 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 +235 -0
- package/packages/settings/src/configuration-service.ts +543 -0
- package/packages/settings/src/index.ts +37 -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 +36 -0
- package/packages/ui/src/observability.ts +175 -0
- package/packages/ui/src/plugin-registry.ts +274 -0
- package/packages/ui/src/settings-dialog.ts +293 -0
- package/packages/ui/src/themes.ts +174 -0
- package/packages/ui/tsconfig.json +24 -0
- package/src/code-lab.css +246 -0
- package/src/extensions/cpp.ts +58 -15
- package/src/extensions/python.ts +156 -24
- 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/shell.ts +363 -39
- package/src/terminal.ts +60 -2
- package/src/workbench/diff-editor.ts +66 -6
- package/src/workbench/icons.ts +5 -2
- package/src/workbench.ts +2410 -220
- 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
package/src/workbench.ts
CHANGED
|
@@ -30,6 +30,8 @@
|
|
|
30
30
|
}
|
|
31
31
|
const CodeLabTerminal = (root && root.CodeLabTerminal) || terminalModule || {};
|
|
32
32
|
const CodeLabShell = (root && root.CodeLabShell) || shellModule || {};
|
|
33
|
+
const getModular = () => (typeof CodeLabModular !== 'undefined' && CodeLabModular) || (root && root.CodeLabModular) || null;
|
|
34
|
+
const getSqlPack = () => (typeof CodeLabSql !== 'undefined' && CodeLabSql) || (root && root.CodeLabSql) || getModular() || null;
|
|
33
35
|
const createPTYTerminalEngine = CodeLabTerminal.createPTYTerminalEngine || CodeLabTerminal.createTerminal || CodeLabTerminal.PTYTerminalEngine || (root && (root.createPTYTerminalEngine || root.PTYTerminalEngine));
|
|
34
36
|
const ansiToHtml = CodeLabTerminal.parseAnsiToHtml || CodeLabTerminal.ansiToHtml || (root && (root.parseAnsiToHtml || root.ansiToHtml));
|
|
35
37
|
const createPosixShell = CodeLabShell.createPosixShell || (root && root.createPosixShell);
|
|
@@ -57,7 +59,7 @@
|
|
|
57
59
|
|
|
58
60
|
// The bundler rewrites this literal from package.json at build time. Keeping
|
|
59
61
|
// the fallback in sync lets tests require src/workbench.js directly.
|
|
60
|
-
const CODELAB_VERSION = '0.
|
|
62
|
+
const CODELAB_VERSION = '0.4.0';
|
|
61
63
|
|
|
62
64
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
63
65
|
const NODE_AMBIENT_DTS = `
|
|
@@ -980,8 +982,8 @@ declare module 'bun:sqlite' {
|
|
|
980
982
|
root.MonacoEnvironment = {
|
|
981
983
|
getWorkerUrl: function () {
|
|
982
984
|
const blobCode = `
|
|
983
|
-
self.MonacoEnvironment = { baseUrl:
|
|
984
|
-
importScripts(
|
|
985
|
+
self.MonacoEnvironment = { baseUrl: ${JSON.stringify(amdBaseUrl)} };
|
|
986
|
+
importScripts(${JSON.stringify(baseUrl + '/base/worker/workerMain.js')});
|
|
985
987
|
`;
|
|
986
988
|
return URL.createObjectURL(new Blob([blobCode], { type: 'application/javascript' }));
|
|
987
989
|
}
|
|
@@ -1144,18 +1146,49 @@ int main() {
|
|
|
1144
1146
|
`
|
|
1145
1147
|
};
|
|
1146
1148
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
+
const DEFAULT_STANDALONE_SQL_FILES = {
|
|
1150
|
+
'query.sql': `-- SQL Playground & Guided Lab\nSELECT 1 AS id, 'code-lab' AS engine;\n`
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
// Helper to convert JS file set to TS, C++, Python, or SQL file set if explicit language files aren't provided
|
|
1154
|
+
function mapFilesToLanguage(filesObj, lang, explicitTsFiles, explicitCppFiles, explicitPyFiles, explicitSqlFiles) {
|
|
1155
|
+
const preserveConfigFiles = (target) => {
|
|
1156
|
+
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1157
|
+
if (name.startsWith('.codelab/')) {
|
|
1158
|
+
target[name] = content;
|
|
1159
|
+
}
|
|
1160
|
+
}
|
|
1161
|
+
return target;
|
|
1162
|
+
};
|
|
1163
|
+
if (lang === 'sql') {
|
|
1164
|
+
if (explicitSqlFiles && Object.keys(explicitSqlFiles).length > 0) {
|
|
1165
|
+
return preserveConfigFiles({ ...explicitSqlFiles });
|
|
1166
|
+
}
|
|
1167
|
+
const existingSql = {};
|
|
1168
|
+
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1169
|
+
if (/\.(sql|md)$/i.test(name) || name.startsWith('.codelab/')) {
|
|
1170
|
+
existingSql[name] = content;
|
|
1171
|
+
}
|
|
1172
|
+
}
|
|
1173
|
+
if (Object.keys(existingSql).some(f => /\.sql$/i.test(f))) {
|
|
1174
|
+
return existingSql;
|
|
1175
|
+
}
|
|
1176
|
+
const outSql = { ...DEFAULT_STANDALONE_SQL_FILES };
|
|
1177
|
+
if (filesObj && filesObj['README.md']) {
|
|
1178
|
+
outSql['README.md'] = filesObj['README.md'];
|
|
1179
|
+
}
|
|
1180
|
+
return preserveConfigFiles(outSql);
|
|
1181
|
+
}
|
|
1149
1182
|
if (lang === 'ts' && explicitTsFiles && Object.keys(explicitTsFiles).length > 0) {
|
|
1150
|
-
return { ...explicitTsFiles };
|
|
1183
|
+
return preserveConfigFiles({ ...explicitTsFiles });
|
|
1151
1184
|
}
|
|
1152
1185
|
if (lang === 'cpp') {
|
|
1153
1186
|
if (explicitCppFiles && Object.keys(explicitCppFiles).length > 0) {
|
|
1154
|
-
return { ...explicitCppFiles };
|
|
1187
|
+
return preserveConfigFiles({ ...explicitCppFiles });
|
|
1155
1188
|
}
|
|
1156
1189
|
const existingCpp = {};
|
|
1157
1190
|
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1158
|
-
if (/\.(cpp|cc|cxx|h|hpp|md)$/i.test(name)) {
|
|
1191
|
+
if (/\.(cpp|cc|cxx|h|hpp|md)$/i.test(name) || name.startsWith('.codelab/')) {
|
|
1159
1192
|
existingCpp[name] = content;
|
|
1160
1193
|
}
|
|
1161
1194
|
}
|
|
@@ -1166,15 +1199,15 @@ int main() {
|
|
|
1166
1199
|
if (filesObj && filesObj['README.md']) {
|
|
1167
1200
|
outCpp['README.md'] = filesObj['README.md'];
|
|
1168
1201
|
}
|
|
1169
|
-
return outCpp;
|
|
1202
|
+
return preserveConfigFiles(outCpp);
|
|
1170
1203
|
}
|
|
1171
1204
|
if (lang === 'py') {
|
|
1172
1205
|
if (explicitPyFiles && Object.keys(explicitPyFiles).length > 0) {
|
|
1173
|
-
return { ...explicitPyFiles };
|
|
1206
|
+
return preserveConfigFiles({ ...explicitPyFiles });
|
|
1174
1207
|
}
|
|
1175
1208
|
const existingPy = {};
|
|
1176
1209
|
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1177
|
-
if (/\.(py|md)$/i.test(name)) {
|
|
1210
|
+
if (/\.(py|md)$/i.test(name) || name.startsWith('.codelab/')) {
|
|
1178
1211
|
existingPy[name] = content;
|
|
1179
1212
|
}
|
|
1180
1213
|
}
|
|
@@ -1185,7 +1218,7 @@ int main() {
|
|
|
1185
1218
|
if (filesObj && filesObj['README.md']) {
|
|
1186
1219
|
outPy['README.md'] = filesObj['README.md'];
|
|
1187
1220
|
}
|
|
1188
|
-
return outPy;
|
|
1221
|
+
return preserveConfigFiles(outPy);
|
|
1189
1222
|
}
|
|
1190
1223
|
const out = {};
|
|
1191
1224
|
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
@@ -1202,8 +1235,8 @@ int main() {
|
|
|
1202
1235
|
}
|
|
1203
1236
|
|
|
1204
1237
|
const DEFAULT_STANDALONE_PYTHON_FILES = {
|
|
1205
|
-
'main.py': `"""
|
|
1206
|
-
'test.py': `from codelab_test import describe, it, assert_equal
|
|
1238
|
+
'main.py': `"""\nStandalone Python 3.12 Sandbox with CPython WebAssembly.\n"""\nfrom codelab_test import describe, it, assert_equal\n\ndef solve(x):\n return x\n\nif __name__ == '__main__':\n print("Hello from Python 3.12 in CodeLab!")\n print("Output:", solve({"status": "ok"}))\n`,
|
|
1239
|
+
'test.py': `from codelab_test import describe, it, assert_equal\nfrom main import solve\n\nwith describe("Python Sandbox Test Suite"):\n with it("returns input value"):\n assert_equal(solve(42), 42)\n`
|
|
1207
1240
|
};
|
|
1208
1241
|
|
|
1209
1242
|
const DEFAULT_STANDALONE_FILES = {
|
|
@@ -1252,8 +1285,11 @@ int main() {
|
|
|
1252
1285
|
warning: '<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/><line x1="12" y1="9" x2="12" y2="13"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>',
|
|
1253
1286
|
clock: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/></svg>',
|
|
1254
1287
|
memory: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 19v2"/><path d="M10 19v2"/><path d="M14 19v2"/><path d="M18 19v2"/><path d="M6 3v2"/><path d="M10 3v2"/><path d="M14 3v2"/><path d="M18 3v2"/><rect x="2" y="5" width="20" height="14" rx="2"/></svg>',
|
|
1255
|
-
keyboard: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.01"/><path d="M10 8h.01"/><path d="M14 8h.01"/><path d="M18 8h.01"/><path d="M6 12h.01"/><path d="M10 12h.01"/><path d="M14 12h.01"/><path d="M18 12h.01"/><path d="M7 16h10"/></svg>',
|
|
1256
|
-
share: '<svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>'
|
|
1288
|
+
keyboard: '<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="4" width="20" height="16" rx="2"/><path d="M6 8h.01"/><path d="M10 8h.01"/><path d="M14 8h.01"/><path d="M18 8h.01"/><path d="M6 12h.01"/><path d="M10 12h.01"/><path d="M14 12h.01"/><path d="M18 12h.01"/><path d="M7 16h10"/></svg>',
|
|
1289
|
+
share: '<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/></svg>',
|
|
1290
|
+
layout: '<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="2"/><line x1="3" y1="9" x2="21" y2="9"/><line x1="9" y1="21" x2="9" y2="9"/></svg>',
|
|
1291
|
+
maximize: '<svg aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/></svg>',
|
|
1292
|
+
settings: '<svg aria-hidden="true" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z"/></svg>'
|
|
1257
1293
|
};
|
|
1258
1294
|
|
|
1259
1295
|
let _workbenchInstanceCounter = 0;
|
|
@@ -1420,7 +1456,21 @@ int main() {
|
|
|
1420
1456
|
const implData = root.IMPLEMENTATIONS_DATA?.[this.labId];
|
|
1421
1457
|
const guidedData = root.GUIDED_LABS_DATA?.[this.labId];
|
|
1422
1458
|
|
|
1423
|
-
const
|
|
1459
|
+
const initLang = options.language || options.lang || 'js';
|
|
1460
|
+
const codeShorthandFile = typeof options.code === 'string'
|
|
1461
|
+
? {
|
|
1462
|
+
[initLang === 'sql'
|
|
1463
|
+
? 'query.sql'
|
|
1464
|
+
: initLang === 'py'
|
|
1465
|
+
? 'main.py'
|
|
1466
|
+
: initLang === 'cpp'
|
|
1467
|
+
? 'main.cpp'
|
|
1468
|
+
: initLang === 'ts'
|
|
1469
|
+
? 'index.ts'
|
|
1470
|
+
: 'index.js']: options.code
|
|
1471
|
+
}
|
|
1472
|
+
: null;
|
|
1473
|
+
const rawRefFiles = options.solutionFiles || options.files || codeShorthandFile || implData?.files || {};
|
|
1424
1474
|
this.referenceFiles = Object.keys(rawRefFiles).length > 0 ? { ...rawRefFiles } : { ...DEFAULT_STANDALONE_FILES };
|
|
1425
1475
|
|
|
1426
1476
|
this.guidedConfig = {
|
|
@@ -1432,7 +1482,9 @@ int main() {
|
|
|
1432
1482
|
...(options.cppStarterFiles ? { cppStarterFiles: options.cppStarterFiles } : {}),
|
|
1433
1483
|
...((options.cppSolutionFiles || options.cppFiles) ? { cppSolutionFiles: options.cppSolutionFiles || options.cppFiles } : {}),
|
|
1434
1484
|
...(options.pyStarterFiles ? { pyStarterFiles: options.pyStarterFiles } : {}),
|
|
1435
|
-
...((options.pySolutionFiles || options.pyFiles) ? { pySolutionFiles: options.pySolutionFiles || options.pyFiles } : {})
|
|
1485
|
+
...((options.pySolutionFiles || options.pyFiles) ? { pySolutionFiles: options.pySolutionFiles || options.pyFiles } : {}),
|
|
1486
|
+
...(options.sqlStarterFiles ? { sqlStarterFiles: options.sqlStarterFiles } : {}),
|
|
1487
|
+
...((options.sqlSolutionFiles || options.sqlFiles) ? { sqlSolutionFiles: options.sqlSolutionFiles || options.sqlFiles } : {})
|
|
1436
1488
|
};
|
|
1437
1489
|
this.steps = options.steps || this.guidedConfig?.steps || [];
|
|
1438
1490
|
this.hasGuidedLab = Boolean(
|
|
@@ -1440,11 +1492,25 @@ int main() {
|
|
|
1440
1492
|
options.guidedLab ||
|
|
1441
1493
|
(this.steps && this.steps.length > 0)
|
|
1442
1494
|
);
|
|
1443
|
-
|
|
1495
|
+
const isPureSqlInit = Boolean(
|
|
1496
|
+
(options.lang === 'sql' || options.language === 'sql') &&
|
|
1497
|
+
!options.languages &&
|
|
1498
|
+
!options.hasMultipleLanguages &&
|
|
1499
|
+
!this.guidedConfig.tsStarterFiles &&
|
|
1500
|
+
!this.guidedConfig.tsSolutionFiles &&
|
|
1501
|
+
!this.guidedConfig.tsFiles &&
|
|
1502
|
+
!this.guidedConfig.cppStarterFiles &&
|
|
1503
|
+
!this.guidedConfig.cppSolutionFiles &&
|
|
1504
|
+
!this.guidedConfig.pyStarterFiles &&
|
|
1505
|
+
!this.guidedConfig.pySolutionFiles
|
|
1506
|
+
);
|
|
1507
|
+
this.enabledLanguages = new Set(isPureSqlInit ? ['sql'] : ['js']);
|
|
1444
1508
|
if (Array.isArray(options.languages)) {
|
|
1509
|
+
this.enabledLanguages = new Set();
|
|
1445
1510
|
for (const l of options.languages) {
|
|
1446
|
-
if (l === 'js' || l === 'ts' || l === 'cpp' || l === 'py') this.enabledLanguages.add(l);
|
|
1511
|
+
if (l === 'js' || l === 'ts' || l === 'cpp' || l === 'py' || l === 'sql') this.enabledLanguages.add(l);
|
|
1447
1512
|
}
|
|
1513
|
+
if (this.enabledLanguages.size === 0) this.enabledLanguages.add('js');
|
|
1448
1514
|
}
|
|
1449
1515
|
if (
|
|
1450
1516
|
options.hasMultipleLanguages ||
|
|
@@ -1474,9 +1540,19 @@ int main() {
|
|
|
1474
1540
|
) {
|
|
1475
1541
|
this.enabledLanguages.add('py');
|
|
1476
1542
|
}
|
|
1543
|
+
if (
|
|
1544
|
+
this.guidedConfig.sqlStarterFiles ||
|
|
1545
|
+
this.guidedConfig.sqlSolutionFiles ||
|
|
1546
|
+
this.guidedConfig.sqlFiles ||
|
|
1547
|
+
options.lang === 'sql' ||
|
|
1548
|
+
options.language === 'sql' ||
|
|
1549
|
+
typeof options.sqlRunner === 'function'
|
|
1550
|
+
) {
|
|
1551
|
+
this.enabledLanguages.add('sql');
|
|
1552
|
+
}
|
|
1477
1553
|
this.hasMultipleLanguages = Boolean(
|
|
1478
1554
|
options.hasMultipleLanguages ||
|
|
1479
|
-
options.languages ||
|
|
1555
|
+
(Array.isArray(options.languages) && options.languages.length > 1) ||
|
|
1480
1556
|
this.enabledLanguages.size > 1 ||
|
|
1481
1557
|
this.guidedConfig.tsStarterFiles ||
|
|
1482
1558
|
this.guidedConfig.tsSolutionFiles ||
|
|
@@ -1487,7 +1563,7 @@ int main() {
|
|
|
1487
1563
|
this.guidedConfig.pyStarterFiles ||
|
|
1488
1564
|
this.guidedConfig.pySolutionFiles ||
|
|
1489
1565
|
this.guidedConfig.pyFiles ||
|
|
1490
|
-
(this.hasGuidedLab && (options.lang || options.language))
|
|
1566
|
+
(!isPureSqlInit && this.hasGuidedLab && (options.lang || options.language))
|
|
1491
1567
|
);
|
|
1492
1568
|
this.showWebPreviewOption = Boolean(options.showWebPreview);
|
|
1493
1569
|
this._diffManager = null;
|
|
@@ -1497,6 +1573,21 @@ int main() {
|
|
|
1497
1573
|
|
|
1498
1574
|
this.mode = options.mode || this.savedState.mode || (this.hasGuidedLab ? 'guided' : 'sandbox');
|
|
1499
1575
|
this.lang = options.language || options.lang || this.savedState.lang || 'js';
|
|
1576
|
+
this.sqlDialect = (
|
|
1577
|
+
options.sqlDialect === 'sqlite' ||
|
|
1578
|
+
options.dialect === 'sqlite' ||
|
|
1579
|
+
(options.sqlSchema && options.sqlSchema.dialect === 'sqlite') ||
|
|
1580
|
+
(options.schema && options.schema.dialect === 'sqlite')
|
|
1581
|
+
) ? 'sqlite' : 'postgres';
|
|
1582
|
+
this.sqlSchema = options.sqlSchema || options.schema || null;
|
|
1583
|
+
this.sqlRunner = typeof options.sqlRunner === 'function' ? options.sqlRunner : null;
|
|
1584
|
+
this.lastSqlResult = null;
|
|
1585
|
+
this._sqlWorkbenchEditor = null;
|
|
1586
|
+
this._forceShowExplorer = Boolean(options.showExplorer);
|
|
1587
|
+
this._workspaceTasks = [];
|
|
1588
|
+
this._settingsDialog = null;
|
|
1589
|
+
this._pluginPanelDisposables = [];
|
|
1590
|
+
|
|
1500
1591
|
this.activeStepIndex = typeof options.stepIndex === 'number' ? options.stepIndex : (this.savedState.activeStepIndex || 0);
|
|
1501
1592
|
if (this.activeStepIndex >= this.steps.length || this.activeStepIndex < 0) this.activeStepIndex = 0;
|
|
1502
1593
|
|
|
@@ -1517,7 +1608,9 @@ int main() {
|
|
|
1517
1608
|
this.renamingItem = null;
|
|
1518
1609
|
this._draggedFile = null;
|
|
1519
1610
|
this.guideTab = 'steps'; // 'steps' | 'readme'
|
|
1520
|
-
this.drawerTab =
|
|
1611
|
+
this.drawerTab = this.lang === 'sql'
|
|
1612
|
+
? 'sql-results'
|
|
1613
|
+
: ((this.hasGuidedLab && this.mode === 'guided') ? 'tests' : 'terminal');
|
|
1521
1614
|
this.testSuiteVisible = Boolean(this.hasGuidedLab && this.mode === 'guided');
|
|
1522
1615
|
this.lastDurationMs = null;
|
|
1523
1616
|
this.lastPeakMemoryBytes = null;
|
|
@@ -1560,7 +1653,9 @@ int main() {
|
|
|
1560
1653
|
this.cursorPos = { lineNumber: 1, column: 1 };
|
|
1561
1654
|
this.lastRunDurationMs = null;
|
|
1562
1655
|
this.runtimeStatusState = 'idle';
|
|
1563
|
-
this.runtimeStatusText =
|
|
1656
|
+
this.runtimeStatusText = this.lang === 'sql'
|
|
1657
|
+
? `${this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18'} · Idle`
|
|
1658
|
+
: 'Node.js v22 Worker · Idle';
|
|
1564
1659
|
|
|
1565
1660
|
// Initialize working files for current mode & language
|
|
1566
1661
|
this.files = this._computeInitialFiles();
|
|
@@ -1656,11 +1751,20 @@ int main() {
|
|
|
1656
1751
|
this.monaco = null;
|
|
1657
1752
|
this.editor = null;
|
|
1658
1753
|
this.models = new Map();
|
|
1659
|
-
|
|
1754
|
+
this._forceOpenedLargeFiles = new Set();
|
|
1755
|
+
this._saveDebounceTimer = null;
|
|
1756
|
+
this._idbSaveChain = Promise.resolve();
|
|
1757
|
+
this._breadcrumbRafId = null;
|
|
1758
|
+
this._markerDisposable = null;
|
|
1759
|
+
this._destroyed = false;
|
|
1760
|
+
|
|
1761
|
+
this._initKernel();
|
|
1660
1762
|
this._renderShell();
|
|
1661
1763
|
this._bindEvents();
|
|
1662
1764
|
this._initEditor();
|
|
1765
|
+
this._syncDotCodelabConfig({ isInitialMount: true });
|
|
1663
1766
|
this._checkUrlSnapshot();
|
|
1767
|
+
this._hydrateFromAsyncStorage();
|
|
1664
1768
|
|
|
1665
1769
|
const initialPlugins = [
|
|
1666
1770
|
...(Array.isArray(options.extensions) ? options.extensions : []),
|
|
@@ -1670,6 +1774,12 @@ int main() {
|
|
|
1670
1774
|
this.use(plugin);
|
|
1671
1775
|
}
|
|
1672
1776
|
|
|
1777
|
+
if (this.plugins && typeof this.plugins.fireActivationEvent === 'function') {
|
|
1778
|
+
this.plugins.fireActivationEvent('onStartupFinished').catch((err) => {
|
|
1779
|
+
this.logger.debug('onStartupFinished plugin activation error.', err);
|
|
1780
|
+
});
|
|
1781
|
+
}
|
|
1782
|
+
|
|
1673
1783
|
if (options.repo && typeof options.repo === 'string') {
|
|
1674
1784
|
this.cloneRepo(options.repo, {
|
|
1675
1785
|
intoRoot: options.cloneIntoRoot !== false,
|
|
@@ -1679,6 +1789,169 @@ int main() {
|
|
|
1679
1789
|
}
|
|
1680
1790
|
}
|
|
1681
1791
|
|
|
1792
|
+
_initKernel() {
|
|
1793
|
+
const mod = getModular();
|
|
1794
|
+
if (!mod || typeof mod.createCodeLabKernel !== 'function') {
|
|
1795
|
+
this.kernel = null;
|
|
1796
|
+
this.configuration = null;
|
|
1797
|
+
this.commands = null;
|
|
1798
|
+
this.keybindings = null;
|
|
1799
|
+
this.themes = null;
|
|
1800
|
+
this.plugins = null;
|
|
1801
|
+
this.contextKeys = null;
|
|
1802
|
+
this._errorBoundary = null;
|
|
1803
|
+
return;
|
|
1804
|
+
}
|
|
1805
|
+
try {
|
|
1806
|
+
this.kernel = mod.createCodeLabKernel({
|
|
1807
|
+
instanceId: this.instanceId,
|
|
1808
|
+
initialFiles: this.files,
|
|
1809
|
+
runtimeDelegate: (opts) => this._executeRuntime(opts)
|
|
1810
|
+
});
|
|
1811
|
+
this.configuration = this.kernel.configuration;
|
|
1812
|
+
this.commands = this.kernel.commands;
|
|
1813
|
+
this.keybindings = this.kernel.keybindings;
|
|
1814
|
+
this.themes = this.kernel.themes;
|
|
1815
|
+
this.plugins = this.kernel.plugins;
|
|
1816
|
+
this.contextKeys = this.kernel.contextKeys;
|
|
1817
|
+
this._errorBoundary = (this.container && mod.WorkbenchErrorBoundary)
|
|
1818
|
+
? new mod.WorkbenchErrorBoundary(this.container, this.kernel.logger)
|
|
1819
|
+
: null;
|
|
1820
|
+
|
|
1821
|
+
if (this.contextKeys) {
|
|
1822
|
+
this.contextKeys.setContext('editorLangId', this.lang);
|
|
1823
|
+
this.contextKeys.setContext('workbenchMode', this.mode);
|
|
1824
|
+
this.contextKeys.setContext('isGuidedLab', this.hasGuidedLab);
|
|
1825
|
+
}
|
|
1826
|
+
|
|
1827
|
+
// Load persisted user settings from localStorage if available
|
|
1828
|
+
if (this.persistState && this.configuration) {
|
|
1829
|
+
const savedUserSettings = safeStorageGet(`${STORAGE_PREFIX}user-settings`, this.logger);
|
|
1830
|
+
if (savedUserSettings) {
|
|
1831
|
+
this.configuration.importProfile(savedUserSettings);
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
|
|
1835
|
+
// Apply URL ?settings= parameter if present
|
|
1836
|
+
if (typeof window !== 'undefined' && window.location && window.location.search && this.configuration) {
|
|
1837
|
+
try {
|
|
1838
|
+
const params = new URLSearchParams(window.location.search);
|
|
1839
|
+
const encoded = params.get('settings');
|
|
1840
|
+
if (encoded) {
|
|
1841
|
+
this.configuration.applyUrlParam(encoded);
|
|
1842
|
+
}
|
|
1843
|
+
} catch (err) {
|
|
1844
|
+
this.logger.debug('URL ?settings= parameter parse skipped.', err);
|
|
1845
|
+
}
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
// Apply constructor overrides onto Layer 4 if passed in options.settings
|
|
1849
|
+
if (this.options && this.options.settings && typeof this.options.settings === 'object' && this.configuration) {
|
|
1850
|
+
this.configuration.setOverrides(this.options.settings);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
// Register built-in commands & keybindings
|
|
1854
|
+
if (this.commands) {
|
|
1855
|
+
this.commands.registerCommand({
|
|
1856
|
+
id: 'workbench.action.openSettings',
|
|
1857
|
+
title: 'Preferences: Open Settings (UI)',
|
|
1858
|
+
category: 'Preferences',
|
|
1859
|
+
handler: () => this.openSettings()
|
|
1860
|
+
});
|
|
1861
|
+
this.commands.registerCommand({
|
|
1862
|
+
id: 'workbench.action.openWorkspaceSettingsJson',
|
|
1863
|
+
title: 'Preferences: Open Workspace Settings (JSON)',
|
|
1864
|
+
category: 'Preferences',
|
|
1865
|
+
handler: () => this.openWorkspaceSettingsJson()
|
|
1866
|
+
});
|
|
1867
|
+
this.commands.registerCommand({
|
|
1868
|
+
id: 'workbench.action.quickOpen',
|
|
1869
|
+
title: 'Go to File...',
|
|
1870
|
+
category: 'File',
|
|
1871
|
+
handler: () => this.openCommandPalette('files')
|
|
1872
|
+
});
|
|
1873
|
+
this.commands.registerCommand({
|
|
1874
|
+
id: 'workbench.action.showCommands',
|
|
1875
|
+
title: 'Show All Commands',
|
|
1876
|
+
category: 'View',
|
|
1877
|
+
handler: () => this.openCommandPalette('commands')
|
|
1878
|
+
});
|
|
1879
|
+
this.commands.registerCommand({
|
|
1880
|
+
id: 'workbench.action.openObservability',
|
|
1881
|
+
title: 'Developer: Open Observability & Services Inspector',
|
|
1882
|
+
category: 'Developer',
|
|
1883
|
+
handler: () => this.switchDrawerTab('observability')
|
|
1884
|
+
});
|
|
1885
|
+
this.commands.registerCommand({
|
|
1886
|
+
id: 'codeLab.runCode',
|
|
1887
|
+
title: 'CodeLab: Run Code',
|
|
1888
|
+
category: 'CodeLab',
|
|
1889
|
+
handler: () => this.runCode()
|
|
1890
|
+
});
|
|
1891
|
+
this.commands.registerCommand({
|
|
1892
|
+
id: 'codeLab.runTests',
|
|
1893
|
+
title: 'CodeLab: Run Tests',
|
|
1894
|
+
category: 'CodeLab',
|
|
1895
|
+
handler: () => this.runTests()
|
|
1896
|
+
});
|
|
1897
|
+
this.commands.registerCommand({
|
|
1898
|
+
id: 'codeLab.runSql',
|
|
1899
|
+
title: 'SQL: Run Query',
|
|
1900
|
+
category: 'SQL',
|
|
1901
|
+
when: "editorLangId == 'sql'",
|
|
1902
|
+
handler: () => this.runSql('run')
|
|
1903
|
+
});
|
|
1904
|
+
this.commands.registerCommand({
|
|
1905
|
+
id: 'codeLab.explainSql',
|
|
1906
|
+
title: 'SQL: Explain Query Plan',
|
|
1907
|
+
category: 'SQL',
|
|
1908
|
+
when: "editorLangId == 'sql'",
|
|
1909
|
+
handler: () => this.runSql('explain')
|
|
1910
|
+
});
|
|
1911
|
+
this.commands.registerCommand({
|
|
1912
|
+
id: 'codeLab.formatDocument',
|
|
1913
|
+
title: 'Editor: Format Document',
|
|
1914
|
+
category: 'Editor',
|
|
1915
|
+
handler: () => this.formatActiveDocument()
|
|
1916
|
+
});
|
|
1917
|
+
this.commands.registerCommand({
|
|
1918
|
+
id: 'tasks.runTask',
|
|
1919
|
+
title: 'Tasks: Run Workspace Task',
|
|
1920
|
+
category: 'Tasks',
|
|
1921
|
+
handler: (taskId) => this.runTask(taskId)
|
|
1922
|
+
});
|
|
1923
|
+
}
|
|
1924
|
+
|
|
1925
|
+
if (this.keybindings) {
|
|
1926
|
+
this.keybindings.registerKeybinding({
|
|
1927
|
+
key: 'Mod+,',
|
|
1928
|
+
command: 'workbench.action.openSettings'
|
|
1929
|
+
});
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
if (this.configuration) {
|
|
1933
|
+
this.configuration.onDidChangeConfiguration((e) => {
|
|
1934
|
+
if (!this._destroyed) {
|
|
1935
|
+
this._applyConfigurationChanges(e);
|
|
1936
|
+
if (e.source === 'user' && this.persistState) {
|
|
1937
|
+
safeStorageSet(`${STORAGE_PREFIX}user-settings`, this.configuration.exportProfile(), this.logger);
|
|
1938
|
+
}
|
|
1939
|
+
}
|
|
1940
|
+
});
|
|
1941
|
+
}
|
|
1942
|
+
|
|
1943
|
+
if (this.plugins) {
|
|
1944
|
+
this.plugins.onDidChangePlugins(() => {
|
|
1945
|
+
if (!this._destroyed) {
|
|
1946
|
+
this._refreshDrawerTabs();
|
|
1947
|
+
}
|
|
1948
|
+
});
|
|
1949
|
+
}
|
|
1950
|
+
} catch (err) {
|
|
1951
|
+
this.logger.warn('Modular kernel initialization failed; continuing in standalone mode.', err);
|
|
1952
|
+
}
|
|
1953
|
+
}
|
|
1954
|
+
|
|
1682
1955
|
_initShell() {
|
|
1683
1956
|
this._wrapPortTable();
|
|
1684
1957
|
this._initPortListeners();
|
|
@@ -1867,16 +2140,99 @@ int main() {
|
|
|
1867
2140
|
}
|
|
1868
2141
|
|
|
1869
2142
|
_resolvedTheme() {
|
|
1870
|
-
if (this.themeOption === 'light' || this.themeOption === 'dark') {
|
|
2143
|
+
if (this.themeOption === 'light' || this.themeOption === 'dark' || this.themeOption === 'high-contrast') {
|
|
1871
2144
|
return this.themeOption;
|
|
1872
2145
|
}
|
|
1873
|
-
if (typeof document !== 'undefined') {
|
|
2146
|
+
if (typeof document !== 'undefined' && document.documentElement && typeof document.documentElement.getAttribute === 'function') {
|
|
1874
2147
|
const docTheme = document.documentElement.getAttribute('data-theme');
|
|
1875
|
-
if (docTheme === 'light') return
|
|
2148
|
+
if (docTheme === 'light' || docTheme === 'high-contrast') return docTheme;
|
|
2149
|
+
if (docTheme === 'dark') return 'dark';
|
|
2150
|
+
}
|
|
2151
|
+
if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
|
|
2152
|
+
try {
|
|
2153
|
+
if (window.matchMedia('(prefers-color-scheme: light)').matches) return 'light';
|
|
2154
|
+
} catch (err) {
|
|
2155
|
+
_bootDebug('matchMedia color-scheme check failed', err);
|
|
2156
|
+
}
|
|
1876
2157
|
}
|
|
1877
2158
|
return 'dark';
|
|
1878
2159
|
}
|
|
1879
2160
|
|
|
2161
|
+
setTheme(nextTheme) {
|
|
2162
|
+
const normalized = (nextTheme === 'light' || nextTheme === 'dark' || nextTheme === 'high-contrast' || nextTheme === 'auto')
|
|
2163
|
+
? nextTheme
|
|
2164
|
+
: 'dark';
|
|
2165
|
+
this.themeOption = normalized;
|
|
2166
|
+
this.theme = normalized;
|
|
2167
|
+
const resolved = this._resolvedTheme();
|
|
2168
|
+
if (this.container) {
|
|
2169
|
+
this.container.classList.remove('codelab-workbench--dark', 'codelab-workbench--light', 'codelab-workbench--high-contrast');
|
|
2170
|
+
if (normalized === 'auto') {
|
|
2171
|
+
if (typeof this.container.removeAttribute === 'function') this.container.removeAttribute('data-theme');
|
|
2172
|
+
} else {
|
|
2173
|
+
this.container.setAttribute('data-theme', normalized);
|
|
2174
|
+
this.container.classList.add(`codelab-workbench--${normalized}`);
|
|
2175
|
+
}
|
|
2176
|
+
const shellEl = this.container.querySelector('.codelab');
|
|
2177
|
+
if (shellEl) {
|
|
2178
|
+
shellEl.setAttribute('data-cl-theme', resolved);
|
|
2179
|
+
if (normalized === 'auto') {
|
|
2180
|
+
if (typeof shellEl.removeAttribute === 'function') shellEl.removeAttribute('data-theme');
|
|
2181
|
+
} else {
|
|
2182
|
+
shellEl.setAttribute('data-theme', normalized);
|
|
2183
|
+
}
|
|
2184
|
+
}
|
|
2185
|
+
}
|
|
2186
|
+
if (this.monaco && this.monaco.editor && typeof this.monaco.editor.setTheme === 'function') {
|
|
2187
|
+
const monacoTheme = resolved === 'light'
|
|
2188
|
+
? 'codelab-light'
|
|
2189
|
+
: resolved === 'high-contrast'
|
|
2190
|
+
? 'hc-black'
|
|
2191
|
+
: 'codelab-dark';
|
|
2192
|
+
try {
|
|
2193
|
+
this.monaco.editor.setTheme(monacoTheme);
|
|
2194
|
+
} catch (err) {
|
|
2195
|
+
this.logger.debug('monaco.editor.setTheme failed.', err);
|
|
2196
|
+
}
|
|
2197
|
+
}
|
|
2198
|
+
if (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.setTheme === 'function') {
|
|
2199
|
+
try {
|
|
2200
|
+
this._sqlWorkbenchEditor.setTheme(resolved === 'light' ? 'light' : 'dark');
|
|
2201
|
+
} catch (err) {
|
|
2202
|
+
this.logger.debug('_sqlWorkbenchEditor.setTheme failed.', err);
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
if (this.themes && typeof this.themes.setTheme === 'function' && !this._applyingThemeFromService) {
|
|
2206
|
+
try {
|
|
2207
|
+
this._applyingThemeFromService = true;
|
|
2208
|
+
this.themes.setTheme(resolved === 'light' ? 'light' : resolved === 'high-contrast' ? 'high-contrast' : 'dark');
|
|
2209
|
+
} catch (err) {
|
|
2210
|
+
this.logger.debug('themes.setTheme failed.', err);
|
|
2211
|
+
} finally {
|
|
2212
|
+
this._applyingThemeFromService = false;
|
|
2213
|
+
}
|
|
2214
|
+
}
|
|
2215
|
+
// Relay color-scheme/theme to preview iframes explicitly (Safari does not inherit color-scheme into iframes)
|
|
2216
|
+
if (this.container && typeof this.container.querySelectorAll === 'function') {
|
|
2217
|
+
const frames = this.container.querySelectorAll('.codelab-preview-frame, iframe[data-cl-preview-frame]');
|
|
2218
|
+
frames.forEach((frame) => {
|
|
2219
|
+
try {
|
|
2220
|
+
if (frame && frame.contentWindow && typeof frame.contentWindow.postMessage === 'function') {
|
|
2221
|
+
frame.contentWindow.postMessage({ type: 'codelab:theme-change', theme: resolved }, '*');
|
|
2222
|
+
}
|
|
2223
|
+
} catch (err) {
|
|
2224
|
+
this.logger.debug('Preview iframe theme postMessage skipped.', err);
|
|
2225
|
+
}
|
|
2226
|
+
});
|
|
2227
|
+
}
|
|
2228
|
+
this._emitEvent('theme-change', { theme: normalized, resolvedTheme: resolved });
|
|
2229
|
+
return this;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
getTheme() {
|
|
2233
|
+
return this.themeOption || 'auto';
|
|
2234
|
+
}
|
|
2235
|
+
|
|
1880
2236
|
_storageKey() {
|
|
1881
2237
|
return `${STORAGE_PREFIX}${this.labId}`;
|
|
1882
2238
|
}
|
|
@@ -1919,33 +2275,124 @@ int main() {
|
|
|
1919
2275
|
return error;
|
|
1920
2276
|
}
|
|
1921
2277
|
|
|
2278
|
+
_buildSavedStateSnapshot() {
|
|
2279
|
+
const key = `${this.mode}:${this.lang}`;
|
|
2280
|
+
const customFiles = (this.savedState && this.savedState.customFiles) || {};
|
|
2281
|
+
customFiles[key] = { ...this.files };
|
|
2282
|
+
const hasSnapshot = Object.assign(
|
|
2283
|
+
{},
|
|
2284
|
+
(this.savedState && this.savedState.hasSnapshot) || {},
|
|
2285
|
+
{ [key]: true }
|
|
2286
|
+
);
|
|
2287
|
+
const completedArr = Array.from(this.completedSteps);
|
|
2288
|
+
const state = {
|
|
2289
|
+
mode: this.mode,
|
|
2290
|
+
lang: this.lang,
|
|
2291
|
+
activeStepIndex: this.activeStepIndex,
|
|
2292
|
+
completedSteps: completedArr,
|
|
2293
|
+
customFiles,
|
|
2294
|
+
hasSnapshot,
|
|
2295
|
+
openTabs: Array.isArray(this.openTabs) ? [...this.openTabs] : undefined,
|
|
2296
|
+
activeFile: this.activeFile,
|
|
2297
|
+
folders: Array.from(this.folders || []),
|
|
2298
|
+
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
2299
|
+
explorerFolder: this.explorerFolder || '',
|
|
2300
|
+
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined,
|
|
2301
|
+
previewSplitWidth: this.previewSplitWidth || undefined
|
|
2302
|
+
};
|
|
2303
|
+
this.savedState = state;
|
|
2304
|
+
return { state, completedArr };
|
|
2305
|
+
}
|
|
2306
|
+
|
|
2307
|
+
_scheduleSaveState(delayMs = 180) {
|
|
2308
|
+
this._buildSavedStateSnapshot();
|
|
2309
|
+
if (this.options && this.options.persistState === false) {
|
|
2310
|
+
this.saveStatusState = 'saved';
|
|
2311
|
+
this.saveStatusError = null;
|
|
2312
|
+
this._updateStatusBar();
|
|
2313
|
+
return;
|
|
2314
|
+
}
|
|
2315
|
+
if (this.configuration && this.configuration.get('files.autoSave', 'afterDelay') === 'off') {
|
|
2316
|
+
return;
|
|
2317
|
+
}
|
|
2318
|
+
const effectiveDelay = (delayMs === 180 && this.configuration)
|
|
2319
|
+
? Math.max(50, Number(this.configuration.get('files.autoSaveDelay', 180)) || 180)
|
|
2320
|
+
: delayMs;
|
|
2321
|
+
if (this._saveDebounceTimer) {
|
|
2322
|
+
clearTimeout(this._saveDebounceTimer);
|
|
2323
|
+
}
|
|
2324
|
+
this._saveDebounceTimer = setTimeout(() => {
|
|
2325
|
+
this._saveDebounceTimer = null;
|
|
2326
|
+
if (!this._destroyed) {
|
|
2327
|
+
this._saveState();
|
|
2328
|
+
}
|
|
2329
|
+
}, effectiveDelay);
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
flushState() {
|
|
2333
|
+
if (this._saveDebounceTimer) {
|
|
2334
|
+
clearTimeout(this._saveDebounceTimer);
|
|
2335
|
+
this._saveDebounceTimer = null;
|
|
2336
|
+
this._saveState();
|
|
2337
|
+
}
|
|
2338
|
+
}
|
|
2339
|
+
|
|
2340
|
+
_hydrateFromAsyncStorage() {
|
|
2341
|
+
if (this.options && this.options.persistState === false) return;
|
|
2342
|
+
if (this.savedState && Object.keys(this.savedState).length > 0) return;
|
|
2343
|
+
if (!root.CodeLabStorage || typeof root.CodeLabStorage.createWorkspaceStorage !== 'function') return;
|
|
2344
|
+
try {
|
|
2345
|
+
if (!this._idbStorage) {
|
|
2346
|
+
this._idbStorage = root.CodeLabStorage.createWorkspaceStorage();
|
|
2347
|
+
}
|
|
2348
|
+
const loader = this._idbStorage && typeof this._idbStorage.loadProject === 'function'
|
|
2349
|
+
? this._idbStorage.loadProject(this.labId)
|
|
2350
|
+
: (this._idbStorage && typeof this._idbStorage.load === 'function' ? this._idbStorage.load(this.labId) : null);
|
|
2351
|
+
if (!loader || typeof loader.then !== 'function') return;
|
|
2352
|
+
Promise.resolve(loader).then((project) => {
|
|
2353
|
+
if (this._destroyed || !project) return;
|
|
2354
|
+
const hydratedFiles = project.files && typeof project.files === 'object' ? project.files : null;
|
|
2355
|
+
if (!hydratedFiles || Object.keys(hydratedFiles).length === 0) return;
|
|
2356
|
+
// Only hydrate if user hasn't started typing over the fresh starter state
|
|
2357
|
+
if (this._saveDebounceTimer) return;
|
|
2358
|
+
this.files = { ...this.files, ...hydratedFiles };
|
|
2359
|
+
for (const f of Object.keys(this.files)) {
|
|
2360
|
+
const parts = f.split('/');
|
|
2361
|
+
for (let i = 1; i < parts.length; i++) {
|
|
2362
|
+
this.folders.add(parts.slice(0, i).join('/'));
|
|
2363
|
+
}
|
|
2364
|
+
if (!this.openTabs.includes(f)) this.openTabs.push(f);
|
|
2365
|
+
if (this.shell && this.shell.vfs && typeof this.shell.vfs.writeFileSync === 'function') {
|
|
2366
|
+
try {
|
|
2367
|
+
if (parts.length > 1 && typeof this.shell.vfs.mkdirSync === 'function') {
|
|
2368
|
+
this.shell.vfs.mkdirSync('/workspace/' + parts.slice(0, -1).join('/'), { recursive: true });
|
|
2369
|
+
}
|
|
2370
|
+
this.shell.vfs.writeFileSync('/workspace/' + f, String(this.files[f] ?? ''));
|
|
2371
|
+
} catch (err) {
|
|
2372
|
+
this.logger.debug('Async hydration VFS sync skipped.', err);
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
this._syncAllModels();
|
|
2377
|
+
this._renderFileLists();
|
|
2378
|
+
this._renderTabs();
|
|
2379
|
+
this._syncActiveFileToView();
|
|
2380
|
+
this._emitEvent('hydrated', { labId: this.labId, files: Object.keys(hydratedFiles) });
|
|
2381
|
+
}).catch((err) => {
|
|
2382
|
+
this.logger.debug('Async WorkspaceStorage hydration skipped.', err);
|
|
2383
|
+
});
|
|
2384
|
+
} catch (err) {
|
|
2385
|
+
this.logger.debug('WorkspaceStorage hydration initialization skipped.', err);
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
|
|
1922
2389
|
_saveState() {
|
|
1923
2390
|
try {
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
(this.savedState && this.savedState.hasSnapshot) || {},
|
|
1930
|
-
{ [key]: true }
|
|
1931
|
-
);
|
|
1932
|
-
const completedArr = Array.from(this.completedSteps);
|
|
1933
|
-
const state = {
|
|
1934
|
-
mode: this.mode,
|
|
1935
|
-
lang: this.lang,
|
|
1936
|
-
activeStepIndex: this.activeStepIndex,
|
|
1937
|
-
completedSteps: completedArr,
|
|
1938
|
-
customFiles,
|
|
1939
|
-
hasSnapshot,
|
|
1940
|
-
openTabs: Array.isArray(this.openTabs) ? [...this.openTabs] : undefined,
|
|
1941
|
-
activeFile: this.activeFile,
|
|
1942
|
-
folders: Array.from(this.folders || []),
|
|
1943
|
-
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
1944
|
-
explorerFolder: this.explorerFolder || '',
|
|
1945
|
-
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined,
|
|
1946
|
-
previewSplitWidth: this.previewSplitWidth || undefined
|
|
1947
|
-
};
|
|
1948
|
-
this.savedState = state;
|
|
2391
|
+
if (this._saveDebounceTimer) {
|
|
2392
|
+
clearTimeout(this._saveDebounceTimer);
|
|
2393
|
+
this._saveDebounceTimer = null;
|
|
2394
|
+
}
|
|
2395
|
+
const { state, completedArr } = this._buildSavedStateSnapshot();
|
|
1949
2396
|
if (this.options && this.options.persistState === false) {
|
|
1950
2397
|
this.saveStatusState = 'saved';
|
|
1951
2398
|
this.saveStatusError = null;
|
|
@@ -1956,31 +2403,43 @@ int main() {
|
|
|
1956
2403
|
const serialized = JSON.stringify(state);
|
|
1957
2404
|
safeStorageSet._lastError = null;
|
|
1958
2405
|
const recordErr = (err) => { safeStorageSet._lastError = err; };
|
|
2406
|
+
const hostMirrorSummary = JSON.stringify({
|
|
2407
|
+
mode: state.mode,
|
|
2408
|
+
lang: state.lang,
|
|
2409
|
+
activeStepIndex: state.activeStepIndex,
|
|
2410
|
+
completedSteps: completedArr,
|
|
2411
|
+
activeFile: state.activeFile,
|
|
2412
|
+
updatedAt: Date.now()
|
|
2413
|
+
});
|
|
1959
2414
|
const persisted = [
|
|
1960
2415
|
safeStorageSet(this._storageKey(), serialized, this.logger, recordErr),
|
|
1961
|
-
// Sync with host app sidebar
|
|
2416
|
+
// Sync lightweight step-completion progress & compact metadata with host app sidebar trackers
|
|
1962
2417
|
safeStorageSet('codelab_progress_' + this.labId, JSON.stringify(completedArr), this.logger, recordErr),
|
|
1963
|
-
safeStorageSet('sd_codelab_' + this.labId,
|
|
2418
|
+
safeStorageSet('sd_codelab_' + this.labId, hostMirrorSummary, this.logger, recordErr)
|
|
1964
2419
|
];
|
|
1965
2420
|
if (root.CodeLabStorage && typeof root.CodeLabStorage.createWorkspaceStorage === 'function') {
|
|
1966
2421
|
try {
|
|
1967
2422
|
if (!this._idbStorage) {
|
|
1968
2423
|
this._idbStorage = root.CodeLabStorage.createWorkspaceStorage();
|
|
1969
2424
|
}
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
2425
|
+
const filesSnapshot = { ...(this.files || {}) };
|
|
2426
|
+
const stateSnapshot = state;
|
|
2427
|
+
this._idbSaveChain = Promise.resolve(this._idbSaveChain).then(() => {
|
|
2428
|
+
if (this._idbStorage && typeof this._idbStorage.saveProject === 'function') {
|
|
2429
|
+
return this._idbStorage.saveProject({
|
|
2430
|
+
id: this.labId,
|
|
2431
|
+
name: this.title || this.labId,
|
|
2432
|
+
files: filesSnapshot,
|
|
2433
|
+
updatedAt: Date.now()
|
|
2434
|
+
});
|
|
2435
|
+
}
|
|
2436
|
+
if (this._idbStorage && typeof this._idbStorage.save === 'function') {
|
|
2437
|
+
return this._idbStorage.save(this.labId, stateSnapshot);
|
|
2438
|
+
}
|
|
2439
|
+
return undefined;
|
|
2440
|
+
}).catch((err) => {
|
|
2441
|
+
this.logger.debug('Async WorkspaceStorage save skipped.', err);
|
|
2442
|
+
});
|
|
1984
2443
|
} catch (err) {
|
|
1985
2444
|
this.logger.debug('WorkspaceStorage initialization skipped.', err);
|
|
1986
2445
|
}
|
|
@@ -2115,13 +2574,15 @@ int main() {
|
|
|
2115
2574
|
curEl.textContent = `Ln ${this.cursorPos.lineNumber || 1}, Col ${this.cursorPos.column || 1}`;
|
|
2116
2575
|
}
|
|
2117
2576
|
if (langEl) {
|
|
2118
|
-
langEl.textContent = this.lang === '
|
|
2119
|
-
? '
|
|
2120
|
-
: this.lang === '
|
|
2121
|
-
? '
|
|
2122
|
-
: this.lang === '
|
|
2123
|
-
? '
|
|
2124
|
-
:
|
|
2577
|
+
langEl.textContent = this.lang === 'sql'
|
|
2578
|
+
? (this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18')
|
|
2579
|
+
: this.lang === 'cpp'
|
|
2580
|
+
? 'C++20 (Clang/WASI)'
|
|
2581
|
+
: this.lang === 'py'
|
|
2582
|
+
? 'Python 3.12 (CPython WASI)'
|
|
2583
|
+
: this.lang === 'ts'
|
|
2584
|
+
? 'TypeScript 5.x'
|
|
2585
|
+
: 'JavaScript (CJS/ESM)';
|
|
2125
2586
|
}
|
|
2126
2587
|
this._updateTelemetryHud();
|
|
2127
2588
|
}
|
|
@@ -2132,13 +2593,23 @@ int main() {
|
|
|
2132
2593
|
...this.referenceFiles,
|
|
2133
2594
|
...(this.guidedConfig?.starterFiles || {})
|
|
2134
2595
|
};
|
|
2135
|
-
if (
|
|
2596
|
+
if (
|
|
2597
|
+
mode === 'guided' &&
|
|
2598
|
+
(
|
|
2599
|
+
this.guidedConfig?.starterFiles ||
|
|
2600
|
+
this.guidedConfig?.tsStarterFiles ||
|
|
2601
|
+
this.guidedConfig?.cppStarterFiles ||
|
|
2602
|
+
this.guidedConfig?.pyStarterFiles ||
|
|
2603
|
+
this.guidedConfig?.sqlStarterFiles
|
|
2604
|
+
)
|
|
2605
|
+
) {
|
|
2136
2606
|
return mapFilesToLanguage(
|
|
2137
2607
|
baseJsStarter,
|
|
2138
2608
|
lang,
|
|
2139
2609
|
this.guidedConfig?.tsStarterFiles,
|
|
2140
2610
|
this.guidedConfig?.cppStarterFiles,
|
|
2141
|
-
this.guidedConfig?.pyStarterFiles
|
|
2611
|
+
this.guidedConfig?.pyStarterFiles,
|
|
2612
|
+
this.guidedConfig?.sqlStarterFiles
|
|
2142
2613
|
);
|
|
2143
2614
|
}
|
|
2144
2615
|
return mapFilesToLanguage(
|
|
@@ -2146,7 +2617,8 @@ int main() {
|
|
|
2146
2617
|
lang,
|
|
2147
2618
|
this.guidedConfig?.tsSolutionFiles,
|
|
2148
2619
|
this.guidedConfig?.cppSolutionFiles,
|
|
2149
|
-
this.guidedConfig?.pySolutionFiles
|
|
2620
|
+
this.guidedConfig?.pySolutionFiles,
|
|
2621
|
+
this.guidedConfig?.sqlSolutionFiles
|
|
2150
2622
|
);
|
|
2151
2623
|
}
|
|
2152
2624
|
|
|
@@ -2168,8 +2640,29 @@ int main() {
|
|
|
2168
2640
|
return base;
|
|
2169
2641
|
}
|
|
2170
2642
|
|
|
2643
|
+
_isSingleFileSqlMode() {
|
|
2644
|
+
if (this.lang !== 'sql' || this._forceShowExplorer) return false;
|
|
2645
|
+
const codeFiles = Object.keys(this.files || {}).filter(
|
|
2646
|
+
f => !f.startsWith('.codelab/') && !/^readme\.md$/i.test(f)
|
|
2647
|
+
);
|
|
2648
|
+
return codeFiles.length <= 1;
|
|
2649
|
+
}
|
|
2650
|
+
|
|
2171
2651
|
_pickDefaultFile() {
|
|
2172
2652
|
const names = Object.keys(this.files);
|
|
2653
|
+
if (this.lang === 'sql') {
|
|
2654
|
+
if (this.guidedConfig?.mainFile) {
|
|
2655
|
+
const sqlMain = this.guidedConfig.mainFile.replace(/\.(js|ts|cpp|py)$/, '.sql');
|
|
2656
|
+
if (this.files[sqlMain]) return sqlMain;
|
|
2657
|
+
if (this.files[this.guidedConfig.mainFile]) return this.guidedConfig.mainFile;
|
|
2658
|
+
}
|
|
2659
|
+
if (this.files['query.sql']) return 'query.sql';
|
|
2660
|
+
if (this.files['solution.sql']) return 'solution.sql';
|
|
2661
|
+
if (this.files['main.sql']) return 'main.sql';
|
|
2662
|
+
if (this.files['schema.sql']) return 'schema.sql';
|
|
2663
|
+
const sqlImpl = names.find(f => /\.sql$/i.test(f) && !/test/i.test(f));
|
|
2664
|
+
return sqlImpl || names.find(f => /\.sql$/i.test(f)) || names.find(f => !f.endsWith('.md') && !f.startsWith('.codelab/')) || names[0] || '';
|
|
2665
|
+
}
|
|
2173
2666
|
if (this.lang === 'py') {
|
|
2174
2667
|
if (this.guidedConfig?.mainFile) {
|
|
2175
2668
|
const pyMain = this.guidedConfig.mainFile.replace(/\.(js|ts|cpp)$/, '.py');
|
|
@@ -2215,6 +2708,28 @@ int main() {
|
|
|
2215
2708
|
|
|
2216
2709
|
_findEntryFile(kind) {
|
|
2217
2710
|
const names = Object.keys(this.files);
|
|
2711
|
+
if (this.lang === 'sql') {
|
|
2712
|
+
if (kind === 'test') {
|
|
2713
|
+
if (this.explicitTestEntry) {
|
|
2714
|
+
const sqlTest = this.explicitTestEntry.replace(/\.(js|ts|cpp|py)$/, '.sql');
|
|
2715
|
+
if (this.files[sqlTest]) return sqlTest;
|
|
2716
|
+
if (this.files[this.explicitTestEntry]) return this.explicitTestEntry;
|
|
2717
|
+
}
|
|
2718
|
+
if (this.files['test.sql']) return 'test.sql';
|
|
2719
|
+
return names.find(f => /(^|\/)(test.*|.*_test)\.sql$/i.test(f)) || null;
|
|
2720
|
+
}
|
|
2721
|
+
if (this.explicitEntry) {
|
|
2722
|
+
const sqlEntry = this.explicitEntry.replace(/\.(js|ts|cpp|py)$/, '.sql');
|
|
2723
|
+
if (this.files[sqlEntry]) return sqlEntry;
|
|
2724
|
+
if (this.files[this.explicitEntry]) return this.explicitEntry;
|
|
2725
|
+
}
|
|
2726
|
+
return (this.activeFile && /\.sql$/i.test(this.activeFile) ? this.activeFile : null) ||
|
|
2727
|
+
(this.files['query.sql'] ? 'query.sql' : null) ||
|
|
2728
|
+
(this.files['solution.sql'] ? 'solution.sql' : null) ||
|
|
2729
|
+
(this.files['main.sql'] ? 'main.sql' : null) ||
|
|
2730
|
+
names.find(f => /\.sql$/i.test(f)) ||
|
|
2731
|
+
null;
|
|
2732
|
+
}
|
|
2218
2733
|
if (this.lang === 'py') {
|
|
2219
2734
|
if (kind === 'test') {
|
|
2220
2735
|
if (this.explicitTestEntry) {
|
|
@@ -2320,19 +2835,22 @@ int main() {
|
|
|
2320
2835
|
(this.enabledLanguages && this.enabledLanguages.size > 1)
|
|
2321
2836
|
);
|
|
2322
2837
|
if (!hasMulti) return '';
|
|
2838
|
+
const showJs = Boolean(!this.enabledLanguages || this.enabledLanguages.has('js'));
|
|
2323
2839
|
const showTs = Boolean(
|
|
2324
2840
|
!this.enabledLanguages ||
|
|
2325
2841
|
this.enabledLanguages.has('ts') ||
|
|
2326
|
-
!this.enabledLanguages.has('cpp')
|
|
2842
|
+
(!this.enabledLanguages.has('cpp') && !this.enabledLanguages.has('py') && !this.enabledLanguages.has('sql'))
|
|
2327
2843
|
);
|
|
2328
2844
|
const showCpp = Boolean(this.enabledLanguages && this.enabledLanguages.has('cpp'));
|
|
2329
2845
|
const showPy = Boolean(this.enabledLanguages && this.enabledLanguages.has('py'));
|
|
2846
|
+
const showSql = Boolean(this.enabledLanguages && this.enabledLanguages.has('sql'));
|
|
2330
2847
|
return `
|
|
2331
2848
|
<div class="codelab-lang-switch" role="group" aria-label="Language Selector">
|
|
2332
|
-
|
|
2849
|
+
${showJs ? `<button type="button" class="codelab-lang-btn ${this.lang === 'js' ? 'active' : ''}" data-cl-lang="js" data-lang="js" aria-pressed="${this.lang === 'js'}">JS</button>` : ''}
|
|
2333
2850
|
${showTs ? `<button type="button" class="codelab-lang-btn ${this.lang === 'ts' ? 'active' : ''}" data-cl-lang="ts" data-lang="ts" aria-pressed="${this.lang === 'ts'}">TS</button>` : ''}
|
|
2334
2851
|
${showCpp ? `<button type="button" class="codelab-lang-btn ${this.lang === 'cpp' ? 'active' : ''}" data-cl-lang="cpp" data-lang="cpp" aria-pressed="${this.lang === 'cpp'}">C++</button>` : ''}
|
|
2335
2852
|
${showPy ? `<button type="button" class="codelab-lang-btn ${this.lang === 'py' ? 'active' : ''}" data-cl-lang="py" data-lang="py" aria-pressed="${this.lang === 'py'}">PY</button>` : ''}
|
|
2853
|
+
${showSql ? `<button type="button" class="codelab-lang-btn ${this.lang === 'sql' ? 'active' : ''}" data-cl-lang="sql" data-lang="sql" aria-pressed="${this.lang === 'sql'}">SQL</button>` : ''}
|
|
2336
2854
|
</div>
|
|
2337
2855
|
`;
|
|
2338
2856
|
}
|
|
@@ -2383,17 +2901,36 @@ int main() {
|
|
|
2383
2901
|
const drawerTabs = this.container.querySelector('.codelab-drawer__tabs');
|
|
2384
2902
|
if (!drawerTabs) return;
|
|
2385
2903
|
|
|
2386
|
-
const
|
|
2387
|
-
const
|
|
2388
|
-
const hasWeb = this._hasWebContent();
|
|
2904
|
+
const isSingleSql = this._isSingleFileSqlMode();
|
|
2905
|
+
const showSqlTab = Boolean(this.lang === 'sql' || this.lastSqlResult);
|
|
2389
2906
|
const problemsCount = this._diagnosticsStore && typeof this._diagnosticsStore.getAll === 'function'
|
|
2390
2907
|
? this._diagnosticsStore.getAll().length
|
|
2391
2908
|
: 0;
|
|
2392
2909
|
|
|
2910
|
+
const appendDrawerTabHtml = (parent, pos, htmlSnippet) => {
|
|
2911
|
+
if (parent && typeof parent.insertAdjacentHTML === 'function') {
|
|
2912
|
+
parent.insertAdjacentHTML(pos, htmlSnippet);
|
|
2913
|
+
} else if (parent && typeof parent.innerHTML === 'string') {
|
|
2914
|
+
parent.innerHTML = pos === 'afterbegin' ? (htmlSnippet + parent.innerHTML) : (parent.innerHTML + htmlSnippet);
|
|
2915
|
+
}
|
|
2916
|
+
};
|
|
2917
|
+
|
|
2918
|
+
let sqlTab = drawerTabs.querySelector('[data-cl-drawertab="sql-results"]');
|
|
2919
|
+
if (!sqlTab && showSqlTab) {
|
|
2920
|
+
appendDrawerTabHtml(drawerTabs, 'afterbegin', `
|
|
2921
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'sql-results'}" class="codelab-drawer__tab ${this.drawerTab === 'sql-results' ? 'active' : ''}" data-cl-drawertab="sql-results" title="SQL Query Results & EXPLAIN Plan">
|
|
2922
|
+
${CL_ICONS.database}
|
|
2923
|
+
<span>Query Results</span>
|
|
2924
|
+
</button>
|
|
2925
|
+
`);
|
|
2926
|
+
} else if (sqlTab && sqlTab.style) {
|
|
2927
|
+
sqlTab.style.display = showSqlTab ? 'inline-flex' : 'none';
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2393
2930
|
let probTab = drawerTabs.querySelector('[data-cl-drawertab="problems"]');
|
|
2394
2931
|
if (!probTab) {
|
|
2395
2932
|
const termTab = drawerTabs.querySelector('[data-cl-drawertab="terminal"]');
|
|
2396
|
-
if (termTab) {
|
|
2933
|
+
if (termTab && typeof termTab.insertAdjacentHTML === 'function') {
|
|
2397
2934
|
termTab.insertAdjacentHTML('afterend', `
|
|
2398
2935
|
<button type="button" role="tab" aria-selected="${this.drawerTab === 'problems'}" class="codelab-drawer__tab ${this.drawerTab === 'problems' ? 'active' : ''}" data-cl-drawertab="problems" title="Compiler & Runtime Problems">
|
|
2399
2936
|
${CL_ICONS.warning}
|
|
@@ -2407,12 +2944,11 @@ int main() {
|
|
|
2407
2944
|
if (countSpan) countSpan.textContent = String(problemsCount);
|
|
2408
2945
|
}
|
|
2409
2946
|
|
|
2410
|
-
|
|
2411
2947
|
let stdinTab = drawerTabs.querySelector('[data-cl-drawertab="stdin"]');
|
|
2412
2948
|
if (!stdinTab) {
|
|
2413
2949
|
const testTab = drawerTabs.querySelector('[data-cl-drawertab="tests"]');
|
|
2414
2950
|
const afterTab = testTab || drawerTabs.querySelector('[data-cl-drawertab="problems"]') || drawerTabs.querySelector('[data-cl-drawertab="terminal"]');
|
|
2415
|
-
if (afterTab) {
|
|
2951
|
+
if (afterTab && typeof afterTab.insertAdjacentHTML === 'function') {
|
|
2416
2952
|
afterTab.insertAdjacentHTML('afterend', `
|
|
2417
2953
|
<button type="button" role="tab" aria-selected="${this.drawerTab === 'stdin'}" class="codelab-drawer__tab ${this.drawerTab === 'stdin' ? 'active' : ''}" data-cl-drawertab="stdin" title="Standard Input">
|
|
2418
2954
|
${CL_ICONS.keyboard}
|
|
@@ -2422,6 +2958,43 @@ int main() {
|
|
|
2422
2958
|
}
|
|
2423
2959
|
}
|
|
2424
2960
|
|
|
2961
|
+
let obsTab = drawerTabs.querySelector('[data-cl-drawertab="observability"]');
|
|
2962
|
+
if (!obsTab && this.kernel) {
|
|
2963
|
+
appendDrawerTabHtml(drawerTabs, 'beforeend', `
|
|
2964
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'observability'}" class="codelab-drawer__tab ${this.drawerTab === 'observability' ? 'active' : ''}" data-cl-drawertab="observability" title="Services, Settings & Event Telemetry">
|
|
2965
|
+
${CL_ICONS.activity}
|
|
2966
|
+
<span>Observability</span>
|
|
2967
|
+
</button>
|
|
2968
|
+
`);
|
|
2969
|
+
}
|
|
2970
|
+
|
|
2971
|
+
if (this.plugins && this.plugins.panels && typeof this.plugins.panels.values === 'function') {
|
|
2972
|
+
for (const panel of this.plugins.panels.values()) {
|
|
2973
|
+
if (!panel || !panel.id) continue;
|
|
2974
|
+
const existingPanelTab = drawerTabs.querySelector(`[data-cl-drawertab="${panel.id}"]`);
|
|
2975
|
+
if (!existingPanelTab) {
|
|
2976
|
+
appendDrawerTabHtml(drawerTabs, 'beforeend', `
|
|
2977
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === panel.id}" class="codelab-drawer__tab ${this.drawerTab === panel.id ? 'active' : ''}" data-cl-drawertab="${escapeHtml(panel.id)}">
|
|
2978
|
+
<span>${escapeHtml(panel.title || panel.id)}</span>
|
|
2979
|
+
</button>
|
|
2980
|
+
`);
|
|
2981
|
+
}
|
|
2982
|
+
}
|
|
2983
|
+
}
|
|
2984
|
+
|
|
2985
|
+
const noisyTabs = ['terminal', 'stdin', 'ports', 'preview', 'network', 'inspector'];
|
|
2986
|
+
for (const noisyId of noisyTabs) {
|
|
2987
|
+
const el = drawerTabs.querySelector(`[data-cl-drawertab="${noisyId}"]`);
|
|
2988
|
+
if (el && el.style) {
|
|
2989
|
+
el.style.display = isSingleSql ? 'none' : '';
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
const testsEl = drawerTabs.querySelector('[data-cl-drawertab="tests"]');
|
|
2993
|
+
if (testsEl && testsEl.style && isSingleSql && !this._findEntryFile('test')) {
|
|
2994
|
+
testsEl.style.display = 'none';
|
|
2995
|
+
} else if (testsEl && testsEl.style && !isSingleSql) {
|
|
2996
|
+
testsEl.style.display = '';
|
|
2997
|
+
}
|
|
2425
2998
|
}
|
|
2426
2999
|
|
|
2427
3000
|
// ── Render Workbench DOM ───────────────────────────────────────────────
|
|
@@ -2433,11 +3006,20 @@ int main() {
|
|
|
2433
3006
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
2434
3007
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
2435
3008
|
const isGuideCollapsed = !this.hasGuidedLab || this.mode === 'sandbox' || !this.steps.length;
|
|
3009
|
+
const isSingleSql = this._isSingleFileSqlMode();
|
|
3010
|
+
const showSqlTab = Boolean(this.lang === 'sql' || this.lastSqlResult);
|
|
3011
|
+
const pluginPanelsHtml = (this.plugins && this.plugins.panels && typeof this.plugins.panels.values === 'function')
|
|
3012
|
+
? Array.from(this.plugins.panels.values()).map((panel) => `
|
|
3013
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === panel.id}" class="codelab-drawer__tab ${this.drawerTab === panel.id ? 'active' : ''}" data-cl-drawertab="${escapeHtml(panel.id)}">
|
|
3014
|
+
<span>${escapeHtml(panel.title || panel.id)}</span>
|
|
3015
|
+
</button>
|
|
3016
|
+
`).join('')
|
|
3017
|
+
: '';
|
|
2436
3018
|
const shellVars = [`--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px`];
|
|
2437
3019
|
if (this.previewSplitWidth) shellVars.push(`--cl-preview-split-width:${Math.round(this.previewSplitWidth)}px`);
|
|
2438
3020
|
const explorerStyle = `style="${shellVars.join(';')}"`;
|
|
2439
3021
|
this.container.innerHTML = `
|
|
2440
|
-
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
3022
|
+
<div class="codelab codelab-workbench ${isGuideCollapsed ? 'guide-collapsed' : ''} ${isSingleSql ? 'is-sql-single-file' : ''}" id="codelab-${escapeHtml(this.labId)}" ${themeAttr} ${explorerStyle}>
|
|
2441
3023
|
<!-- Top Bar -->
|
|
2442
3024
|
<div class="codelab-topbar codelab-toolbar">
|
|
2443
3025
|
<div class="codelab-topbar__left">
|
|
@@ -2479,9 +3061,9 @@ int main() {
|
|
|
2479
3061
|
<span>Stop</span>
|
|
2480
3062
|
</button>
|
|
2481
3063
|
${(this.hasGuidedLab && this.mode === 'guided') ? `
|
|
2482
|
-
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="Run demo.js (⌘+Shift+Enter)">
|
|
3064
|
+
<button type="button" class="codelab-btn codelab-btn--run" data-cl-action="run-demo" title="${this.lang === 'sql' ? 'Run Query (⌘+Shift+Enter)' : 'Run demo.js (⌘+Shift+Enter)'}">
|
|
2483
3065
|
${CL_ICONS.play}
|
|
2484
|
-
<span
|
|
3066
|
+
<span>${this.lang === 'sql' ? 'Run Query' : 'Run Demo'}</span>
|
|
2485
3067
|
<span class="codelab-btn__kbd">⇧⌘↵</span>
|
|
2486
3068
|
</button>
|
|
2487
3069
|
<button type="button" class="codelab-btn codelab-btn--test" id="cl-primary-exec-btn" data-cl-action="verify-step" title="Verify Current Step (⌘+Enter)">
|
|
@@ -2491,9 +3073,9 @@ int main() {
|
|
|
2491
3073
|
</button>
|
|
2492
3074
|
` : `
|
|
2493
3075
|
<div class="codelab-btn-split">
|
|
2494
|
-
<button type="button" class="codelab-btn codelab-btn--run codelab-btn-split__main" id="cl-primary-exec-btn" data-cl-action="run-code" title="Run Code (⌘↵)">
|
|
3076
|
+
<button type="button" class="codelab-btn codelab-btn--run codelab-btn-split__main" id="cl-primary-exec-btn" data-cl-action="run-code" title="${this.lang === 'sql' ? 'Run SQL Query (⌘↵)' : 'Run Code (⌘↵)'}">
|
|
2495
3077
|
${CL_ICONS.play}
|
|
2496
|
-
<span
|
|
3078
|
+
<span>${this.lang === 'sql' ? 'Run SQL' : 'Run Code'}</span>
|
|
2497
3079
|
<span class="codelab-btn__kbd">⌘↵</span>
|
|
2498
3080
|
</button>
|
|
2499
3081
|
<button type="button" class="codelab-btn codelab-btn--run codelab-btn-split__trigger" id="cl-split-run-trigger" title="More Execution Options" aria-haspopup="true">
|
|
@@ -2506,6 +3088,11 @@ int main() {
|
|
|
2506
3088
|
<button type="button" class="codelab-split-menu__item" data-cl-action="run-active-file">
|
|
2507
3089
|
<span>▶ Run Active File (${escapeHtml(this.activeFile || 'active')})</span> <kbd style="opacity:0.6">⇧⌘↵</kbd>
|
|
2508
3090
|
</button>
|
|
3091
|
+
${this.lang === 'sql' ? `
|
|
3092
|
+
<button type="button" class="codelab-split-menu__item" data-cl-action="explain-sql">
|
|
3093
|
+
<span>⚡ Explain Query Plan</span>
|
|
3094
|
+
</button>
|
|
3095
|
+
` : ''}
|
|
2509
3096
|
${this._findEntryFile('test') ? `
|
|
2510
3097
|
<button type="button" class="codelab-split-menu__item" data-cl-action="run-tests">
|
|
2511
3098
|
<span>✓ Run Test Suite</span>
|
|
@@ -2526,18 +3113,21 @@ int main() {
|
|
|
2526
3113
|
<span class="codelab-toolbar__sep" aria-hidden="true"></span>
|
|
2527
3114
|
${this.hasGuidedLab ? `
|
|
2528
3115
|
<button type="button" class="codelab-btn codelab-btn--icon ${isGuideCollapsed ? '' : 'active'}" id="cl-toggle-guide-btn" data-cl-action="toggle-guide" title="Toggle Guide Panel" aria-label="Toggle Guide Panel" aria-pressed="${isGuideCollapsed ? 'false' : 'true'}">
|
|
2529
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18"/></svg>
|
|
3116
|
+
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M9 3v18"/></svg>
|
|
2530
3117
|
</button>
|
|
2531
3118
|
` : ''}
|
|
2532
3119
|
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-toggle-drawer-btn" data-cl-action="toggle-drawer" title="Toggle Terminal Drawer" aria-label="Toggle Terminal Drawer">
|
|
2533
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 15h18"/></svg>
|
|
3120
|
+
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="18" height="18" rx="2"/><path d="M3 15h18"/></svg>
|
|
3121
|
+
</button>
|
|
3122
|
+
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-settings-btn" data-cl-action="open-settings" title="Settings (⌘,)" aria-label="Open Settings">
|
|
3123
|
+
${CL_ICONS.settings}
|
|
2534
3124
|
</button>
|
|
2535
3125
|
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-fullscreen-btn" data-cl-action="toggle-fullscreen" title="Toggle Fullscreen IDE (Esc to exit)" aria-label="Toggle Fullscreen IDE">
|
|
2536
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>
|
|
3126
|
+
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>
|
|
2537
3127
|
</button>
|
|
2538
3128
|
${this.onClose ? `
|
|
2539
3129
|
<button type="button" class="codelab-btn codelab-btn--exit-lab codelab-btn--close-ide" id="cl-close-ide-btn" data-cl-action="close-lab" title="${escapeHtml(this.backLabel ? `Exit Lab (${this.backLabel})` : 'Exit Lab / Back to Build Guide')}" aria-label="Exit Lab">
|
|
2540
|
-
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
|
|
3130
|
+
<svg aria-hidden="true" width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/><polyline points="16 17 21 12 16 7"/><line x1="21" y1="12" x2="9" y2="12"/></svg>
|
|
2541
3131
|
<span class="codelab-btn__label">Exit Lab</span>
|
|
2542
3132
|
</button>
|
|
2543
3133
|
` : ''}
|
|
@@ -2559,7 +3149,7 @@ int main() {
|
|
|
2559
3149
|
<span>Architecture Brief</span>
|
|
2560
3150
|
</button>
|
|
2561
3151
|
<button type="button" class="codelab-guide__collapse-btn" data-cl-action="toggle-guide" title="Collapse sidebar" aria-label="Collapse sidebar">
|
|
2562
|
-
<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
3152
|
+
<svg aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
2563
3153
|
<polyline points="15 18 9 12 15 6"></polyline>
|
|
2564
3154
|
</svg>
|
|
2565
3155
|
</button>
|
|
@@ -2598,6 +3188,7 @@ int main() {
|
|
|
2598
3188
|
<div class="codelab-breadcrumbs" id="cl-breadcrumbs" aria-label="Editor Breadcrumbs"></div>
|
|
2599
3189
|
<div class="codelab-editor-wrap">
|
|
2600
3190
|
<div class="codelab-monaco-host" id="cl-monaco-host"></div>
|
|
3191
|
+
<div class="codelab-sql-host" id="cl-sql-editor-host" style="display:none"></div>
|
|
2601
3192
|
<div class="codelab-fallback-wrap" id="cl-fallback-wrap" style="display:none">
|
|
2602
3193
|
<div class="codelab-fallback-gutter" id="cl-fallback-gutter" aria-hidden="true">1</div>
|
|
2603
3194
|
<textarea class="codelab-fallback-editor" id="cl-fallback-editor" spellcheck="false" aria-label="Code Editor"></textarea>
|
|
@@ -2619,7 +3210,11 @@ int main() {
|
|
|
2619
3210
|
<div class="codelab-drawer codelab-bottom" id="cl-drawer">
|
|
2620
3211
|
<div class="codelab-drawer__bar">
|
|
2621
3212
|
<div class="codelab-drawer__tabs" role="tablist" aria-label="Execution Output Panels">
|
|
2622
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === '
|
|
3213
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'sql-results'}" class="codelab-drawer__tab ${this.drawerTab === 'sql-results' ? 'active' : ''}" data-cl-drawertab="sql-results" title="SQL Query Results & EXPLAIN Plan" style="display:${showSqlTab ? 'inline-flex' : 'none'}">
|
|
3214
|
+
${CL_ICONS.database}
|
|
3215
|
+
<span>Query Results</span>
|
|
3216
|
+
</button>
|
|
3217
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'terminal'}" class="codelab-drawer__tab ${this.drawerTab === 'terminal' ? 'active' : ''}" data-cl-drawertab="terminal" style="${isSingleSql ? 'display:none' : ''}">
|
|
2623
3218
|
${CL_ICONS.terminal}
|
|
2624
3219
|
<span>Terminal & REPL</span>
|
|
2625
3220
|
</button>
|
|
@@ -2628,40 +3223,47 @@ int main() {
|
|
|
2628
3223
|
<span>Problems</span>
|
|
2629
3224
|
<span class="codelab-badge" id="cl-problems-count" style="margin-left:4px;font-size:10px;padding:1px 5px;border-radius:10px;background:rgba(255,255,255,0.1);color:#fff;">${this._diagnosticsStore ? this._diagnosticsStore.getAll().length : 0}</span>
|
|
2630
3225
|
</button>
|
|
2631
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === 'tests'}" class="codelab-drawer__tab ${this.drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests">
|
|
3226
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'tests'}" class="codelab-drawer__tab ${this.drawerTab === 'tests' ? 'active' : ''}" data-cl-drawertab="tests" style="${(isSingleSql && !this._findEntryFile('test')) ? 'display:none' : ''}">
|
|
2632
3227
|
${CL_ICONS.check}
|
|
2633
3228
|
<span>Test Suite</span>
|
|
2634
3229
|
<span class="codelab-drawer__pill" id="cl-test-pill">Ready</span>
|
|
2635
3230
|
</button>
|
|
2636
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === 'stdin'}" class="codelab-drawer__tab ${this.drawerTab === 'stdin' ? 'active' : ''}" data-cl-drawertab="stdin" title="Standard Input">
|
|
3231
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'stdin'}" class="codelab-drawer__tab ${this.drawerTab === 'stdin' ? 'active' : ''}" data-cl-drawertab="stdin" title="Standard Input" style="${isSingleSql ? 'display:none' : ''}">
|
|
2637
3232
|
${CL_ICONS.keyboard}
|
|
2638
3233
|
<span>Stdin</span>
|
|
2639
3234
|
</button>
|
|
2640
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === 'ports'}" class="codelab-drawer__tab ${this.drawerTab === 'ports' ? 'active' : ''}" data-cl-drawertab="ports">
|
|
3235
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'ports'}" class="codelab-drawer__tab ${this.drawerTab === 'ports' ? 'active' : ''}" data-cl-drawertab="ports" style="${isSingleSql ? 'display:none' : ''}">
|
|
2641
3236
|
${CL_ICONS.radio}
|
|
2642
3237
|
<span>Ports</span>
|
|
2643
3238
|
<span class="codelab-drawer__pill" id="cl-ports-pill">${this.portTable && typeof this.portTable.listServers === 'function' ? this.portTable.listServers().length : 0} open</span>
|
|
2644
3239
|
</button>
|
|
2645
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === 'preview'}" class="codelab-drawer__tab ${this.drawerTab === 'preview' ? 'active' : ''}" data-cl-drawertab="preview" title="In-browser Web Preview">
|
|
3240
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'preview'}" class="codelab-drawer__tab ${this.drawerTab === 'preview' ? 'active' : ''}" data-cl-drawertab="preview" title="In-browser Web Preview" style="${isSingleSql ? 'display:none' : ''}">
|
|
2646
3241
|
${CL_ICONS.globe}
|
|
2647
3242
|
<span>Web Preview</span>
|
|
2648
3243
|
</button>
|
|
2649
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === 'network'}" class="codelab-drawer__tab ${this.drawerTab === 'network' ? 'active' : ''}" data-cl-drawertab="network">
|
|
3244
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'network'}" class="codelab-drawer__tab ${this.drawerTab === 'network' ? 'active' : ''}" data-cl-drawertab="network" style="${isSingleSql ? 'display:none' : ''}">
|
|
2650
3245
|
${CL_ICONS.activity}
|
|
2651
3246
|
<span>Network</span>
|
|
2652
3247
|
<span class="codelab-drawer__pill" id="cl-network-pill">${(this.lastHttpTrace || []).length} reqs</span>
|
|
2653
3248
|
</button>
|
|
2654
|
-
<button type="button" role="tab" aria-selected="${this.drawerTab === 'inspector'}" class="codelab-drawer__tab ${this.drawerTab === 'inspector' ? 'active' : ''}" data-cl-drawertab="inspector">
|
|
3249
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'inspector'}" class="codelab-drawer__tab ${this.drawerTab === 'inspector' ? 'active' : ''}" data-cl-drawertab="inspector" style="${isSingleSql ? 'display:none' : ''}">
|
|
2655
3250
|
${CL_ICONS.database}
|
|
2656
3251
|
<span>Virtual Disk & HTTP</span>
|
|
2657
3252
|
<span class="codelab-drawer__pill" id="cl-vfs-pill">0 files</span>
|
|
2658
3253
|
</button>
|
|
3254
|
+
${this.kernel ? `
|
|
3255
|
+
<button type="button" role="tab" aria-selected="${this.drawerTab === 'observability'}" class="codelab-drawer__tab ${this.drawerTab === 'observability' ? 'active' : ''}" data-cl-drawertab="observability" title="Services, Settings & Event Telemetry">
|
|
3256
|
+
${CL_ICONS.activity}
|
|
3257
|
+
<span>Observability</span>
|
|
3258
|
+
</button>
|
|
3259
|
+
` : ''}
|
|
3260
|
+
${pluginPanelsHtml}
|
|
2659
3261
|
</div>
|
|
2660
3262
|
<div class="codelab-hud-pill" id="cl-telemetry-hud" style="display:none;" title="Last Execution Telemetry"></div>
|
|
2661
3263
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
2662
|
-
<div class="codelab-terminal-sessions" id="cl-terminal-sessions"></div>
|
|
2663
|
-
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-new-terminal-btn" data-cl-action="new-terminal-session" title="New Terminal Session" aria-label="New Terminal Session" style="padding:2px 6px;font-size:11px;">+</button>
|
|
2664
|
-
<button type="button" class="codelab-btn codelab-btn--icon codelab-btn--ctrl-c" id="cl-ctrl-c-btn" data-cl-action="interrupt" title="Send Ctrl+C — interrupt a running command" aria-label="Send Ctrl+C interrupt" style="padding:2px 8px;font-size:11px;font-family:var(--cl-font-mono);">Ctrl+C</button>
|
|
3264
|
+
<div class="codelab-terminal-sessions" id="cl-terminal-sessions" style="${isSingleSql ? 'display:none' : ''}"></div>
|
|
3265
|
+
<button type="button" class="codelab-btn codelab-btn--icon" id="cl-new-terminal-btn" data-cl-action="new-terminal-session" title="New Terminal Session" aria-label="New Terminal Session" style="padding:2px 6px;font-size:11px;${isSingleSql ? 'display:none;' : ''}">+</button>
|
|
3266
|
+
<button type="button" class="codelab-btn codelab-btn--icon codelab-btn--ctrl-c" id="cl-ctrl-c-btn" data-cl-action="interrupt" title="Send Ctrl+C — interrupt a running command" aria-label="Send Ctrl+C interrupt" style="padding:2px 8px;font-size:11px;font-family:var(--cl-font-mono);${isSingleSql ? 'display:none;' : ''}">Ctrl+C</button>
|
|
2665
3267
|
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="clear-terminal" title="Clear Output" style="padding:2px 6px;font-size:11px;">Clear</button>
|
|
2666
3268
|
<button type="button" class="codelab-btn codelab-btn--icon" data-cl-action="toggle-drawer" title="Minimize/Expand Drawer" aria-label="Minimize or Expand Drawer" style="padding:2px 6px;font-size:11px;">${CL_ICONS.chevronsUpDown}</button>
|
|
2667
3269
|
</div>
|
|
@@ -2676,7 +3278,7 @@ int main() {
|
|
|
2676
3278
|
<div class="codelab-statusbar__left">
|
|
2677
3279
|
<span class="codelab-statusbar__item" id="cl-status-runtime">
|
|
2678
3280
|
<span class="codelab-statusbar__dot" id="cl-status-dot"></span>
|
|
2679
|
-
<span id="cl-status-text"
|
|
3281
|
+
<span id="cl-status-text">${escapeHtml(this.runtimeStatusText || 'Node.js v22 Worker · Idle')}</span>
|
|
2680
3282
|
</span>
|
|
2681
3283
|
<span class="codelab-statusbar__sep">·</span>
|
|
2682
3284
|
<span class="codelab-statusbar__item" id="cl-status-file">${escapeHtml(this.activeFile || 'workspace')}</span>
|
|
@@ -2688,7 +3290,7 @@ int main() {
|
|
|
2688
3290
|
<span class="codelab-statusbar__sep">·</span>
|
|
2689
3291
|
<span class="codelab-statusbar__item">UTF-8</span>
|
|
2690
3292
|
<span class="codelab-statusbar__sep">·</span>
|
|
2691
|
-
<span class="codelab-statusbar__item" id="cl-status-lang">${this.lang === 'cpp' ? 'C++20 (Clang/WASI)' : this.lang === 'py' ? 'Python 3.12 (CPython WASI)' : this.lang === 'ts' ? 'TypeScript 5.x' : 'JavaScript (CJS/ESM)'}</span>
|
|
3293
|
+
<span class="codelab-statusbar__item" id="cl-status-lang">${this.lang === 'sql' ? (this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18') : this.lang === 'cpp' ? 'C++20 (Clang/WASI)' : this.lang === 'py' ? 'Python 3.12 (CPython WASI)' : this.lang === 'ts' ? 'TypeScript 5.x' : 'JavaScript (CJS/ESM)'}</span>
|
|
2692
3294
|
</div>
|
|
2693
3295
|
</footer>
|
|
2694
3296
|
|
|
@@ -2711,6 +3313,14 @@ int main() {
|
|
|
2711
3313
|
|
|
2712
3314
|
_resolveStepTargetFile(rawTarget) {
|
|
2713
3315
|
if (!rawTarget) return '';
|
|
3316
|
+
if (this.lang === 'sql') {
|
|
3317
|
+
const asSql = rawTarget.replace(/\.(js|ts|cpp|py)$/, '.sql');
|
|
3318
|
+
if (this.files && this.files[asSql] !== undefined) return asSql;
|
|
3319
|
+
if (this.files && this.files[rawTarget] !== undefined) return rawTarget;
|
|
3320
|
+
if (this.files && this.files['query.sql'] !== undefined) return 'query.sql';
|
|
3321
|
+
if (this.files && this.files['solution.sql'] !== undefined) return 'solution.sql';
|
|
3322
|
+
return asSql;
|
|
3323
|
+
}
|
|
2714
3324
|
if (this.lang === 'cpp') {
|
|
2715
3325
|
const asHpp = rawTarget.replace(/\.(js|ts)$/, '.hpp');
|
|
2716
3326
|
if (this.files && this.files[asHpp] !== undefined) return asHpp;
|
|
@@ -3109,6 +3719,10 @@ int main() {
|
|
|
3109
3719
|
}
|
|
3110
3720
|
|
|
3111
3721
|
_renderFileLists() {
|
|
3722
|
+
const shell = this.container.querySelector('.codelab');
|
|
3723
|
+
if (shell && shell.classList) {
|
|
3724
|
+
shell.classList.toggle('is-sql-single-file', this._isSingleFileSqlMode());
|
|
3725
|
+
}
|
|
3112
3726
|
const explorerEl = this.container.querySelector('#cl-explorer-list');
|
|
3113
3727
|
const tabsEl = this.container.querySelector('#cl-file-tabs');
|
|
3114
3728
|
const explorerLangEl = this.container.querySelector('#cl-explorer-lang');
|
|
@@ -3129,20 +3743,34 @@ int main() {
|
|
|
3129
3743
|
for (const fNode of sortedFolders) {
|
|
3130
3744
|
const isCollapsed = this.collapsedFolders.has(fNode.fullPath);
|
|
3131
3745
|
const indent = depth * 14 + 10;
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
<div class="codelab-
|
|
3140
|
-
<
|
|
3141
|
-
<
|
|
3142
|
-
<button type="button" class="codelab-node-action" data-cl-action="delete-folder" data-cl-folder="${escapeHtml(fNode.fullPath)}" title="Delete Folder">${CL_ICONS.trash}</button>
|
|
3746
|
+
const isRenamingFolder = Boolean(
|
|
3747
|
+
this.renamingItem &&
|
|
3748
|
+
this.renamingItem.type === 'folder' &&
|
|
3749
|
+
this.renamingItem.targetPath === fNode.fullPath
|
|
3750
|
+
);
|
|
3751
|
+
if (isRenamingFolder) {
|
|
3752
|
+
treeHtml += `
|
|
3753
|
+
<div class="codelab-tree-create-row codelab-tree-rename-row" style="padding-left: ${indent}px;">
|
|
3754
|
+
<span class="codelab-tree-create-icon">${CL_ICONS.folder}</span>
|
|
3755
|
+
<input type="text" id="cl-tree-rename-input" class="codelab-tree-input" value="${escapeHtml(fNode.name)}" aria-label="Rename folder ${escapeHtml(fNode.name)}" autocomplete="off" spellcheck="false" />
|
|
3143
3756
|
</div>
|
|
3144
|
-
|
|
3145
|
-
|
|
3757
|
+
`;
|
|
3758
|
+
} else {
|
|
3759
|
+
treeHtml += `
|
|
3760
|
+
<div class="codelab-folder-item ${isCollapsed ? 'collapsed' : 'expanded'}" data-cl-folder="${escapeHtml(fNode.fullPath)}" data-folder="${escapeHtml(fNode.fullPath)}" data-cl-drop-folder="${escapeHtml(fNode.fullPath)}" data-depth="${depth}" style="padding-left: ${indent}px;">
|
|
3761
|
+
<button type="button" class="codelab-chevron" data-cl-action="toggle-folder" data-cl-folder="${escapeHtml(fNode.fullPath)}" title="${isCollapsed ? 'Expand folder' : 'Collapse folder'}" aria-label="${isCollapsed ? 'Expand folder' : 'Collapse folder'}">
|
|
3762
|
+
${isCollapsed ? CL_ICONS.chevronRight : CL_ICONS.chevronDown}
|
|
3763
|
+
</button>
|
|
3764
|
+
<span class="codelab-folder-icon">${CL_ICONS.folder}</span>
|
|
3765
|
+
<span class="codelab-folder-name" title="${escapeHtml(fNode.name)}">${escapeHtml(fNode.name)}</span>
|
|
3766
|
+
<div class="codelab-node-actions">
|
|
3767
|
+
<button type="button" class="codelab-node-action" data-cl-action="new-file-folder" data-cl-folder="${escapeHtml(fNode.fullPath)}" title="New File in ${escapeHtml(fNode.name)}">${CL_ICONS.plus}</button>
|
|
3768
|
+
<button type="button" class="codelab-node-action" data-cl-action="new-folder-folder" data-cl-folder="${escapeHtml(fNode.fullPath)}" title="New Folder in ${escapeHtml(fNode.name)}">${CL_ICONS.folder}</button>
|
|
3769
|
+
<button type="button" class="codelab-node-action" data-cl-action="delete-folder" data-cl-folder="${escapeHtml(fNode.fullPath)}" title="Delete Folder">${CL_ICONS.trash}</button>
|
|
3770
|
+
</div>
|
|
3771
|
+
</div>
|
|
3772
|
+
`;
|
|
3773
|
+
}
|
|
3146
3774
|
|
|
3147
3775
|
if (this.creatingItem && this.creatingItem.parentFolder === fNode.fullPath && !isCollapsed) {
|
|
3148
3776
|
const createIndent = (depth + 1) * 14 + 10;
|
|
@@ -3162,17 +3790,31 @@ int main() {
|
|
|
3162
3790
|
const sortedFiles = Array.from(node.files.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
3163
3791
|
for (const [baseName, fullPath] of sortedFiles) {
|
|
3164
3792
|
const isActive = fullPath === this.activeFile;
|
|
3165
|
-
const badge = fullPath.endsWith('.md') ? 'DOC' : fullPath.endsWith('.json') ? 'PKG' : /(^|\/)test\./i.test(fullPath) ? 'TEST' : /(^|\/)(demo|main)\./i.test(fullPath) ? 'DEMO' : /\.(hpp|h)$/i.test(fullPath) ? 'HDR' : 'SRC';
|
|
3166
|
-
const ext = /\.(cpp|cc|cxx|hpp|h)$/i.test(fullPath) ? 'cpp' : fullPath.endsWith('.ts') ? 'ts' : fullPath.endsWith('.js') ? 'js' : fullPath.endsWith('.json') ? 'json' : fullPath.endsWith('.md') ? 'md' : 'txt';
|
|
3167
|
-
const fileIcon = ext === 'json' ? CL_ICONS.database : ext === 'md' ? CL_ICONS.book : CL_ICONS.file;
|
|
3793
|
+
const badge = fullPath.endsWith('.md') ? 'DOC' : fullPath.endsWith('.json') ? 'PKG' : /\.sql$/i.test(fullPath) ? 'SQL' : /(^|\/)test\./i.test(fullPath) ? 'TEST' : /(^|\/)(demo|main)\./i.test(fullPath) ? 'DEMO' : /\.(hpp|h)$/i.test(fullPath) ? 'HDR' : 'SRC';
|
|
3794
|
+
const ext = /\.(cpp|cc|cxx|hpp|h)$/i.test(fullPath) ? 'cpp' : /\.sql$/i.test(fullPath) ? 'sql' : fullPath.endsWith('.py') ? 'py' : fullPath.endsWith('.ts') ? 'ts' : fullPath.endsWith('.js') ? 'js' : fullPath.endsWith('.json') ? 'json' : fullPath.endsWith('.md') ? 'md' : 'txt';
|
|
3795
|
+
const fileIcon = (ext === 'json' || ext === 'sql') ? CL_ICONS.database : ext === 'md' ? CL_ICONS.book : CL_ICONS.file;
|
|
3168
3796
|
const indent = depth * 14 + 10;
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3797
|
+
const isRenamingFile = Boolean(
|
|
3798
|
+
this.renamingItem &&
|
|
3799
|
+
this.renamingItem.type === 'file' &&
|
|
3800
|
+
this.renamingItem.targetPath === fullPath
|
|
3801
|
+
);
|
|
3802
|
+
if (isRenamingFile) {
|
|
3803
|
+
treeHtml += `
|
|
3804
|
+
<div class="codelab-tree-create-row codelab-tree-rename-row" style="padding-left: ${indent}px;">
|
|
3805
|
+
<span class="codelab-tree-create-icon">${fileIcon}</span>
|
|
3806
|
+
<input type="text" id="cl-tree-rename-input" class="codelab-tree-input" value="${escapeHtml(baseName)}" aria-label="Rename file ${escapeHtml(baseName)}" autocomplete="off" spellcheck="false" />
|
|
3807
|
+
</div>
|
|
3808
|
+
`;
|
|
3809
|
+
} else {
|
|
3810
|
+
treeHtml += `
|
|
3811
|
+
<button type="button" class="codelab-file-item ${isActive ? 'active' : ''}" draggable="true" data-cl-file="${escapeHtml(fullPath)}" data-file="${escapeHtml(fullPath)}" data-depth="${depth}" style="padding-left: ${indent}px;">
|
|
3812
|
+
<span class="codelab-file-icon">${fileIcon}</span>
|
|
3813
|
+
<span class="codelab-file-name" title="${escapeHtml(baseName)}">${escapeHtml(baseName)}</span>
|
|
3814
|
+
<span class="codelab-file-badge">${badge}</span>
|
|
3815
|
+
</button>
|
|
3816
|
+
`;
|
|
3817
|
+
}
|
|
3176
3818
|
}
|
|
3177
3819
|
};
|
|
3178
3820
|
|
|
@@ -3252,14 +3894,19 @@ int main() {
|
|
|
3252
3894
|
// Tree inline creation input listeners
|
|
3253
3895
|
const treeInput = explorerEl.querySelector('#cl-tree-create-input');
|
|
3254
3896
|
if (treeInput) {
|
|
3897
|
+
let createSettled = false;
|
|
3255
3898
|
treeInput.focus();
|
|
3256
3899
|
treeInput.addEventListener('keydown', e => {
|
|
3257
3900
|
if (e.key === 'Escape') {
|
|
3258
3901
|
e.stopPropagation();
|
|
3902
|
+
createSettled = true;
|
|
3259
3903
|
this.creatingItem = null;
|
|
3260
3904
|
this._renderFileLists();
|
|
3261
3905
|
} else if (e.key === 'Enter') {
|
|
3262
3906
|
e.preventDefault();
|
|
3907
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
3908
|
+
if (createSettled) return;
|
|
3909
|
+
createSettled = true;
|
|
3263
3910
|
const val = (treeInput.value || '').trim();
|
|
3264
3911
|
const item = this.creatingItem;
|
|
3265
3912
|
this.creatingItem = null;
|
|
@@ -3276,28 +3923,98 @@ int main() {
|
|
|
3276
3923
|
}
|
|
3277
3924
|
});
|
|
3278
3925
|
treeInput.addEventListener('blur', () => {
|
|
3926
|
+
if (createSettled) return;
|
|
3927
|
+
createSettled = true;
|
|
3279
3928
|
if (this.creatingItem) {
|
|
3929
|
+
const val = (treeInput.value || '').trim();
|
|
3930
|
+
const item = this.creatingItem;
|
|
3280
3931
|
this.creatingItem = null;
|
|
3281
|
-
|
|
3932
|
+
if (val && item) {
|
|
3933
|
+
const full = item.parentFolder ? `${item.parentFolder}/${val}` : val;
|
|
3934
|
+
if (item.type === 'folder') {
|
|
3935
|
+
this.createFolder(full);
|
|
3936
|
+
} else {
|
|
3937
|
+
this.createFile(full);
|
|
3938
|
+
}
|
|
3939
|
+
} else {
|
|
3940
|
+
this._renderFileLists();
|
|
3941
|
+
}
|
|
3282
3942
|
}
|
|
3283
3943
|
});
|
|
3284
3944
|
}
|
|
3285
3945
|
|
|
3286
|
-
//
|
|
3287
|
-
const
|
|
3288
|
-
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3946
|
+
// Tree inline rename input listeners
|
|
3947
|
+
const renameInput = explorerEl.querySelector('#cl-tree-rename-input');
|
|
3948
|
+
if (renameInput) {
|
|
3949
|
+
let renameSettled = false;
|
|
3950
|
+
renameInput.focus();
|
|
3951
|
+
if (typeof renameInput.setSelectionRange === 'function') {
|
|
3952
|
+
try {
|
|
3953
|
+
const val = renameInput.value || '';
|
|
3954
|
+
const dotIdx = this.renamingItem && this.renamingItem.type === 'file' ? val.lastIndexOf('.') : -1;
|
|
3955
|
+
renameInput.setSelectionRange(0, dotIdx > 0 ? dotIdx : val.length);
|
|
3956
|
+
} catch (err) {
|
|
3957
|
+
_bootDebug('renameInput.setSelectionRange failed', err);
|
|
3958
|
+
}
|
|
3959
|
+
}
|
|
3960
|
+
const commitRename = () => {
|
|
3961
|
+
if (renameSettled) return;
|
|
3962
|
+
renameSettled = true;
|
|
3963
|
+
const rawVal = (renameInput.value || '').trim().replace(/^\/+|\/+$/g, '');
|
|
3964
|
+
const item = this.renamingItem;
|
|
3965
|
+
this.renamingItem = null;
|
|
3966
|
+
if (!rawVal || !item) {
|
|
3967
|
+
this._renderFileLists();
|
|
3968
|
+
return;
|
|
3969
|
+
}
|
|
3970
|
+
const lastSlash = item.targetPath.lastIndexOf('/');
|
|
3971
|
+
const parentDir = lastSlash > 0 ? item.targetPath.slice(0, lastSlash) : '';
|
|
3972
|
+
const nextPath = rawVal.includes('/')
|
|
3973
|
+
? rawVal
|
|
3974
|
+
: (parentDir ? `${parentDir}/${rawVal}` : rawVal);
|
|
3975
|
+
if (nextPath === item.targetPath) {
|
|
3976
|
+
this._renderFileLists();
|
|
3977
|
+
return;
|
|
3978
|
+
}
|
|
3979
|
+
const ok = item.type === 'folder'
|
|
3980
|
+
? this.renameFolder(item.targetPath, nextPath)
|
|
3981
|
+
: this.renameFile(item.targetPath, nextPath);
|
|
3982
|
+
if (!ok) {
|
|
3983
|
+
this._renderFileLists();
|
|
3984
|
+
}
|
|
3985
|
+
};
|
|
3986
|
+
renameInput.addEventListener('keydown', e => {
|
|
3987
|
+
if (e.key === 'Escape') {
|
|
3988
|
+
e.stopPropagation();
|
|
3989
|
+
renameSettled = true;
|
|
3990
|
+
this.renamingItem = null;
|
|
3991
|
+
this._renderFileLists();
|
|
3992
|
+
} else if (e.key === 'Enter') {
|
|
3993
|
+
e.preventDefault();
|
|
3994
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
3995
|
+
commitRename();
|
|
3996
|
+
}
|
|
3997
|
+
});
|
|
3998
|
+
renameInput.addEventListener('blur', () => {
|
|
3999
|
+
commitRename();
|
|
4000
|
+
});
|
|
4001
|
+
}
|
|
4002
|
+
|
|
4003
|
+
// Tabs rendering
|
|
4004
|
+
const openTabs = Array.isArray(this.openTabs) ? this.openTabs : [];
|
|
4005
|
+
const tabsHtml = openTabs.map(f => {
|
|
4006
|
+
const isActive = f === this.activeFile;
|
|
4007
|
+
const ext = /\.(cpp|cc|cxx|hpp|h)$/i.test(f) ? 'cpp' : /\.sql$/i.test(f) ? 'sql' : f.endsWith('.py') ? 'py' : f.endsWith('.ts') ? 'ts' : f.endsWith('.js') ? 'js' : f.endsWith('.json') ? 'json' : f.endsWith('.md') ? 'md' : 'txt';
|
|
4008
|
+
return `
|
|
4009
|
+
<div role="tab" tabindex="0" aria-selected="${isActive}" class="codelab-tab ${isActive ? 'active' : ''}" data-cl-file="${escapeHtml(f)}" data-tab-file="${escapeHtml(f)}">
|
|
4010
|
+
<span class="codelab-tab__ext codelab-tab__ext--${ext}">${ext === 'cpp' ? 'C++' : ext.toUpperCase()}</span>
|
|
4011
|
+
<span class="codelab-tab__label">${escapeHtml(f)}</span>
|
|
4012
|
+
<button type="button" class="codelab-tab__close" data-action="close-tab" data-cl-file="${escapeHtml(f)}" title="Close ${escapeHtml(f)}" aria-label="Close ${escapeHtml(f)}">×</button>
|
|
4013
|
+
</div>
|
|
4014
|
+
`;
|
|
4015
|
+
}).join('');
|
|
4016
|
+
|
|
4017
|
+
const newFileControl = this.isCreatingFile
|
|
3301
4018
|
? `<form class="codelab-new-file-form" id="cl-new-file-form">
|
|
3302
4019
|
<input type="text" class="codelab-new-file-input" id="cl-new-file-input" placeholder="helper.${this.lang}" autocomplete="off" spellcheck="false" aria-label="New file name" />
|
|
3303
4020
|
</form>`
|
|
@@ -3427,7 +4144,97 @@ int main() {
|
|
|
3427
4144
|
}
|
|
3428
4145
|
|
|
3429
4146
|
renameFile(oldPath, newPath) {
|
|
3430
|
-
|
|
4147
|
+
const ok = this.moveFile(oldPath, newPath);
|
|
4148
|
+
if (ok) {
|
|
4149
|
+
this._syncFilesToShellVfs();
|
|
4150
|
+
this._emitEvent('codelab:file-rename', { labId: this.labId, oldPath, newPath });
|
|
4151
|
+
}
|
|
4152
|
+
return ok;
|
|
4153
|
+
}
|
|
4154
|
+
|
|
4155
|
+
movePath(sourcePath, targetFolder = '') {
|
|
4156
|
+
const cleanSrc = String(sourcePath || '').trim().replace(/^\/+|\/+$/g, '');
|
|
4157
|
+
const cleanDest = String(targetFolder || '').trim().replace(/^\/+|\/+$/g, '');
|
|
4158
|
+
if (!cleanSrc) return false;
|
|
4159
|
+
const allFolders = this._listWorkspaceFolders();
|
|
4160
|
+
if (allFolders.includes(cleanSrc)) {
|
|
4161
|
+
const baseName = cleanSrc.split('/').pop();
|
|
4162
|
+
const nextFolder = cleanDest ? `${cleanDest}/${baseName}` : baseName;
|
|
4163
|
+
if (nextFolder === cleanSrc || nextFolder.startsWith(cleanSrc + '/')) return false;
|
|
4164
|
+
return this.renameFolder(cleanSrc, nextFolder);
|
|
4165
|
+
}
|
|
4166
|
+
return this.moveFile(cleanSrc, cleanDest);
|
|
4167
|
+
}
|
|
4168
|
+
|
|
4169
|
+
startInlineCreate(type = 'file', folderPrefix = '') {
|
|
4170
|
+
const kind = type === 'folder' ? 'folder' : 'file';
|
|
4171
|
+
const cleanFolder = String(folderPrefix || '').trim().replace(/^\/+|\/+$/g, '');
|
|
4172
|
+
if (cleanFolder) {
|
|
4173
|
+
const parts = cleanFolder.split('/');
|
|
4174
|
+
let cur = '';
|
|
4175
|
+
for (const p of parts) {
|
|
4176
|
+
cur = cur ? `${cur}/${p}` : p;
|
|
4177
|
+
this.folders.add(cur);
|
|
4178
|
+
this.collapsedFolders.delete(cur);
|
|
4179
|
+
}
|
|
4180
|
+
if (this.explorerFolder && cleanFolder !== this.explorerFolder && !cleanFolder.startsWith(this.explorerFolder + '/')) {
|
|
4181
|
+
this.explorerFolder = '';
|
|
4182
|
+
}
|
|
4183
|
+
}
|
|
4184
|
+
this.renamingItem = null;
|
|
4185
|
+
this.isCreatingFile = false;
|
|
4186
|
+
this.creatingItem = {
|
|
4187
|
+
type: kind,
|
|
4188
|
+
parentFolder: cleanFolder || (this.explorerFolder || '')
|
|
4189
|
+
};
|
|
4190
|
+
this._renderFileLists();
|
|
4191
|
+
}
|
|
4192
|
+
|
|
4193
|
+
startInlineRename(typeOrPath, maybeTargetOrIsFolder) {
|
|
4194
|
+
let kind = 'file';
|
|
4195
|
+
let rawTarget = '';
|
|
4196
|
+
if ((typeOrPath === 'file' || typeOrPath === 'folder') && typeof maybeTargetOrIsFolder === 'string') {
|
|
4197
|
+
kind = typeOrPath;
|
|
4198
|
+
rawTarget = maybeTargetOrIsFolder;
|
|
4199
|
+
} else {
|
|
4200
|
+
rawTarget = String(typeOrPath || '');
|
|
4201
|
+
const normalizedProbe = rawTarget.trim().replace(/^\/+|\/+$/g, '');
|
|
4202
|
+
if (typeof maybeTargetOrIsFolder === 'boolean') {
|
|
4203
|
+
kind = maybeTargetOrIsFolder ? 'folder' : 'file';
|
|
4204
|
+
} else if (this._listWorkspaceFolders().includes(normalizedProbe) && this.files[normalizedProbe] === undefined) {
|
|
4205
|
+
kind = 'folder';
|
|
4206
|
+
} else {
|
|
4207
|
+
kind = 'file';
|
|
4208
|
+
}
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
const cleanTarget = String(rawTarget || '').trim().replace(/^\/+|\/+$/g, '');
|
|
4212
|
+
if (!cleanTarget) return;
|
|
4213
|
+
if (kind === 'file' && this.files[cleanTarget] === undefined) return;
|
|
4214
|
+
if (kind === 'folder' && !this._listWorkspaceFolders().includes(cleanTarget)) return;
|
|
4215
|
+
|
|
4216
|
+
const parts = cleanTarget.split('/');
|
|
4217
|
+
let cur = '';
|
|
4218
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
4219
|
+
cur = cur ? `${cur}/${parts[i]}` : parts[i];
|
|
4220
|
+
this.collapsedFolders.delete(cur);
|
|
4221
|
+
}
|
|
4222
|
+
if (this.explorerFolder && cleanTarget !== this.explorerFolder && !cleanTarget.startsWith(this.explorerFolder + '/')) {
|
|
4223
|
+
this.explorerFolder = '';
|
|
4224
|
+
}
|
|
4225
|
+
|
|
4226
|
+
this.creatingItem = null;
|
|
4227
|
+
this.isCreatingFile = false;
|
|
4228
|
+
this.renamingItem = { type: kind, targetPath: cleanTarget };
|
|
4229
|
+
this._renderFileLists();
|
|
4230
|
+
}
|
|
4231
|
+
|
|
4232
|
+
promptNewFile(folderPrefix = '') {
|
|
4233
|
+
this.startInlineCreate('file', folderPrefix);
|
|
4234
|
+
}
|
|
4235
|
+
|
|
4236
|
+
promptNewFolder(folderPrefix = '') {
|
|
4237
|
+
this.startInlineCreate('folder', folderPrefix);
|
|
3431
4238
|
}
|
|
3432
4239
|
|
|
3433
4240
|
renameFolder(oldFolder, newFolder) {
|
|
@@ -3544,13 +4351,13 @@ int main() {
|
|
|
3544
4351
|
|
|
3545
4352
|
createFile(rawName, initialContent = null) {
|
|
3546
4353
|
let clean = String(rawName).trim().replace(/^\/+/, '');
|
|
3547
|
-
if (!clean) return;
|
|
3548
|
-
if (!/\.(js|ts|cpp|cc|cxx|hpp|h|json|md|txt)$/i.test(clean) && !clean.includes('.')) {
|
|
4354
|
+
if (!clean) return null;
|
|
4355
|
+
if (!/\.(js|ts|jsx|tsx|mjs|cjs|py|cpp|cc|cxx|hpp|h|html|css|json|md|txt|sh|sql|yaml|yml)$/i.test(clean) && !clean.includes('.')) {
|
|
3549
4356
|
clean += `.${this.lang}`;
|
|
3550
4357
|
}
|
|
3551
4358
|
if (this.files[clean] !== undefined) {
|
|
3552
4359
|
this.openFile(clean);
|
|
3553
|
-
return;
|
|
4360
|
+
return clean;
|
|
3554
4361
|
}
|
|
3555
4362
|
const parts = clean.split('/');
|
|
3556
4363
|
let cur = '';
|
|
@@ -3563,16 +4370,22 @@ int main() {
|
|
|
3563
4370
|
} else {
|
|
3564
4371
|
this.files[clean] = clean.endsWith('.json')
|
|
3565
4372
|
? '{\n "name": "' + this.labId + '",\n "dependencies": {}\n}\n'
|
|
3566
|
-
:
|
|
3567
|
-
? `#
|
|
3568
|
-
:
|
|
3569
|
-
? `#
|
|
3570
|
-
:
|
|
4373
|
+
: clean.endsWith('.py')
|
|
4374
|
+
? `# ${clean}\n`
|
|
4375
|
+
: clean.endsWith('.md')
|
|
4376
|
+
? `# ${clean}\n`
|
|
4377
|
+
: /\.(hpp|h)$/i.test(clean)
|
|
4378
|
+
? `#pragma once\n#include <bits/stdc++.h>\n\n// ${clean}\n`
|
|
4379
|
+
: /\.(cpp|cc|cxx)$/i.test(clean)
|
|
4380
|
+
? `#include <bits/stdc++.h>\nusing namespace std;\n\n// ${clean}\nint main() {\n return 0;\n}\n`
|
|
4381
|
+
: `'use strict';\n\n// ${clean}\n`;
|
|
3571
4382
|
}
|
|
3572
4383
|
this._saveState();
|
|
3573
4384
|
this._getOrCreateModel(clean);
|
|
4385
|
+
this._syncFilesToShellVfs();
|
|
3574
4386
|
this._emitEvent('codelab:file-create', { labId: this.labId, filename: clean, content: this.files[clean] });
|
|
3575
4387
|
this.openFile(clean);
|
|
4388
|
+
return clean;
|
|
3576
4389
|
}
|
|
3577
4390
|
|
|
3578
4391
|
duplicateFile(filename) {
|
|
@@ -4049,6 +4862,113 @@ int main() {
|
|
|
4049
4862
|
</div>
|
|
4050
4863
|
</div>
|
|
4051
4864
|
`;
|
|
4865
|
+
return;
|
|
4866
|
+
}
|
|
4867
|
+
|
|
4868
|
+
if (this.drawerTab === 'sql-results') {
|
|
4869
|
+
const res = this.lastSqlResult;
|
|
4870
|
+
if (!res) {
|
|
4871
|
+
bodyEl.innerHTML = `
|
|
4872
|
+
<div style="color:var(--cl-fg-muted);padding:16px;">
|
|
4873
|
+
Press <strong>⌘+Enter</strong> or click <strong>${this.hasGuidedLab && this.mode === 'guided' ? 'Verify Step' : 'Run SQL'}</strong> to execute the SQL query (${this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18'}).
|
|
4874
|
+
</div>
|
|
4875
|
+
`;
|
|
4876
|
+
return;
|
|
4877
|
+
}
|
|
4878
|
+
const verificationHtml = res.verification
|
|
4879
|
+
? `<div class="codelab-test-summary ${res.verification.passed ? 'all-pass' : 'has-fail'}" style="margin-bottom:10px;">
|
|
4880
|
+
<div>
|
|
4881
|
+
<strong>${res.verification.passed ? '✓ Step Verification Passed' : '✖ Step Verification Failed'}</strong>
|
|
4882
|
+
${res.verification.message ? `<span style="margin-left:8px;font-size:12px;">${escapeHtml(res.verification.message)}</span>` : ''}
|
|
4883
|
+
</div>
|
|
4884
|
+
<span style="font-family:var(--cl-font-mono);font-size:12px;">${typeof res.durationMs === 'number' ? `${res.durationMs.toFixed(1)} ms` : ''}</span>
|
|
4885
|
+
</div>`
|
|
4886
|
+
: '';
|
|
4887
|
+
const errHtml = res.error
|
|
4888
|
+
? `<div role="alert" style="padding:10px 12px;margin-bottom:10px;border-radius:6px;border:1px solid rgba(239,68,68,0.45);background:rgba(239,68,68,0.12);color:var(--cl-red,#f87171);font-family:var(--cl-font-mono);font-size:12px;white-space:pre-wrap;">${escapeHtml(typeof res.error === 'string' ? res.error : (res.error.message || String(res.error)))}</div>`
|
|
4889
|
+
: '';
|
|
4890
|
+
const cols = Array.isArray(res.columns) ? res.columns : [];
|
|
4891
|
+
const rows = Array.isArray(res.rows) ? res.rows : [];
|
|
4892
|
+
const captionId = `cl-sql-cap-${escapeHtml(this.instanceId)}`;
|
|
4893
|
+
const rowSummary = `${rows.length} row${rows.length === 1 ? '' : 's'}${typeof res.durationMs === 'number' ? ` · ${res.durationMs.toFixed(1)} ms` : ''}`;
|
|
4894
|
+
const tableHtml = cols.length > 0
|
|
4895
|
+
? `<div tabindex="0" role="region" aria-labelledby="${captionId}" class="cl-sql-results-wrapper">
|
|
4896
|
+
<table class="cl-sql-results-table">
|
|
4897
|
+
<caption id="${captionId}" class="cl-sql-results-caption">Query Result (${escapeHtml(rowSummary)})</caption>
|
|
4898
|
+
<thead>
|
|
4899
|
+
<tr>
|
|
4900
|
+
${cols.map(c => `<th scope="col">${escapeHtml(String(c))}</th>`).join('')}
|
|
4901
|
+
</tr>
|
|
4902
|
+
</thead>
|
|
4903
|
+
<tbody>
|
|
4904
|
+
${rows.length === 0
|
|
4905
|
+
? `<tr><td colspan="${cols.length}" style="color:var(--cl-fg-muted);font-style:italic;">0 rows returned</td></tr>`
|
|
4906
|
+
: rows.map(row => {
|
|
4907
|
+
const cells = Array.isArray(row)
|
|
4908
|
+
? cols.map((_, idx) => row[idx])
|
|
4909
|
+
: cols.map(c => (row && typeof row === 'object' ? row[c] : undefined));
|
|
4910
|
+
return `<tr>${cells.map((val, idx) => {
|
|
4911
|
+
const colLabel = String(cols[idx] ?? '').replace(/['"\\]/g, '');
|
|
4912
|
+
const display = val === null || val === undefined
|
|
4913
|
+
? '<span style="opacity:0.5;font-style:italic;">NULL</span>'
|
|
4914
|
+
: escapeHtml(typeof val === 'object' ? JSON.stringify(val) : String(val));
|
|
4915
|
+
return `<td style="--col-label: '${escapeHtml(colLabel)}'">${display}</td>`;
|
|
4916
|
+
}).join('')}</tr>`;
|
|
4917
|
+
}).join('')}
|
|
4918
|
+
</tbody>
|
|
4919
|
+
</table>
|
|
4920
|
+
</div>`
|
|
4921
|
+
: (!res.error
|
|
4922
|
+
? `<div style="color:var(--cl-fg-muted);font-size:12px;padding:8px 2px;">Statement executed (${escapeHtml(rowSummary)}).</div>`
|
|
4923
|
+
: '');
|
|
4924
|
+
const planHtml = res.plan
|
|
4925
|
+
? `<div style="margin-top:10px;">
|
|
4926
|
+
<div style="font-size:11px;font-weight:600;color:var(--cl-fg-muted);margin-bottom:4px;text-transform:uppercase;letter-spacing:0.05em;">Query Execution Plan</div>
|
|
4927
|
+
<pre style="margin:0;padding:10px;border-radius:6px;border:1px solid var(--cl-border,#262626);background:var(--cl-bg,#0a0a0a);color:var(--cl-fg,#f5f5f5);font-family:var(--cl-font-mono);font-size:11.5px;overflow:auto;">${escapeHtml(typeof res.plan === 'string' ? res.plan : JSON.stringify(res.plan, null, 2))}</pre>
|
|
4928
|
+
</div>`
|
|
4929
|
+
: '';
|
|
4930
|
+
bodyEl.innerHTML = `<div style="padding:10px;">${verificationHtml}${errHtml}${tableHtml}${planHtml}</div>`;
|
|
4931
|
+
return;
|
|
4932
|
+
}
|
|
4933
|
+
|
|
4934
|
+
if (this.drawerTab === 'observability') {
|
|
4935
|
+
const mod = getModular();
|
|
4936
|
+
if (this.kernel && mod && typeof mod.renderObservabilityPanelHtml === 'function') {
|
|
4937
|
+
bodyEl.innerHTML = mod.renderObservabilityPanelHtml({
|
|
4938
|
+
container: this.kernel.container,
|
|
4939
|
+
configuration: this.configuration,
|
|
4940
|
+
plugins: this.plugins,
|
|
4941
|
+
logger: this.kernel.logger,
|
|
4942
|
+
recentEvents: this.kernel.getRecentEvents(),
|
|
4943
|
+
workerStatus: this.runtimeStatusText || 'Idle'
|
|
4944
|
+
});
|
|
4945
|
+
} else {
|
|
4946
|
+
bodyEl.innerHTML = `<div style="padding:14px;color:var(--cl-fg-muted);font-size:12px;">Observability kernel is not initialized.</div>`;
|
|
4947
|
+
}
|
|
4948
|
+
return;
|
|
4949
|
+
}
|
|
4950
|
+
|
|
4951
|
+
if (this.plugins && this.plugins.panels && typeof this.plugins.panels.get === 'function') {
|
|
4952
|
+
const contributedPanel = this.plugins.panels.get(this.drawerTab);
|
|
4953
|
+
if (contributedPanel && typeof contributedPanel.render === 'function') {
|
|
4954
|
+
while (this._pluginPanelDisposables && this._pluginPanelDisposables.length > 0) {
|
|
4955
|
+
const d = this._pluginPanelDisposables.pop();
|
|
4956
|
+
if (d && typeof d.dispose === 'function') {
|
|
4957
|
+
try { d.dispose(); } catch (err) { this.logger.debug('Plugin panel dispose skipped.', err); }
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
bodyEl.innerHTML = '';
|
|
4961
|
+
try {
|
|
4962
|
+
const disp = contributedPanel.render(bodyEl);
|
|
4963
|
+
if (disp && typeof disp.dispose === 'function') {
|
|
4964
|
+
this._pluginPanelDisposables.push(disp);
|
|
4965
|
+
}
|
|
4966
|
+
} catch (err) {
|
|
4967
|
+
this.logger.error(`Plugin panel "${this.drawerTab}" render threw.`, err);
|
|
4968
|
+
bodyEl.innerHTML = `<div role="alert" style="padding:12px;color:var(--cl-red);">Failed to render plugin panel: ${escapeHtml(err && err.message ? err.message : String(err))}</div>`;
|
|
4969
|
+
}
|
|
4970
|
+
return;
|
|
4971
|
+
}
|
|
4052
4972
|
}
|
|
4053
4973
|
}
|
|
4054
4974
|
|
|
@@ -4484,7 +5404,7 @@ int main() {
|
|
|
4484
5404
|
} else if (httpState.activeResponseTab === 'preview') {
|
|
4485
5405
|
const isHtml = lastRes.headers && Object.entries(lastRes.headers).some(([k, v]) => k.toLowerCase() === 'content-type' && String(v).includes('text/html'));
|
|
4486
5406
|
if (isHtml || lastRes.body.includes('<html') || lastRes.body.includes('<!DOCTYPE') || lastRes.body.includes('<div') || lastRes.body.includes('<body')) {
|
|
4487
|
-
responseBodyView = `<iframe class="codelab-response-iframe" sandbox="
|
|
5407
|
+
responseBodyView = `<iframe class="codelab-response-iframe" title="HTTP response HTML preview" sandbox="" srcdoc="${escapeHtml(lastRes.body)}"></iframe>`;
|
|
4488
5408
|
} else {
|
|
4489
5409
|
responseBodyView = `<pre class="codelab-response-raw"><code>${escapeHtml(lastRes.formattedBody || lastRes.body)}</code></pre>`;
|
|
4490
5410
|
}
|
|
@@ -4845,23 +5765,23 @@ int main() {
|
|
|
4845
5765
|
<option value="5xx" ${filter.status === '5xx' ? 'selected' : ''}>5xx / Network Fault</option>
|
|
4846
5766
|
</select>
|
|
4847
5767
|
<button type="button" class="codelab-btn" data-cl-action="clear-net-traces">Clear</button>
|
|
4848
|
-
<span style="margin-left:auto;font-size:11.5px;color:var(--cl-fg-muted);">${filtered.length} of ${traces.length} requests</span>
|
|
5768
|
+
<span id="cl-net-count" style="margin-left:auto;font-size:11.5px;color:var(--cl-fg-muted);">${filtered.length} of ${traces.length} requests</span>
|
|
4849
5769
|
</div>
|
|
4850
5770
|
<div class="codelab-net-main">
|
|
4851
5771
|
<div class="codelab-net-table-container">
|
|
4852
5772
|
<table class="codelab-net-table">
|
|
4853
5773
|
<thead>
|
|
4854
5774
|
<tr>
|
|
4855
|
-
<th style="width:85px;">Status</th>
|
|
4856
|
-
<th style="width:65px;">Method</th>
|
|
4857
|
-
<th>Path</th>
|
|
4858
|
-
<th style="width:95px;">Route</th>
|
|
4859
|
-
<th style="width:75px;">Time</th>
|
|
4860
|
-
<th style="width:70px;">Size</th>
|
|
4861
|
-
<th style="width:140px;">Waterfall</th>
|
|
5775
|
+
<th scope="col" style="width:85px;">Status</th>
|
|
5776
|
+
<th scope="col" style="width:65px;">Method</th>
|
|
5777
|
+
<th scope="col">Path</th>
|
|
5778
|
+
<th scope="col" style="width:95px;">Route</th>
|
|
5779
|
+
<th scope="col" style="width:75px;">Time</th>
|
|
5780
|
+
<th scope="col" style="width:70px;">Size</th>
|
|
5781
|
+
<th scope="col" style="width:140px;">Waterfall</th>
|
|
4862
5782
|
</tr>
|
|
4863
5783
|
</thead>
|
|
4864
|
-
<tbody>
|
|
5784
|
+
<tbody id="cl-net-tbody">
|
|
4865
5785
|
${rowsHtml}
|
|
4866
5786
|
</tbody>
|
|
4867
5787
|
</table>
|
|
@@ -4874,13 +5794,82 @@ int main() {
|
|
|
4874
5794
|
this._bindNetworkEvents(bodyEl);
|
|
4875
5795
|
}
|
|
4876
5796
|
|
|
5797
|
+
_updateNetworkRowsInPlace(bodyEl) {
|
|
5798
|
+
if (!bodyEl) return false;
|
|
5799
|
+
const tbody = bodyEl.querySelector('#cl-net-tbody');
|
|
5800
|
+
const countEl = bodyEl.querySelector('#cl-net-count');
|
|
5801
|
+
if (!tbody) return false;
|
|
5802
|
+
const traces = this.lastHttpTrace || [];
|
|
5803
|
+
const filter = this.networkFilter;
|
|
5804
|
+
const filtered = traces.filter(t => {
|
|
5805
|
+
if (filter.method !== 'ALL' && (t.method || 'GET').toUpperCase() !== filter.method) return false;
|
|
5806
|
+
if (filter.status !== 'ALL') {
|
|
5807
|
+
const s = Number(t.status || 0);
|
|
5808
|
+
if (filter.status === '2xx' && (s < 200 || s >= 300)) return false;
|
|
5809
|
+
if (filter.status === '3xx' && (s < 300 || s >= 400)) return false;
|
|
5810
|
+
if (filter.status === '4xx' && (s < 400 || s >= 500)) return false;
|
|
5811
|
+
if (filter.status === '5xx' && (s < 500 && s !== 0)) return false;
|
|
5812
|
+
}
|
|
5813
|
+
if (filter.search) {
|
|
5814
|
+
const query = filter.search.toLowerCase();
|
|
5815
|
+
const urlMatch = String(t.url || '').toLowerCase().includes(query);
|
|
5816
|
+
const methodMatch = String(t.method || '').toLowerCase().includes(query);
|
|
5817
|
+
const portMatch = String(t.port || '').includes(query);
|
|
5818
|
+
if (!urlMatch && !methodMatch && !portMatch) return false;
|
|
5819
|
+
}
|
|
5820
|
+
return true;
|
|
5821
|
+
});
|
|
5822
|
+
const selectedTrace = traces.find(t => String(t.id) === String(filter.selectedTraceId)) || null;
|
|
5823
|
+
if (countEl) {
|
|
5824
|
+
countEl.textContent = `${filtered.length} of ${traces.length} requests`;
|
|
5825
|
+
}
|
|
5826
|
+
if (filtered.length === 0) {
|
|
5827
|
+
tbody.innerHTML = `
|
|
5828
|
+
<tr>
|
|
5829
|
+
<td colspan="7" style="text-align:center;padding:32px;color:var(--cl-fg-muted);">
|
|
5830
|
+
${traces.length === 0 ? 'No network requests recorded yet. Run a demo, click "⚡ Load Test", or run `hey -n 50 http://localhost:3000` in the terminal.' : 'No network requests match the active filters.'}
|
|
5831
|
+
</td>
|
|
5832
|
+
</tr>
|
|
5833
|
+
`;
|
|
5834
|
+
} else {
|
|
5835
|
+
const maxDuration = Math.max(1, ...filtered.map(t => t.durationMs || 1));
|
|
5836
|
+
tbody.innerHTML = filtered.map(t => {
|
|
5837
|
+
const status = Number(t.status || 0);
|
|
5838
|
+
const statusLabel = status === 0 ? (t.statusText || 'ERR') : String(status);
|
|
5839
|
+
const statusClass = status === 0 ? 'status-5xx' : (status < 300 ? 'status-2xx' : (status < 400 ? 'status-3xx' : (status < 500 ? 'status-4xx' : 'status-5xx')));
|
|
5840
|
+
const widthPct = Math.min(100, Math.max(8, Math.round(((t.durationMs || 1) / maxDuration) * 100)));
|
|
5841
|
+
const isSelected = selectedTrace && String(selectedTrace.id) === String(t.id);
|
|
5842
|
+
const hopLabel = t.fromPort ? `:${t.fromPort}→:${t.port || 3000}` : `:${t.port || 3000}`;
|
|
5843
|
+
const chaosChip = t.chaosEffect ? `<span class="codelab-chaos-badge codelab-chaos-badge--warn" style="margin-left:4px;">${escapeHtml(String(t.chaosEffect))}</span>` : '';
|
|
5844
|
+
return `
|
|
5845
|
+
<tr class="codelab-net-row ${isSelected ? 'selected' : ''}" data-cl-action="select-net-trace" data-trace-id="${escapeHtml(t.id || '')}" data-cl-trace-id="${escapeHtml(t.id || '')}">
|
|
5846
|
+
<td><span class="codelab-status-badge ${statusClass}">${escapeHtml(statusLabel)}</span>${chaosChip}</td>
|
|
5847
|
+
<td><span class="codelab-method-badge codelab-method-${(t.method || 'GET').toLowerCase()}">${escapeHtml(t.method || 'GET')}</span></td>
|
|
5848
|
+
<td class="codelab-net-path" title="${escapeHtml(t.url || '/')}">${escapeHtml(t.url || '/')}</td>
|
|
5849
|
+
<td><code>${escapeHtml(hopLabel)}</code></td>
|
|
5850
|
+
<td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${(t.durationMs || 0).toFixed(1)} ms</td>
|
|
5851
|
+
<td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${t.size != null ? t.size : 0} B</td>
|
|
5852
|
+
<td class="codelab-waterfall-cell">
|
|
5853
|
+
<div class="codelab-waterfall-track">
|
|
5854
|
+
<div class="codelab-waterfall-bar" style="width:${widthPct}%;"></div>
|
|
5855
|
+
</div>
|
|
5856
|
+
</td>
|
|
5857
|
+
</tr>
|
|
5858
|
+
`;
|
|
5859
|
+
}).join('');
|
|
5860
|
+
}
|
|
5861
|
+
return true;
|
|
5862
|
+
}
|
|
5863
|
+
|
|
4877
5864
|
_bindNetworkEvents(bodyEl) {
|
|
4878
5865
|
if (!bodyEl) return;
|
|
4879
5866
|
const searchInput = bodyEl.querySelector('#cl-net-search');
|
|
4880
5867
|
if (searchInput) {
|
|
4881
5868
|
searchInput.addEventListener('input', e => {
|
|
4882
5869
|
this.networkFilter.search = e.target.value;
|
|
4883
|
-
this.
|
|
5870
|
+
if (!this._updateNetworkRowsInPlace(bodyEl)) {
|
|
5871
|
+
this._renderDrawerBody();
|
|
5872
|
+
}
|
|
4884
5873
|
});
|
|
4885
5874
|
}
|
|
4886
5875
|
const methodSelect = bodyEl.querySelector('#cl-net-method');
|
|
@@ -5030,6 +6019,14 @@ int main() {
|
|
|
5030
6019
|
const active = b.dataset.clDrawertab === this.drawerTab;
|
|
5031
6020
|
b.classList.toggle('active', active);
|
|
5032
6021
|
b.setAttribute('aria-selected', String(active));
|
|
6022
|
+
if (active && typeof b.scrollIntoView === 'function') {
|
|
6023
|
+
try {
|
|
6024
|
+
const scrollOpts = { block: 'nearest', inline: 'nearest', container: 'nearest' };
|
|
6025
|
+
b['scrollIntoView'](scrollOpts);
|
|
6026
|
+
} catch (err) {
|
|
6027
|
+
void err;
|
|
6028
|
+
}
|
|
6029
|
+
}
|
|
5033
6030
|
});
|
|
5034
6031
|
const drawer = this.container.querySelector('#cl-drawer');
|
|
5035
6032
|
if (drawer) drawer.classList.remove('is-minimized');
|
|
@@ -6158,7 +7155,7 @@ int main() {
|
|
|
6158
7155
|
this.files[this.activeFile] = fallbackEl.value;
|
|
6159
7156
|
this._updateFallbackGutter();
|
|
6160
7157
|
updateFallbackCursor();
|
|
6161
|
-
this.
|
|
7158
|
+
this._scheduleSaveState();
|
|
6162
7159
|
this._notifyCodeChange(this.activeFile, fallbackEl.value);
|
|
6163
7160
|
}
|
|
6164
7161
|
});
|
|
@@ -6196,6 +7193,56 @@ int main() {
|
|
|
6196
7193
|
loadMonaco(this.monacoUrl).then(m => {
|
|
6197
7194
|
this.monaco = m;
|
|
6198
7195
|
if (!monacoHost) return;
|
|
7196
|
+
if (m.editor && typeof m.editor.defineTheme === 'function') {
|
|
7197
|
+
try {
|
|
7198
|
+
m.editor.defineTheme('codelab-hc-dark', {
|
|
7199
|
+
base: 'hc-black',
|
|
7200
|
+
inherit: true,
|
|
7201
|
+
rules: [],
|
|
7202
|
+
colors: {
|
|
7203
|
+
'editor.background': '#000000',
|
|
7204
|
+
'editor.foreground': '#ffffff'
|
|
7205
|
+
}
|
|
7206
|
+
});
|
|
7207
|
+
} catch (err) {
|
|
7208
|
+
this.logger.debug('defineTheme codelab-hc-dark skipped.', err);
|
|
7209
|
+
}
|
|
7210
|
+
}
|
|
7211
|
+
const mod = getModular();
|
|
7212
|
+
if (m.languages && m.languages.json && m.languages.json.jsonDefaults && typeof m.languages.json.jsonDefaults.setDiagnosticsOptions === 'function' && this.configuration && mod) {
|
|
7213
|
+
try {
|
|
7214
|
+
m.languages.json.jsonDefaults.setDiagnosticsOptions({
|
|
7215
|
+
validate: true,
|
|
7216
|
+
allowComments: true,
|
|
7217
|
+
trailingCommas: 'ignore',
|
|
7218
|
+
schemas: [
|
|
7219
|
+
{
|
|
7220
|
+
uri: 'https://code-lab.dev/schemas/settings.json',
|
|
7221
|
+
fileMatch: ['**/.codelab/settings.json', '.codelab/settings.json'],
|
|
7222
|
+
schema: this.configuration.getJsonSchema()
|
|
7223
|
+
},
|
|
7224
|
+
{
|
|
7225
|
+
uri: 'https://code-lab.dev/schemas/keybindings.json',
|
|
7226
|
+
fileMatch: ['**/.codelab/keybindings.json', '.codelab/keybindings.json'],
|
|
7227
|
+
schema: mod.KEYBINDINGS_JSON_SCHEMA
|
|
7228
|
+
},
|
|
7229
|
+
{
|
|
7230
|
+
uri: 'https://code-lab.dev/schemas/tasks.json',
|
|
7231
|
+
fileMatch: ['**/.codelab/tasks.json', '.codelab/tasks.json'],
|
|
7232
|
+
schema: mod.TASKS_JSON_SCHEMA
|
|
7233
|
+
},
|
|
7234
|
+
{
|
|
7235
|
+
uri: 'https://code-lab.dev/schemas/extensions.json',
|
|
7236
|
+
fileMatch: ['**/.codelab/extensions.json', '.codelab/extensions.json'],
|
|
7237
|
+
schema: mod.EXTENSIONS_JSON_SCHEMA
|
|
7238
|
+
}
|
|
7239
|
+
]
|
|
7240
|
+
});
|
|
7241
|
+
} catch (err) {
|
|
7242
|
+
this.logger.debug('Monaco JSON schema registration skipped.', err);
|
|
7243
|
+
}
|
|
7244
|
+
}
|
|
7245
|
+
|
|
6199
7246
|
const isDark = this._resolvedTheme() !== 'light';
|
|
6200
7247
|
|
|
6201
7248
|
// Create models for all code files
|
|
@@ -6205,12 +7252,14 @@ int main() {
|
|
|
6205
7252
|
this.editor = m.editor.create(monacoHost, {
|
|
6206
7253
|
model: currentModel,
|
|
6207
7254
|
theme: isDark ? 'codelab-dark' : 'codelab-light',
|
|
6208
|
-
fontFamily: '"Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace',
|
|
6209
|
-
fontSize: 13,
|
|
7255
|
+
fontFamily: this.configuration ? this.configuration.get('editor.fontFamily', '"Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace') : '"Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace',
|
|
7256
|
+
fontSize: this.configuration ? this.configuration.get('editor.fontSize', 13) : 13,
|
|
6210
7257
|
lineHeight: 20,
|
|
6211
|
-
tabSize: 2,
|
|
7258
|
+
tabSize: this.configuration ? this.configuration.get('editor.tabSize', 2) : 2,
|
|
6212
7259
|
insertSpaces: true,
|
|
6213
|
-
|
|
7260
|
+
wordWrap: this.configuration ? this.configuration.get('editor.wordWrap', 'off') : 'off',
|
|
7261
|
+
lineNumbers: this.configuration ? this.configuration.get('editor.lineNumbers', 'on') : 'on',
|
|
7262
|
+
minimap: { enabled: this.configuration ? Boolean(this.configuration.get('editor.minimap.enabled', false)) : false },
|
|
6214
7263
|
scrollBeyondLastLine: false,
|
|
6215
7264
|
automaticLayout: true,
|
|
6216
7265
|
padding: { top: 12, bottom: 12 },
|
|
@@ -6220,6 +7269,8 @@ int main() {
|
|
|
6220
7269
|
bracketPairColorization: { enabled: true }
|
|
6221
7270
|
});
|
|
6222
7271
|
|
|
7272
|
+
this._applyConfigurationChanges(null);
|
|
7273
|
+
|
|
6223
7274
|
// Dynamic ResizeObserver to guarantee 100% width on layout shifts
|
|
6224
7275
|
if (typeof ResizeObserver !== 'undefined' && monacoHost) {
|
|
6225
7276
|
this._editorResizeObserver = new ResizeObserver(() => {
|
|
@@ -6235,6 +7286,8 @@ int main() {
|
|
|
6235
7286
|
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyCode.Enter, () => {
|
|
6236
7287
|
if (this.mode === 'guided') {
|
|
6237
7288
|
this.verifyCurrentStep();
|
|
7289
|
+
} else if (this.lang === 'sql' || (this.activeFile && /\.sql$/i.test(this.activeFile))) {
|
|
7290
|
+
this.runSql('run');
|
|
6238
7291
|
} else {
|
|
6239
7292
|
this.runTests();
|
|
6240
7293
|
}
|
|
@@ -6242,6 +7295,11 @@ int main() {
|
|
|
6242
7295
|
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyMod.Shift | m.KeyCode.Enter, () => {
|
|
6243
7296
|
this.runDemo();
|
|
6244
7297
|
});
|
|
7298
|
+
if (m.KeyCode.Comma) {
|
|
7299
|
+
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyCode.Comma, () => {
|
|
7300
|
+
this.openSettings();
|
|
7301
|
+
});
|
|
7302
|
+
}
|
|
6245
7303
|
if (m.KeyCode.KeyP) {
|
|
6246
7304
|
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyMod.Shift | m.KeyCode.KeyP, () => {
|
|
6247
7305
|
this.openCommandPalette('commands');
|
|
@@ -6267,11 +7325,17 @@ int main() {
|
|
|
6267
7325
|
col: e.position.column
|
|
6268
7326
|
};
|
|
6269
7327
|
this._updateStatusBar();
|
|
6270
|
-
this.
|
|
7328
|
+
this._scheduleBreadcrumbs();
|
|
6271
7329
|
}
|
|
6272
7330
|
});
|
|
6273
7331
|
}
|
|
6274
7332
|
|
|
7333
|
+
if (m.editor && typeof m.editor.onDidChangeMarkers === 'function') {
|
|
7334
|
+
this._markerDisposable = m.editor.onDidChangeMarkers(() => {
|
|
7335
|
+
this._syncMonacoMarkersToDiagnostics();
|
|
7336
|
+
});
|
|
7337
|
+
}
|
|
7338
|
+
|
|
6275
7339
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
6276
7340
|
this._syncActiveFileToView();
|
|
6277
7341
|
|
|
@@ -6296,18 +7360,30 @@ int main() {
|
|
|
6296
7360
|
}
|
|
6297
7361
|
|
|
6298
7362
|
_notifyCodeChange(filename, code) {
|
|
6299
|
-
|
|
7363
|
+
const cleanRel = filename ? String(filename).replace(/^\/+/, '') : '';
|
|
7364
|
+
if (this.shell && this.shell.vfs && cleanRel && typeof this.shell.vfs.writeFileSync === 'function') {
|
|
6300
7365
|
try {
|
|
6301
|
-
const
|
|
6302
|
-
const parts = clean.split('/');
|
|
7366
|
+
const parts = cleanRel.split('/');
|
|
6303
7367
|
if (parts.length > 1 && typeof this.shell.vfs.mkdirSync === 'function') {
|
|
6304
7368
|
this.shell.vfs.mkdirSync('/workspace/' + parts.slice(0, -1).join('/'), { recursive: true });
|
|
6305
7369
|
}
|
|
6306
|
-
this.shell.vfs.writeFileSync('/workspace/' +
|
|
7370
|
+
this.shell.vfs.writeFileSync('/workspace/' + cleanRel, String(code ?? ''));
|
|
6307
7371
|
} catch (err) {
|
|
6308
7372
|
this.logger.debug(`Could not sync "${filename}" to shell VFS on edit.`, err);
|
|
6309
7373
|
}
|
|
6310
7374
|
}
|
|
7375
|
+
if (this.kernel && this.kernel.fs && cleanRel && typeof this.kernel.fs.writeFile === 'function') {
|
|
7376
|
+
try {
|
|
7377
|
+
Promise.resolve(this.kernel.fs.writeFile('/workspace/' + cleanRel, String(code ?? ''))).catch((err) => {
|
|
7378
|
+
this.logger.debug(`Could not sync "${cleanRel}" to kernel VFS.`, err);
|
|
7379
|
+
});
|
|
7380
|
+
} catch (err) {
|
|
7381
|
+
this.logger.debug(`Could not sync "${cleanRel}" to kernel VFS.`, err);
|
|
7382
|
+
}
|
|
7383
|
+
}
|
|
7384
|
+
if (cleanRel.startsWith('.codelab/')) {
|
|
7385
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
7386
|
+
}
|
|
6311
7387
|
if ((this.drawerTab === 'preview' || (this.previewState && this.previewState.dockMode === 'split')) && this.previewState && this.previewState.port) {
|
|
6312
7388
|
if (this._previewReloadTimer) {
|
|
6313
7389
|
clearTimeout(this._previewReloadTimer);
|
|
@@ -6327,6 +7403,61 @@ int main() {
|
|
|
6327
7403
|
this._renderBreadcrumbs();
|
|
6328
7404
|
}
|
|
6329
7405
|
|
|
7406
|
+
_scheduleBreadcrumbs() {
|
|
7407
|
+
if (typeof requestAnimationFrame !== 'function') {
|
|
7408
|
+
this._renderBreadcrumbs();
|
|
7409
|
+
return;
|
|
7410
|
+
}
|
|
7411
|
+
if (this._breadcrumbRafId) return;
|
|
7412
|
+
this._breadcrumbRafId = requestAnimationFrame(() => {
|
|
7413
|
+
this._breadcrumbRafId = null;
|
|
7414
|
+
if (!this._destroyed) {
|
|
7415
|
+
this._renderBreadcrumbs();
|
|
7416
|
+
}
|
|
7417
|
+
});
|
|
7418
|
+
}
|
|
7419
|
+
|
|
7420
|
+
_syncMonacoMarkersToDiagnostics() {
|
|
7421
|
+
if (!this.monaco || !this.monaco.editor || typeof this.monaco.editor.getModelMarkers !== 'function') return;
|
|
7422
|
+
const diagMod = root.CodeLabDiagnostics;
|
|
7423
|
+
if (!this._diagnosticsStore && diagMod && typeof diagMod.createDiagnosticsStore === 'function') {
|
|
7424
|
+
this._diagnosticsStore = diagMod.createDiagnosticsStore();
|
|
7425
|
+
}
|
|
7426
|
+
if (!this._diagnosticsStore || typeof this._diagnosticsStore.setFileDiagnostics !== 'function') return;
|
|
7427
|
+
const prefix = `file:///${encodeURIComponent(this.instanceId)}/`;
|
|
7428
|
+
for (const [filename, model] of this.models.entries()) {
|
|
7429
|
+
const uri = model && model.uri ? model.uri : null;
|
|
7430
|
+
let markers = [];
|
|
7431
|
+
try {
|
|
7432
|
+
markers = uri
|
|
7433
|
+
? this.monaco.editor.getModelMarkers({ resource: uri })
|
|
7434
|
+
: this.monaco.editor.getModelMarkers({}).filter(mk => String(mk.resource || '').startsWith(prefix) && String(mk.resource || '').endsWith('/' + filename));
|
|
7435
|
+
} catch (err) {
|
|
7436
|
+
this.logger.debug('getModelMarkers failed during diagnostics sync.', err);
|
|
7437
|
+
}
|
|
7438
|
+
const mapped = (markers || []).map(mk => ({
|
|
7439
|
+
file: filename,
|
|
7440
|
+
line: mk.startLineNumber || 1,
|
|
7441
|
+
column: mk.startColumn || 1,
|
|
7442
|
+
endLine: mk.endLineNumber || mk.startLineNumber || 1,
|
|
7443
|
+
endColumn: mk.endColumn || mk.startColumn || 1,
|
|
7444
|
+
severity: mk.severity === 8 ? 'error' : mk.severity === 4 ? 'warning' : 'info',
|
|
7445
|
+
message: String(mk.message || ''),
|
|
7446
|
+
source: String(mk.source || 'monaco')
|
|
7447
|
+
}));
|
|
7448
|
+
this._diagnosticsStore.setFileDiagnostics(filename, mapped, 'monaco');
|
|
7449
|
+
}
|
|
7450
|
+
const badgeEl = this.container ? this.container.querySelector('#cl-problems-count') : null;
|
|
7451
|
+
if (badgeEl && typeof this._diagnosticsStore.getAll === 'function') {
|
|
7452
|
+
const total = this._diagnosticsStore.getAll().length;
|
|
7453
|
+
badgeEl.textContent = String(total);
|
|
7454
|
+
badgeEl.style.display = total > 0 ? 'inline-block' : 'none';
|
|
7455
|
+
}
|
|
7456
|
+
if (this.drawerTab === 'problems') {
|
|
7457
|
+
this._renderDrawerBody();
|
|
7458
|
+
}
|
|
7459
|
+
}
|
|
7460
|
+
|
|
6330
7461
|
_getOrCreateModel(filename) {
|
|
6331
7462
|
if (!filename || !this.monaco || !this.monaco.editor) return null;
|
|
6332
7463
|
const uriParser = (this.monaco.Uri && typeof this.monaco.Uri.parse === 'function')
|
|
@@ -6334,31 +7465,33 @@ int main() {
|
|
|
6334
7465
|
: (this.monaco.editor.Uri && typeof this.monaco.editor.Uri.parse === 'function')
|
|
6335
7466
|
? this.monaco.editor.Uri
|
|
6336
7467
|
: null;
|
|
6337
|
-
const rawUri = `file:///${this.
|
|
7468
|
+
const rawUri = `file:///${encodeURIComponent(this.instanceId)}/${filename}`;
|
|
6338
7469
|
const uri = uriParser ? uriParser.parse(rawUri) : { toString: () => rawUri };
|
|
6339
7470
|
let model = typeof this.monaco.editor.getModel === 'function' ? this.monaco.editor.getModel(uri) : null;
|
|
6340
7471
|
const lang = /\.(cpp|cc|cxx|hpp|h)$/i.test(filename)
|
|
6341
7472
|
? 'cpp'
|
|
6342
7473
|
: /\.py$/i.test(filename)
|
|
6343
7474
|
? 'python'
|
|
6344
|
-
:
|
|
6345
|
-
? '
|
|
6346
|
-
: filename.endsWith('.
|
|
6347
|
-
? '
|
|
6348
|
-
: filename.endsWith('.
|
|
6349
|
-
? '
|
|
6350
|
-
: filename.endsWith('.
|
|
6351
|
-
? '
|
|
6352
|
-
: filename.endsWith('.
|
|
6353
|
-
? '
|
|
6354
|
-
: '
|
|
7475
|
+
: /\.sql$/i.test(filename)
|
|
7476
|
+
? 'sql'
|
|
7477
|
+
: filename.endsWith('.ts')
|
|
7478
|
+
? 'typescript'
|
|
7479
|
+
: filename.endsWith('.json')
|
|
7480
|
+
? 'json'
|
|
7481
|
+
: filename.endsWith('.html')
|
|
7482
|
+
? 'html'
|
|
7483
|
+
: filename.endsWith('.css')
|
|
7484
|
+
? 'css'
|
|
7485
|
+
: filename.endsWith('.md')
|
|
7486
|
+
? 'markdown'
|
|
7487
|
+
: 'javascript';
|
|
6355
7488
|
if (!model) {
|
|
6356
7489
|
model = this.monaco.editor.createModel(this.files[filename] || '', lang, uri);
|
|
6357
7490
|
if (model && typeof model.onDidChangeContent === 'function') {
|
|
6358
7491
|
model.onDidChangeContent(() => {
|
|
6359
7492
|
const val = model.getValue();
|
|
6360
7493
|
this.files[filename] = val;
|
|
6361
|
-
this.
|
|
7494
|
+
this._scheduleSaveState();
|
|
6362
7495
|
this._notifyCodeChange(filename, val);
|
|
6363
7496
|
if (this.lang === 'py' && typeof this._pyLintHandler === 'function') {
|
|
6364
7497
|
this._pyLintHandler(filename, val);
|
|
@@ -6377,13 +7510,26 @@ int main() {
|
|
|
6377
7510
|
|
|
6378
7511
|
_syncAllModels() {
|
|
6379
7512
|
if (!this.monaco) return;
|
|
6380
|
-
|
|
6381
|
-
|
|
7513
|
+
const activeSet = new Set(Object.keys(this.files || {}));
|
|
7514
|
+
for (const [filename, model] of Array.from(this.models.entries())) {
|
|
7515
|
+
if (!activeSet.has(filename)) {
|
|
7516
|
+
if (model && typeof model.dispose === 'function') {
|
|
7517
|
+
try { model.dispose(); } catch (err) { this.logger.debug('Stale model dispose skipped.', err); }
|
|
7518
|
+
}
|
|
7519
|
+
this.models.delete(filename);
|
|
7520
|
+
}
|
|
7521
|
+
}
|
|
7522
|
+
for (const filename of activeSet) {
|
|
7523
|
+
const content = String(this.files[filename] || '');
|
|
7524
|
+
if (content.length <= 2 * 1024 * 1024 && !content.includes('\x00')) {
|
|
7525
|
+
this._getOrCreateModel(filename);
|
|
7526
|
+
}
|
|
6382
7527
|
}
|
|
6383
7528
|
}
|
|
6384
7529
|
|
|
6385
7530
|
_syncActiveFileToView() {
|
|
6386
7531
|
const monacoHost = this.container.querySelector('#cl-monaco-host');
|
|
7532
|
+
const sqlHost = this.container.querySelector('#cl-sql-editor-host');
|
|
6387
7533
|
const fallbackWrap = this.container.querySelector('#cl-fallback-wrap');
|
|
6388
7534
|
const fallbackEl = this.container.querySelector('#cl-fallback-editor');
|
|
6389
7535
|
const mdPreview = this.container.querySelector('#cl-md-preview');
|
|
@@ -6391,6 +7537,7 @@ int main() {
|
|
|
6391
7537
|
|
|
6392
7538
|
if (!this.activeFile || !this.openTabs || this.openTabs.length === 0) {
|
|
6393
7539
|
if (monacoHost) monacoHost.style.display = 'none';
|
|
7540
|
+
if (sqlHost) sqlHost.style.display = 'none';
|
|
6394
7541
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
6395
7542
|
if (mdPreview) mdPreview.style.display = 'none';
|
|
6396
7543
|
if (this.editor) {
|
|
@@ -6406,20 +7553,103 @@ int main() {
|
|
|
6406
7553
|
return;
|
|
6407
7554
|
}
|
|
6408
7555
|
|
|
7556
|
+
const activeContent = String(this.files[this.activeFile] ?? '');
|
|
7557
|
+
const isBinaryContent = activeContent.includes('\x00') || /\.(png|jpe?g|gif|webp|ico|woff2?|ttf|wasm|pdf|zip)$/i.test(this.activeFile);
|
|
7558
|
+
const isHugeContent = activeContent.length > 2 * 1024 * 1024;
|
|
7559
|
+
if ((isBinaryContent || isHugeContent) && !(this._forceOpenedLargeFiles && this._forceOpenedLargeFiles.has(this.activeFile))) {
|
|
7560
|
+
if (monacoHost) monacoHost.style.display = 'none';
|
|
7561
|
+
if (sqlHost) sqlHost.style.display = 'none';
|
|
7562
|
+
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
7563
|
+
if (mdPreview) mdPreview.style.display = 'none';
|
|
7564
|
+
if (this.editor) {
|
|
7565
|
+
try { this.editor.setModel(null); } catch (err) { this.logger.debug('editor.setModel(null) failed.', err); }
|
|
7566
|
+
}
|
|
7567
|
+
if (emptyEl) {
|
|
7568
|
+
emptyEl.style.display = 'flex';
|
|
7569
|
+
const sizeKb = (activeContent.length / 1024).toFixed(1);
|
|
7570
|
+
emptyEl.innerHTML = `
|
|
7571
|
+
<div class="codelab-file-guard" role="status">
|
|
7572
|
+
<strong>${escapeHtml(this.activeFile)}</strong>
|
|
7573
|
+
<span>${isBinaryContent
|
|
7574
|
+
? `Binary file (${sizeKb} KB) cannot be displayed as plain text.`
|
|
7575
|
+
: `Large file (${sizeKb} KB) paused before rendering to keep the editor responsive.`}</span>
|
|
7576
|
+
${!isBinaryContent
|
|
7577
|
+
? `<button type="button" class="codelab-btn codelab-btn--primary" data-cl-action="open-large-file-anyway" data-cl-file="${escapeHtml(this.activeFile)}">Open File Anyway</button>`
|
|
7578
|
+
: ''}
|
|
7579
|
+
</div>
|
|
7580
|
+
`;
|
|
7581
|
+
}
|
|
7582
|
+
this._renderFileLists();
|
|
7583
|
+
this._renderBreadcrumbs();
|
|
7584
|
+
this._updateStatusBar();
|
|
7585
|
+
return;
|
|
7586
|
+
}
|
|
7587
|
+
|
|
6409
7588
|
if (emptyEl) {
|
|
6410
7589
|
emptyEl.style.display = 'none';
|
|
6411
7590
|
}
|
|
6412
7591
|
|
|
6413
7592
|
const isMd = this.activeFile.endsWith('.md');
|
|
7593
|
+
const isSqlFile = /\.sql$/i.test(this.activeFile);
|
|
7594
|
+
const sqlPack = getSqlPack();
|
|
7595
|
+
const useLightweightSqlEditor = Boolean(
|
|
7596
|
+
isSqlFile &&
|
|
7597
|
+
sqlHost &&
|
|
7598
|
+
sqlPack &&
|
|
7599
|
+
typeof sqlPack.createSqlEditor === 'function' &&
|
|
7600
|
+
(!this.editor || (this.options && this.options.editorEngine !== 'monaco'))
|
|
7601
|
+
);
|
|
7602
|
+
|
|
6414
7603
|
if (isMd) {
|
|
6415
7604
|
if (monacoHost) monacoHost.style.display = 'none';
|
|
7605
|
+
if (sqlHost) sqlHost.style.display = 'none';
|
|
6416
7606
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
6417
7607
|
if (mdPreview) {
|
|
6418
7608
|
mdPreview.style.display = 'block';
|
|
6419
7609
|
mdPreview.innerHTML = renderSimpleMarkdown(this.files[this.activeFile] || '');
|
|
6420
7610
|
}
|
|
7611
|
+
} else if (useLightweightSqlEditor) {
|
|
7612
|
+
if (mdPreview) mdPreview.style.display = 'none';
|
|
7613
|
+
if (monacoHost) monacoHost.style.display = 'none';
|
|
7614
|
+
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
7615
|
+
sqlHost.style.display = 'block';
|
|
7616
|
+
if (!this._sqlWorkbenchEditor) {
|
|
7617
|
+
this._sqlWorkbenchEditor = sqlPack.createSqlEditor(sqlHost, {
|
|
7618
|
+
value: this.files[this.activeFile] || '',
|
|
7619
|
+
mode: 'inline',
|
|
7620
|
+
dialect: this.sqlDialect,
|
|
7621
|
+
schema: this.sqlSchema || undefined,
|
|
7622
|
+
theme: this._resolvedTheme() === 'light' ? 'light' : 'dark',
|
|
7623
|
+
minLines: 10,
|
|
7624
|
+
maxLines: 200,
|
|
7625
|
+
ariaLabel: `SQL Editor (${this.activeFile})`,
|
|
7626
|
+
onChange: (nextVal) => {
|
|
7627
|
+
if (this.activeFile && /\.sql$/i.test(this.activeFile)) {
|
|
7628
|
+
this.files[this.activeFile] = nextVal;
|
|
7629
|
+
this._scheduleSaveState();
|
|
7630
|
+
this._notifyCodeChange(this.activeFile, nextVal);
|
|
7631
|
+
}
|
|
7632
|
+
},
|
|
7633
|
+
onRun: (payload) => {
|
|
7634
|
+
if (this.mode === 'guided') {
|
|
7635
|
+
this.verifyCurrentStep(payload);
|
|
7636
|
+
} else {
|
|
7637
|
+
this.runSql('run', payload);
|
|
7638
|
+
}
|
|
7639
|
+
},
|
|
7640
|
+
onExplain: (payload) => {
|
|
7641
|
+
this.runSql('explain', payload);
|
|
7642
|
+
}
|
|
7643
|
+
});
|
|
7644
|
+
} else {
|
|
7645
|
+
const desired = this.files[this.activeFile] || '';
|
|
7646
|
+
if (this._sqlWorkbenchEditor.getValue() !== desired) {
|
|
7647
|
+
this._sqlWorkbenchEditor.setValue(desired);
|
|
7648
|
+
}
|
|
7649
|
+
}
|
|
6421
7650
|
} else {
|
|
6422
7651
|
if (mdPreview) mdPreview.style.display = 'none';
|
|
7652
|
+
if (sqlHost) sqlHost.style.display = 'none';
|
|
6423
7653
|
if (this.editor && this.monaco) {
|
|
6424
7654
|
if (monacoHost) monacoHost.style.display = 'block';
|
|
6425
7655
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
@@ -6525,11 +7755,32 @@ int main() {
|
|
|
6525
7755
|
? e.target.closest('#cl-preview-url-input')
|
|
6526
7756
|
: null;
|
|
6527
7757
|
if (previewInput && e.key === 'Enter') {
|
|
7758
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
6528
7759
|
e.preventDefault();
|
|
6529
7760
|
this._previewGo(previewInput.value);
|
|
6530
7761
|
return;
|
|
6531
7762
|
}
|
|
6532
|
-
if (e.key === '
|
|
7763
|
+
if ((e.metaKey || e.ctrlKey) && e.key === ',') {
|
|
7764
|
+
e.preventDefault();
|
|
7765
|
+
this.openSettings();
|
|
7766
|
+
return;
|
|
7767
|
+
}
|
|
7768
|
+
if (this.keybindings && this.commands && typeof this.keybindings.resolve === 'function') {
|
|
7769
|
+
const kbRule = this.keybindings.resolve(e);
|
|
7770
|
+
if (kbRule && this.commands.hasCommand(kbRule.command)) {
|
|
7771
|
+
const activeTag = e.target && e.target.tagName ? String(e.target.tagName).toUpperCase() : '';
|
|
7772
|
+
const hasMod = Boolean(e.metaKey || e.ctrlKey || e.altKey || /^F\d+$/i.test(e.key || ''));
|
|
7773
|
+
if (hasMod || (activeTag !== 'INPUT' && activeTag !== 'TEXTAREA')) {
|
|
7774
|
+
e.preventDefault();
|
|
7775
|
+
const cmdArgs = Array.isArray(kbRule.args) ? kbRule.args : (kbRule.args !== undefined ? [kbRule.args] : []);
|
|
7776
|
+
this.commands.executeCommand(kbRule.command, ...cmdArgs).catch((err) => {
|
|
7777
|
+
this.logger.warn(`Keybinding command "${kbRule.command}" failed.`, err);
|
|
7778
|
+
});
|
|
7779
|
+
return;
|
|
7780
|
+
}
|
|
7781
|
+
}
|
|
7782
|
+
}
|
|
7783
|
+
if (e.key === 'Escape' && this.folderSwitcherOpen) {
|
|
6533
7784
|
this.folderSwitcherOpen = false;
|
|
6534
7785
|
this._renderBreadcrumbs();
|
|
6535
7786
|
return;
|
|
@@ -6539,6 +7790,15 @@ int main() {
|
|
|
6539
7790
|
this.openCommandPalette('commands');
|
|
6540
7791
|
return;
|
|
6541
7792
|
}
|
|
7793
|
+
if (e.key === 'F2' && !e.metaKey && !e.ctrlKey && !e.altKey) {
|
|
7794
|
+
const activeTag = e.target && e.target.tagName ? String(e.target.tagName).toUpperCase() : '';
|
|
7795
|
+
const inMonaco = e.target && typeof e.target.closest === 'function' && Boolean(e.target.closest('.monaco-editor'));
|
|
7796
|
+
if (!inMonaco && activeTag !== 'INPUT' && activeTag !== 'TEXTAREA' && this.activeFile) {
|
|
7797
|
+
e.preventDefault();
|
|
7798
|
+
this.startInlineRename('file', this.activeFile);
|
|
7799
|
+
return;
|
|
7800
|
+
}
|
|
7801
|
+
}
|
|
6542
7802
|
if ((e.metaKey || e.ctrlKey) && keyLower === 'k') {
|
|
6543
7803
|
e.preventDefault();
|
|
6544
7804
|
this.openCommandPalette('commands');
|
|
@@ -6563,6 +7823,9 @@ int main() {
|
|
|
6563
7823
|
}
|
|
6564
7824
|
}
|
|
6565
7825
|
if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
|
|
7826
|
+
if (e.defaultPrevented || (e.target && typeof e.target.closest === 'function' && e.target.closest('#cl-sql-editor-host'))) {
|
|
7827
|
+
return;
|
|
7828
|
+
}
|
|
6566
7829
|
e.preventDefault();
|
|
6567
7830
|
if (e.shiftKey) {
|
|
6568
7831
|
if (this.mode === 'guided') {
|
|
@@ -6922,6 +8185,9 @@ int main() {
|
|
|
6922
8185
|
if (action === 'run-code') this.runCode();
|
|
6923
8186
|
else if (action === 'run-entry') this.runEntry();
|
|
6924
8187
|
else if (action === 'run-active-file') this.runActiveFile();
|
|
8188
|
+
else if (action === 'explain-sql') this.runSql('explain');
|
|
8189
|
+
else if (action === 'open-settings') this.openSettings();
|
|
8190
|
+
else if (action === 'open-settings-json') this.openWorkspaceSettingsJson();
|
|
6925
8191
|
else if (action === 'open-stdin') this.switchDrawerTab('stdin');
|
|
6926
8192
|
else if (action === 'share-snapshot') this.shareSnapshot();
|
|
6927
8193
|
else if (action === 'run-demo') this.runDemo();
|
|
@@ -7178,6 +8444,12 @@ int main() {
|
|
|
7178
8444
|
this.logger.debug('Quick load test failed.', err);
|
|
7179
8445
|
});
|
|
7180
8446
|
}
|
|
8447
|
+
} else if (action === 'open-large-file-anyway') {
|
|
8448
|
+
const targetFile = actionBtn.dataset.clFile || this.activeFile;
|
|
8449
|
+
if (targetFile) {
|
|
8450
|
+
this._forceOpenedLargeFiles.add(targetFile);
|
|
8451
|
+
this._syncActiveFileToView();
|
|
8452
|
+
}
|
|
7181
8453
|
}
|
|
7182
8454
|
return;
|
|
7183
8455
|
}
|
|
@@ -7251,13 +8523,21 @@ int main() {
|
|
|
7251
8523
|
|
|
7252
8524
|
// ── VS Code Command Palette & Quick Open ────────────────────────────────
|
|
7253
8525
|
_getPaletteCommands() {
|
|
7254
|
-
|
|
8526
|
+
const builtin = [
|
|
7255
8527
|
{ id: 'run-code', label: 'CodeLab: Run Code (Entry or Active File)', shortcut: '⌘↵', action: () => this.runCode() },
|
|
7256
8528
|
{ id: 'run-active', label: 'CodeLab: Run Active File', shortcut: '⇧⌘↵', action: () => this.runActiveFile() },
|
|
7257
8529
|
{ id: 'run-demo', label: 'CodeLab: Run Demo Script', shortcut: '⇧⌘↵', action: () => this.runDemo() },
|
|
7258
8530
|
{ id: 'run-tests', label: 'CodeLab: Run Unit Tests', shortcut: '⌘↵', action: () => this.runTests() },
|
|
7259
8531
|
{ id: 'verify-step', label: 'CodeLab: Verify Current Guided Step', shortcut: '⌘↵', action: () => this.verifyCurrentStep() },
|
|
8532
|
+
{ id: 'sql-run', label: 'SQL: Run Query', shortcut: '⌘↵', action: () => this.runSql('run') },
|
|
8533
|
+
{ id: 'sql-explain', label: 'SQL: Explain Query Plan', action: () => this.runSql('explain') },
|
|
7260
8534
|
{ id: 'format-document', label: 'Editor: Format Document', shortcut: '⇧⌥F', action: () => this.formatActiveDocument() },
|
|
8535
|
+
{ id: 'open-settings', label: 'Preferences: Open Settings (UI)', shortcut: '⌘,', action: () => this.openSettings() },
|
|
8536
|
+
{ id: 'open-settings-json', label: 'Preferences: Open Workspace Settings (.codelab/settings.json)', action: () => this.openWorkspaceSettingsJson() },
|
|
8537
|
+
{ id: 'theme-dark', label: 'Preferences: Color Theme — Dark', action: () => this.setTheme('dark') },
|
|
8538
|
+
{ id: 'theme-light', label: 'Preferences: Color Theme — Light', action: () => this.setTheme('light') },
|
|
8539
|
+
{ id: 'theme-hc', label: 'Preferences: Color Theme — High Contrast', action: () => this.setTheme('high-contrast') },
|
|
8540
|
+
{ id: 'open-observability', label: 'Developer: Open Observability & Services Inspector', action: () => this.switchDrawerTab('observability') },
|
|
7261
8541
|
{ id: 'share-snapshot', label: 'CodeLab: Share Snapshot Link (#codelab=...)', action: () => this.shareSnapshot() },
|
|
7262
8542
|
{ id: 'open-stdin', label: 'View: Open Stdin / Custom Input Panel', action: () => this.switchDrawerTab('stdin') },
|
|
7263
8543
|
{ id: 'view-problems-tab', label: 'View: Focus Problems Drawer Tab', action: () => this.switchDrawerTab('problems') },
|
|
@@ -7271,10 +8551,11 @@ int main() {
|
|
|
7271
8551
|
{ id: 'export-workspace', label: 'Workspace: Export Workspace as JSON', action: () => this.exportWorkspace({ download: true }) },
|
|
7272
8552
|
{ id: 'export-workspace-zip', label: 'Workspace: Export Project as ZIP Archive', action: () => this.exportProjectZip({ download: true }) },
|
|
7273
8553
|
{ id: 'reset-workspace', label: 'Workspace: Reset Workspace to Clean State', action: () => this.resetLab() },
|
|
7274
|
-
{ id: 'switch-lang', label: 'Language: Switch JavaScript / TypeScript / C++ / Python', action: () => {
|
|
8554
|
+
{ id: 'switch-lang', label: 'Language: Switch JavaScript / TypeScript / C++ / Python / SQL', action: () => {
|
|
7275
8555
|
const order = ['js', 'ts'];
|
|
7276
8556
|
if (this.enabledLanguages && this.enabledLanguages.has('cpp')) order.push('cpp');
|
|
7277
8557
|
if (this.enabledLanguages && this.enabledLanguages.has('py')) order.push('py');
|
|
8558
|
+
if (this.enabledLanguages && this.enabledLanguages.has('sql')) order.push('sql');
|
|
7278
8559
|
const next = order[(order.indexOf(this.lang) + 1) % order.length] || 'js';
|
|
7279
8560
|
this.setLanguage(next);
|
|
7280
8561
|
} },
|
|
@@ -7292,6 +8573,55 @@ int main() {
|
|
|
7292
8573
|
{ id: 'open-packages', label: 'Packages: Manage NPM Dependencies & Runtime', action: () => this.showPackagesModal() },
|
|
7293
8574
|
{ id: 'git-clone', label: 'Git: Clone Public GitHub Repository...', action: () => this.showCloneRepoModal() }
|
|
7294
8575
|
];
|
|
8576
|
+
|
|
8577
|
+
if (Array.isArray(this._workspaceTasks)) {
|
|
8578
|
+
for (const task of this._workspaceTasks) {
|
|
8579
|
+
builtin.push({
|
|
8580
|
+
id: `task:${task.id}`,
|
|
8581
|
+
label: `Tasks: Run ${task.label} (${task.command})`,
|
|
8582
|
+
shortcut: '',
|
|
8583
|
+
action: () => this.runTask(task.id)
|
|
8584
|
+
});
|
|
8585
|
+
}
|
|
8586
|
+
}
|
|
8587
|
+
|
|
8588
|
+
if (this.commands && typeof this.commands.getCommands === 'function') {
|
|
8589
|
+
const builtinIds = new Set([
|
|
8590
|
+
...builtin.map((b) => b.id),
|
|
8591
|
+
'workbench.action.openSettings',
|
|
8592
|
+
'workbench.action.openWorkspaceSettingsJson',
|
|
8593
|
+
'workbench.action.quickOpen',
|
|
8594
|
+
'workbench.action.showCommands',
|
|
8595
|
+
'workbench.action.openObservability',
|
|
8596
|
+
'codeLab.runCode',
|
|
8597
|
+
'codeLab.runTests',
|
|
8598
|
+
'codeLab.runSql',
|
|
8599
|
+
'codeLab.explainSql',
|
|
8600
|
+
'codeLab.formatDocument',
|
|
8601
|
+
'tasks.runTask'
|
|
8602
|
+
]);
|
|
8603
|
+
const contributed = this.commands.getCommands(this.contextKeys || undefined);
|
|
8604
|
+
const mod = getModular();
|
|
8605
|
+
for (const cmd of contributed) {
|
|
8606
|
+
if (builtinIds.has(cmd.id)) continue;
|
|
8607
|
+
const kbRaw = this.keybindings ? this.keybindings.lookupKeybinding(cmd.id) : undefined;
|
|
8608
|
+
const shortcut = kbRaw && mod && typeof mod.formatShortcutBadge === 'function'
|
|
8609
|
+
? mod.formatShortcutBadge(kbRaw, true)
|
|
8610
|
+
: (kbRaw || '');
|
|
8611
|
+
builtin.push({
|
|
8612
|
+
id: cmd.id,
|
|
8613
|
+
label: cmd.category ? `${cmd.category}: ${cmd.title}` : cmd.title,
|
|
8614
|
+
shortcut,
|
|
8615
|
+
action: () => {
|
|
8616
|
+
this.commands.executeCommand(cmd.id).catch((err) => {
|
|
8617
|
+
this.logger.warn(`Command "${cmd.id}" threw.`, err);
|
|
8618
|
+
});
|
|
8619
|
+
}
|
|
8620
|
+
});
|
|
8621
|
+
}
|
|
8622
|
+
}
|
|
8623
|
+
|
|
8624
|
+
return builtin;
|
|
7295
8625
|
}
|
|
7296
8626
|
|
|
7297
8627
|
openCommandPalette(mode = 'commands') {
|
|
@@ -7345,6 +8675,7 @@ int main() {
|
|
|
7345
8675
|
this._renderPaletteList(input.value);
|
|
7346
8676
|
}
|
|
7347
8677
|
} else if (e.key === 'Enter') {
|
|
8678
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
7348
8679
|
e.preventDefault();
|
|
7349
8680
|
this._executePaletteSelection(this.paletteSelectedIndex);
|
|
7350
8681
|
} else if (e.key === 'Escape') {
|
|
@@ -7376,8 +8707,12 @@ int main() {
|
|
|
7376
8707
|
}));
|
|
7377
8708
|
} else {
|
|
7378
8709
|
const files = this._orderedFileNames();
|
|
7379
|
-
|
|
7380
|
-
|
|
8710
|
+
const mod = getModular();
|
|
8711
|
+
const excludePatterns = this.configuration ? this.configuration.get('search.exclude', []) : [];
|
|
8712
|
+
const ranked = (mod && typeof mod.rankWorkspaceFiles === 'function')
|
|
8713
|
+
? mod.rankWorkspaceFiles(files, query, Array.isArray(excludePatterns) ? excludePatterns : [])
|
|
8714
|
+
: files.filter(f => !query || f.toLowerCase().includes(query));
|
|
8715
|
+
items = ranked
|
|
7381
8716
|
.map(f => ({
|
|
7382
8717
|
type: 'file',
|
|
7383
8718
|
id: f,
|
|
@@ -7820,10 +9155,17 @@ int main() {
|
|
|
7820
9155
|
if (newMode !== 'guided' && newMode !== 'sandbox') return;
|
|
7821
9156
|
if (this.mode === newMode) return;
|
|
7822
9157
|
this.mode = newMode;
|
|
9158
|
+
if (this.contextKeys) {
|
|
9159
|
+
this.contextKeys.setContext('workbenchMode', this.mode);
|
|
9160
|
+
}
|
|
7823
9161
|
this.files = this._computeInitialFiles();
|
|
7824
9162
|
this.openTabs = this._orderedFileNames();
|
|
7825
9163
|
this.activeFile = this._pickDefaultFile();
|
|
7826
9164
|
this._saveState();
|
|
9165
|
+
if (this.kernel && this.kernel.fs) {
|
|
9166
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
9167
|
+
}
|
|
9168
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
7827
9169
|
|
|
7828
9170
|
this.container.querySelectorAll('[data-cl-mode]').forEach(btn => {
|
|
7829
9171
|
const isActive = btn.dataset.clMode === this.mode;
|
|
@@ -7837,6 +9179,10 @@ int main() {
|
|
|
7837
9179
|
primaryBtn.setAttribute('data-cl-action', 'verify-step');
|
|
7838
9180
|
primaryBtn.setAttribute('title', 'Verify Current Step (⌘+Enter)');
|
|
7839
9181
|
primaryBtn.innerHTML = `${CL_ICONS.check}<span>Verify Step</span><span class="codelab-btn__kbd">⌘↵</span>`;
|
|
9182
|
+
} else if (this.lang === 'sql') {
|
|
9183
|
+
primaryBtn.setAttribute('data-cl-action', 'run-code');
|
|
9184
|
+
primaryBtn.setAttribute('title', 'Run SQL Query (⌘+Enter)');
|
|
9185
|
+
primaryBtn.innerHTML = `${CL_ICONS.play}<span>Run Query</span><span class="codelab-btn__kbd">⌘↵</span>`;
|
|
7840
9186
|
} else {
|
|
7841
9187
|
primaryBtn.setAttribute('data-cl-action', 'run-tests');
|
|
7842
9188
|
primaryBtn.setAttribute('title', 'Run Test Suite (⌘+Enter)');
|
|
@@ -7880,22 +9226,36 @@ int main() {
|
|
|
7880
9226
|
}
|
|
7881
9227
|
|
|
7882
9228
|
setLanguage(newLang) {
|
|
7883
|
-
if (newLang !== 'js' && newLang !== 'ts' && newLang !== 'cpp' && newLang !== 'py') return;
|
|
9229
|
+
if (newLang !== 'js' && newLang !== 'ts' && newLang !== 'cpp' && newLang !== 'py' && newLang !== 'sql') return;
|
|
7884
9230
|
if (this.lang === newLang) return;
|
|
7885
9231
|
this.lang = newLang;
|
|
7886
9232
|
if (this.enabledLanguages instanceof Set) {
|
|
7887
9233
|
this.enabledLanguages.add(newLang);
|
|
7888
9234
|
}
|
|
9235
|
+
if (this.contextKeys) {
|
|
9236
|
+
this.contextKeys.setContext('editorLangId', this.lang);
|
|
9237
|
+
}
|
|
9238
|
+
if (this.plugins && typeof this.plugins.fireActivationEvent === 'function') {
|
|
9239
|
+
this.plugins.fireActivationEvent(`onLanguage:${this.lang}`).catch(() => {});
|
|
9240
|
+
}
|
|
7889
9241
|
this.files = this._computeInitialFiles();
|
|
7890
9242
|
this.openTabs = this._orderedFileNames();
|
|
7891
9243
|
this.activeFile = this._pickDefaultFile();
|
|
9244
|
+
if (this.lang === 'sql') {
|
|
9245
|
+
this.drawerTab = 'sql-results';
|
|
9246
|
+
}
|
|
7892
9247
|
this._saveState();
|
|
9248
|
+
if (this.kernel && this.kernel.fs) {
|
|
9249
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
9250
|
+
}
|
|
9251
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
7893
9252
|
|
|
7894
9253
|
if (typeof this._refreshToolbarAndTabs === 'function') {
|
|
7895
9254
|
this._refreshToolbarAndTabs();
|
|
7896
9255
|
} else {
|
|
7897
9256
|
this._refreshLanguageSwitcher();
|
|
7898
9257
|
}
|
|
9258
|
+
this._refreshDrawerTabs();
|
|
7899
9259
|
this.container.querySelectorAll('[data-cl-lang]').forEach(btn => {
|
|
7900
9260
|
const isActive = btn.dataset.clLang === this.lang;
|
|
7901
9261
|
btn.classList.toggle('active', isActive);
|
|
@@ -7905,6 +9265,7 @@ int main() {
|
|
|
7905
9265
|
this._syncAllModels();
|
|
7906
9266
|
this._syncActiveFileToView();
|
|
7907
9267
|
this._renderGuidePane();
|
|
9268
|
+
this._renderDrawerBody();
|
|
7908
9269
|
this._updateStatusBar();
|
|
7909
9270
|
}
|
|
7910
9271
|
|
|
@@ -7935,7 +9296,7 @@ int main() {
|
|
|
7935
9296
|
if (mode === 'guided' || mode === 'sandbox') {
|
|
7936
9297
|
this.setMode(mode);
|
|
7937
9298
|
}
|
|
7938
|
-
if (lang === 'js' || lang === 'ts' || lang === 'cpp' || lang === 'py') {
|
|
9299
|
+
if (lang === 'js' || lang === 'ts' || lang === 'cpp' || lang === 'py' || lang === 'sql') {
|
|
7939
9300
|
this.setLanguage(lang);
|
|
7940
9301
|
}
|
|
7941
9302
|
if (typeof stepIndex === 'number' && !Number.isNaN(stepIndex)) {
|
|
@@ -7989,6 +9350,32 @@ int main() {
|
|
|
7989
9350
|
this._handleInterrupt();
|
|
7990
9351
|
}
|
|
7991
9352
|
|
|
9353
|
+
cancelExecution() {
|
|
9354
|
+
this.stopExecution();
|
|
9355
|
+
}
|
|
9356
|
+
|
|
9357
|
+
toggleWebPreview() {
|
|
9358
|
+
if (this.previewState && this.previewState.dockMode === 'split') {
|
|
9359
|
+
this._togglePreviewDock();
|
|
9360
|
+
if (this.drawerTab === 'preview') {
|
|
9361
|
+
this.switchDrawerTab('terminal');
|
|
9362
|
+
}
|
|
9363
|
+
return;
|
|
9364
|
+
}
|
|
9365
|
+
if (this.drawerTab === 'preview') {
|
|
9366
|
+
this.switchDrawerTab('terminal');
|
|
9367
|
+
return;
|
|
9368
|
+
}
|
|
9369
|
+
const existingPort = (this.previewState && this.previewState.port) || this._firstListeningPort();
|
|
9370
|
+
if (existingPort) {
|
|
9371
|
+
this._openWebPreview(existingPort);
|
|
9372
|
+
} else if (this._hasWebContent()) {
|
|
9373
|
+
this.previewApp();
|
|
9374
|
+
} else {
|
|
9375
|
+
this._openWebPreview(3000);
|
|
9376
|
+
}
|
|
9377
|
+
}
|
|
9378
|
+
|
|
7992
9379
|
resetLab() {
|
|
7993
9380
|
this.completedSteps = new Set();
|
|
7994
9381
|
this.folders = new Set();
|
|
@@ -8010,6 +9397,10 @@ int main() {
|
|
|
8010
9397
|
delete this.savedState.hasSnapshot[key];
|
|
8011
9398
|
}
|
|
8012
9399
|
this._saveState();
|
|
9400
|
+
if (this.kernel && this.kernel.fs) {
|
|
9401
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
9402
|
+
}
|
|
9403
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
8013
9404
|
this._syncAllModels();
|
|
8014
9405
|
this._syncActiveFileToView();
|
|
8015
9406
|
this._renderStepPills();
|
|
@@ -8093,6 +9484,7 @@ int main() {
|
|
|
8093
9484
|
input.focus();
|
|
8094
9485
|
input.addEventListener('keydown', e => {
|
|
8095
9486
|
if (e.key === 'Enter' && input.value.trim()) {
|
|
9487
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
8096
9488
|
e.preventDefault();
|
|
8097
9489
|
this.addNpmPackage(input.value.trim());
|
|
8098
9490
|
}
|
|
@@ -8165,6 +9557,10 @@ int main() {
|
|
|
8165
9557
|
if (slot) slot.innerHTML = '';
|
|
8166
9558
|
}
|
|
8167
9559
|
|
|
9560
|
+
closeCommandPalette() {
|
|
9561
|
+
this.closeModal();
|
|
9562
|
+
}
|
|
9563
|
+
|
|
8168
9564
|
applyReferenceSolution() {
|
|
8169
9565
|
const refFiles = this._getBaseFilesForModeAndLang('sandbox', this.lang);
|
|
8170
9566
|
const targetFile = refFiles[this.activeFile] ? this.activeFile : this._pickDefaultFile();
|
|
@@ -8244,6 +9640,9 @@ int main() {
|
|
|
8244
9640
|
this.lastRunDurationMs = res && typeof res.durationMs === 'number' ? res.durationMs : elapsed;
|
|
8245
9641
|
this.lastDurationMs = this.lastRunDurationMs;
|
|
8246
9642
|
this.lastPeakMemoryBytes = res && typeof res.peakMemoryBytes === 'number' ? res.peakMemoryBytes : null;
|
|
9643
|
+
if (res && res.vfsChanges) {
|
|
9644
|
+
this._applyWorkerVfsDiffToWorkspace(res.vfsChanges);
|
|
9645
|
+
}
|
|
8247
9646
|
this._updateTelemetryHud();
|
|
8248
9647
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
8249
9648
|
return res;
|
|
@@ -8257,7 +9656,127 @@ int main() {
|
|
|
8257
9656
|
}
|
|
8258
9657
|
}
|
|
8259
9658
|
|
|
9659
|
+
_applyWorkerVfsDiffToWorkspace(vfsChanges) {
|
|
9660
|
+
if (!vfsChanges || typeof vfsChanges !== 'object') return;
|
|
9661
|
+
const { createdDirs = [], modifiedFiles = {}, deletedFiles = [] } = vfsChanges;
|
|
9662
|
+
let changed = false;
|
|
9663
|
+
|
|
9664
|
+
if (Array.isArray(createdDirs)) {
|
|
9665
|
+
for (const dir of createdDirs) {
|
|
9666
|
+
if (typeof dir === 'string' && dir.startsWith('/workspace/')) {
|
|
9667
|
+
const relDir = dir.slice('/workspace/'.length);
|
|
9668
|
+
if (relDir && !relDir.startsWith('.git') && !relDir.startsWith('node_modules')) {
|
|
9669
|
+
if (!this.folders.has(relDir)) {
|
|
9670
|
+
this.folders.add(relDir);
|
|
9671
|
+
changed = true;
|
|
9672
|
+
}
|
|
9673
|
+
}
|
|
9674
|
+
}
|
|
9675
|
+
if (this.shell && this.shell.vfs && typeof this.shell.vfs.mkdirSync === 'function') {
|
|
9676
|
+
try {
|
|
9677
|
+
this.shell.vfs.mkdirSync(dir, { recursive: true });
|
|
9678
|
+
} catch (err) {
|
|
9679
|
+
_bootDebug('_applyWorkerVfsDiffToWorkspace mkdirSync failed', dir, err);
|
|
9680
|
+
}
|
|
9681
|
+
}
|
|
9682
|
+
}
|
|
9683
|
+
}
|
|
9684
|
+
|
|
9685
|
+
if (modifiedFiles && typeof modifiedFiles === 'object') {
|
|
9686
|
+
const decoder = typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { fatal: false }) : null;
|
|
9687
|
+
for (const [absPath, rawData] of Object.entries(modifiedFiles)) {
|
|
9688
|
+
if (this.shell && this.shell.vfs && typeof this.shell.vfs.writeFileSync === 'function') {
|
|
9689
|
+
try {
|
|
9690
|
+
const slashIdx = absPath.lastIndexOf('/');
|
|
9691
|
+
if (slashIdx > 0 && typeof this.shell.vfs.mkdirSync === 'function') {
|
|
9692
|
+
this.shell.vfs.mkdirSync(absPath.slice(0, slashIdx), { recursive: true });
|
|
9693
|
+
}
|
|
9694
|
+
this.shell.vfs.writeFileSync(absPath, rawData);
|
|
9695
|
+
} catch (err) {
|
|
9696
|
+
_bootDebug('_applyWorkerVfsDiffToWorkspace writeFileSync failed', absPath, err);
|
|
9697
|
+
}
|
|
9698
|
+
}
|
|
9699
|
+
if (absPath.startsWith('/workspace/')) {
|
|
9700
|
+
const rel = absPath.slice('/workspace/'.length);
|
|
9701
|
+
if (!rel || rel.startsWith('.git/') || rel.startsWith('node_modules/')) continue;
|
|
9702
|
+
let textVal = '';
|
|
9703
|
+
let isLikelyBinary = false;
|
|
9704
|
+
if (typeof rawData === 'string') {
|
|
9705
|
+
textVal = rawData;
|
|
9706
|
+
} else if (rawData instanceof Uint8Array || ArrayBuffer.isView(rawData)) {
|
|
9707
|
+
const bytes = rawData instanceof Uint8Array
|
|
9708
|
+
? rawData
|
|
9709
|
+
: new Uint8Array(rawData.buffer, rawData.byteOffset, rawData.byteLength);
|
|
9710
|
+
const probeLen = Math.min(bytes.length, 512);
|
|
9711
|
+
for (let i = 0; i < probeLen; i++) {
|
|
9712
|
+
if (bytes[i] === 0) {
|
|
9713
|
+
isLikelyBinary = true;
|
|
9714
|
+
break;
|
|
9715
|
+
}
|
|
9716
|
+
}
|
|
9717
|
+
if (!isLikelyBinary) {
|
|
9718
|
+
textVal = decoder ? decoder.decode(bytes) : String.fromCharCode(...bytes);
|
|
9719
|
+
}
|
|
9720
|
+
}
|
|
9721
|
+
if (!isLikelyBinary && this.files[rel] !== textVal) {
|
|
9722
|
+
this.files[rel] = textVal;
|
|
9723
|
+
const parts = rel.split('/');
|
|
9724
|
+
let cur = '';
|
|
9725
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
9726
|
+
cur = cur ? `${cur}/${parts[i]}` : parts[i];
|
|
9727
|
+
this.folders.add(cur);
|
|
9728
|
+
}
|
|
9729
|
+
const model = this.models.get(rel);
|
|
9730
|
+
if (model && typeof model.getValue === 'function' && model.getValue() !== textVal) {
|
|
9731
|
+
model.setValue(textVal);
|
|
9732
|
+
}
|
|
9733
|
+
changed = true;
|
|
9734
|
+
}
|
|
9735
|
+
}
|
|
9736
|
+
}
|
|
9737
|
+
}
|
|
9738
|
+
|
|
9739
|
+
if (Array.isArray(deletedFiles)) {
|
|
9740
|
+
for (const absPath of deletedFiles) {
|
|
9741
|
+
if (this.shell && this.shell.vfs && typeof this.shell.vfs.unlinkSync === 'function') {
|
|
9742
|
+
try {
|
|
9743
|
+
this.shell.vfs.unlinkSync(absPath);
|
|
9744
|
+
} catch (err) {
|
|
9745
|
+
_bootDebug('_applyWorkerVfsDiffToWorkspace unlinkSync failed', absPath, err);
|
|
9746
|
+
}
|
|
9747
|
+
}
|
|
9748
|
+
if (absPath.startsWith('/workspace/')) {
|
|
9749
|
+
const rel = absPath.slice('/workspace/'.length);
|
|
9750
|
+
if (rel && Object.prototype.hasOwnProperty.call(this.files, rel)) {
|
|
9751
|
+
delete this.files[rel];
|
|
9752
|
+
const model = this.models.get(rel);
|
|
9753
|
+
if (model) {
|
|
9754
|
+
model.dispose();
|
|
9755
|
+
this.models.delete(rel);
|
|
9756
|
+
}
|
|
9757
|
+
if (Array.isArray(this.openTabs)) {
|
|
9758
|
+
const idx = this.openTabs.indexOf(rel);
|
|
9759
|
+
if (idx !== -1) this.openTabs.splice(idx, 1);
|
|
9760
|
+
}
|
|
9761
|
+
if (this.activeFile === rel) {
|
|
9762
|
+
this.activeFile = (this.openTabs && this.openTabs[0]) || null;
|
|
9763
|
+
}
|
|
9764
|
+
changed = true;
|
|
9765
|
+
}
|
|
9766
|
+
}
|
|
9767
|
+
}
|
|
9768
|
+
}
|
|
9769
|
+
|
|
9770
|
+
if (changed) {
|
|
9771
|
+
this._saveState();
|
|
9772
|
+
this._renderFileLists();
|
|
9773
|
+
}
|
|
9774
|
+
}
|
|
9775
|
+
|
|
8260
9776
|
async runCode() {
|
|
9777
|
+
if (this.lang === 'sql' || (this.activeFile && /\.sql$/i.test(this.activeFile))) {
|
|
9778
|
+
return this.runSql('run');
|
|
9779
|
+
}
|
|
8261
9780
|
const entry = this._findEntryFile('demo') || this.activeFile || this._pickDefaultFile();
|
|
8262
9781
|
if (!entry) {
|
|
8263
9782
|
this.terminalLogs.push({ type: 'stderr', text: 'No entry file or active file to run.' });
|
|
@@ -8265,9 +9784,95 @@ int main() {
|
|
|
8265
9784
|
this._renderDrawerBody();
|
|
8266
9785
|
return;
|
|
8267
9786
|
}
|
|
9787
|
+
if (/\.sql$/i.test(entry)) {
|
|
9788
|
+
return this.runSql('run');
|
|
9789
|
+
}
|
|
8268
9790
|
return this._executeEntryFile(entry);
|
|
8269
9791
|
}
|
|
8270
9792
|
|
|
9793
|
+
async runProject() {
|
|
9794
|
+
if (this.lang === 'sql') {
|
|
9795
|
+
return this.runSql('run');
|
|
9796
|
+
}
|
|
9797
|
+
const entry = this._findEntryFile('demo');
|
|
9798
|
+
if (!entry && this._hasWebContent() && typeof this.previewApp === 'function') {
|
|
9799
|
+
return this.previewApp();
|
|
9800
|
+
}
|
|
9801
|
+
return this.runCode();
|
|
9802
|
+
}
|
|
9803
|
+
|
|
9804
|
+
async runSelectedCode() {
|
|
9805
|
+
if (this.isRunning) return null;
|
|
9806
|
+
if (this.lang === 'sql' || (this.activeFile && /\.sql$/i.test(this.activeFile))) {
|
|
9807
|
+
const fullSql = (this.activeFile && typeof this.files[this.activeFile] === 'string') ? this.files[this.activeFile] : '';
|
|
9808
|
+
const selectedSql = this._sqlWorkbenchEditor ? this._sqlWorkbenchEditor.getSelection() : '';
|
|
9809
|
+
return this.runSql('run', {
|
|
9810
|
+
sql: fullSql,
|
|
9811
|
+
selectedSql,
|
|
9812
|
+
effectiveSql: (selectedSql && selectedSql.trim()) ? selectedSql : fullSql,
|
|
9813
|
+
dialect: this.sqlDialect
|
|
9814
|
+
});
|
|
9815
|
+
}
|
|
9816
|
+
let selectedText = '';
|
|
9817
|
+
if (this.editor && typeof this.editor.getSelection === 'function' && typeof this.editor.getModel === 'function') {
|
|
9818
|
+
const sel = this.editor.getSelection();
|
|
9819
|
+
const model = this.editor.getModel();
|
|
9820
|
+
if (sel && model && typeof model.getValueInRange === 'function') {
|
|
9821
|
+
selectedText = model.getValueInRange(sel) || '';
|
|
9822
|
+
}
|
|
9823
|
+
}
|
|
9824
|
+
if (!selectedText && this.container) {
|
|
9825
|
+
const fallback = this.container.querySelector('#cl-fallback-editor');
|
|
9826
|
+
if (fallback && typeof fallback.selectionStart === 'number' && typeof fallback.selectionEnd === 'number') {
|
|
9827
|
+
selectedText = String(fallback.value || '').slice(fallback.selectionStart, fallback.selectionEnd);
|
|
9828
|
+
}
|
|
9829
|
+
}
|
|
9830
|
+
if (!selectedText && this.activeFile && typeof this.files[this.activeFile] === 'string') {
|
|
9831
|
+
selectedText = this.files[this.activeFile];
|
|
9832
|
+
}
|
|
9833
|
+
const trimmed = String(selectedText || '').trim();
|
|
9834
|
+
if (!trimmed) return null;
|
|
9835
|
+
|
|
9836
|
+
this.isRunning = true;
|
|
9837
|
+
this._updateRunStateUI();
|
|
9838
|
+
this.drawerTab = 'terminal';
|
|
9839
|
+
this.terminalLogs.push({ type: 'system', text: '\n$ node -e "<selection>"' });
|
|
9840
|
+
this._renderDrawerBody();
|
|
9841
|
+
|
|
9842
|
+
const abortCtrl = new AbortController();
|
|
9843
|
+
this._activeCommandAbortController = abortCtrl;
|
|
9844
|
+
let streamedStdout = false;
|
|
9845
|
+
let streamedStderr = false;
|
|
9846
|
+
try {
|
|
9847
|
+
const res = await this._executeRuntime({
|
|
9848
|
+
files: { ...this.files },
|
|
9849
|
+
mode: 'repl',
|
|
9850
|
+
replCode: trimmed,
|
|
9851
|
+
signal: abortCtrl.signal,
|
|
9852
|
+
onStdout: (c) => { streamedStdout = true; this._appendTerminalStream('stdout', c); },
|
|
9853
|
+
onStderr: (c) => { streamedStderr = true; this._appendTerminalStream('stderr', c); }
|
|
9854
|
+
});
|
|
9855
|
+
this._flushTerminalStream();
|
|
9856
|
+
if (!streamedStdout && res && res.stdout) {
|
|
9857
|
+
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
9858
|
+
}
|
|
9859
|
+
if (!streamedStderr && res && res.stderr) {
|
|
9860
|
+
this.terminalLogs.push({ type: 'stderr', text: res.stderr.replace(/\n$/, '') });
|
|
9861
|
+
}
|
|
9862
|
+
if (res && res.replValue !== undefined) {
|
|
9863
|
+
this.terminalLogs.push({ type: 'success', text: `→ ${res.replValue}` });
|
|
9864
|
+
}
|
|
9865
|
+
this._renderDrawerBody();
|
|
9866
|
+
return res;
|
|
9867
|
+
} finally {
|
|
9868
|
+
if (this._activeCommandAbortController === abortCtrl) {
|
|
9869
|
+
this._activeCommandAbortController = null;
|
|
9870
|
+
}
|
|
9871
|
+
this.isRunning = false;
|
|
9872
|
+
this._updateRunStateUI();
|
|
9873
|
+
}
|
|
9874
|
+
}
|
|
9875
|
+
|
|
8271
9876
|
async runEntry() {
|
|
8272
9877
|
return this.runCode();
|
|
8273
9878
|
}
|
|
@@ -8280,6 +9885,9 @@ int main() {
|
|
|
8280
9885
|
this._renderDrawerBody();
|
|
8281
9886
|
return;
|
|
8282
9887
|
}
|
|
9888
|
+
if (/\.sql$/i.test(file) || this.lang === 'sql') {
|
|
9889
|
+
return this.runSql('run');
|
|
9890
|
+
}
|
|
8283
9891
|
return this._executeEntryFile(file);
|
|
8284
9892
|
}
|
|
8285
9893
|
|
|
@@ -8371,6 +9979,9 @@ int main() {
|
|
|
8371
9979
|
|
|
8372
9980
|
async runDemo() {
|
|
8373
9981
|
if (this.isRunning) return;
|
|
9982
|
+
if (this.lang === 'sql') {
|
|
9983
|
+
return this.runSql('run');
|
|
9984
|
+
}
|
|
8374
9985
|
const entry = this._findEntryFile('demo') || this._findEntryFile('entry') || this.activeFile;
|
|
8375
9986
|
if (!entry) {
|
|
8376
9987
|
if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
|
|
@@ -8381,6 +9992,9 @@ int main() {
|
|
|
8381
9992
|
this._renderDrawerBody();
|
|
8382
9993
|
return;
|
|
8383
9994
|
}
|
|
9995
|
+
if (/\.sql$/i.test(entry)) {
|
|
9996
|
+
return this.runSql('run');
|
|
9997
|
+
}
|
|
8384
9998
|
return this._executeEntryFile(entry);
|
|
8385
9999
|
}
|
|
8386
10000
|
|
|
@@ -8390,6 +10004,25 @@ int main() {
|
|
|
8390
10004
|
const code = this.files[file] || '';
|
|
8391
10005
|
if (!code) return;
|
|
8392
10006
|
|
|
10007
|
+
if (file.endsWith('.sql')) {
|
|
10008
|
+
const sqlPack = getSqlPack();
|
|
10009
|
+
const tabSize = this.configuration ? this.configuration.get('editor.tabSize', 2) : 2;
|
|
10010
|
+
const formatted = this._sqlWorkbenchEditor
|
|
10011
|
+
? this._sqlWorkbenchEditor.format()
|
|
10012
|
+
: (sqlPack && typeof sqlPack.formatSql === 'function'
|
|
10013
|
+
? sqlPack.formatSql(code, { dialect: this.sqlDialect, indent: Number(tabSize) || 2, keywordCase: 'upper' })
|
|
10014
|
+
: code);
|
|
10015
|
+
if (formatted !== code) {
|
|
10016
|
+
this.files[file] = formatted;
|
|
10017
|
+
if (this.editor && this.editor.getModel()) {
|
|
10018
|
+
this.editor.setValue(formatted);
|
|
10019
|
+
}
|
|
10020
|
+
this._saveState();
|
|
10021
|
+
this._notifyCodeChange(file, formatted);
|
|
10022
|
+
}
|
|
10023
|
+
return;
|
|
10024
|
+
}
|
|
10025
|
+
|
|
8393
10026
|
if (file.endsWith('.js') || file.endsWith('.ts') || file.endsWith('.jsx') || file.endsWith('.tsx')) {
|
|
8394
10027
|
if (this.editor && typeof this.editor.getAction === 'function') {
|
|
8395
10028
|
const action = this.editor.getAction('editor.action.formatDocument');
|
|
@@ -8517,7 +10150,7 @@ int main() {
|
|
|
8517
10150
|
const snapshot = await decompressor(token);
|
|
8518
10151
|
if (snapshot && snapshot.files && typeof snapshot.files === 'object') {
|
|
8519
10152
|
this.files = { ...snapshot.files };
|
|
8520
|
-
if (snapshot.lang && (snapshot.lang === 'js' || snapshot.lang === 'ts' || snapshot.lang === 'cpp' || snapshot.lang === 'py')) {
|
|
10153
|
+
if (snapshot.lang && (snapshot.lang === 'js' || snapshot.lang === 'ts' || snapshot.lang === 'cpp' || snapshot.lang === 'py' || snapshot.lang === 'sql')) {
|
|
8521
10154
|
this.lang = snapshot.lang;
|
|
8522
10155
|
}
|
|
8523
10156
|
if (snapshot.stdin) {
|
|
@@ -8541,6 +10174,12 @@ int main() {
|
|
|
8541
10174
|
async runTests(filterTestNames = null) {
|
|
8542
10175
|
if (this.isRunning) return;
|
|
8543
10176
|
const entry = this._findEntryFile('test');
|
|
10177
|
+
if (!entry && this.lang === 'sql') {
|
|
10178
|
+
return this.runSql('verify');
|
|
10179
|
+
}
|
|
10180
|
+
if (entry && /\.sql$/i.test(entry)) {
|
|
10181
|
+
return this.runSql('verify');
|
|
10182
|
+
}
|
|
8544
10183
|
if (!entry) {
|
|
8545
10184
|
this.terminalLogs.push({ type: 'stderr', text: 'No test file (test.js, test.ts, test.cpp, test.py) found in this workspace.' });
|
|
8546
10185
|
this.drawerTab = 'terminal';
|
|
@@ -8674,8 +10313,12 @@ int main() {
|
|
|
8674
10313
|
return lastRes;
|
|
8675
10314
|
}
|
|
8676
10315
|
|
|
8677
|
-
async verifyCurrentStep() {
|
|
8678
|
-
|
|
10316
|
+
async verifyCurrentStep(payloadOverride = null) {
|
|
10317
|
+
if (this.lang === 'sql' && !this._findEntryFile('test')) {
|
|
10318
|
+
await this.runSql('verify', payloadOverride);
|
|
10319
|
+
} else {
|
|
10320
|
+
await this.runTests();
|
|
10321
|
+
}
|
|
8679
10322
|
const step = this.steps[this.activeStepIndex];
|
|
8680
10323
|
if (step && this.completedSteps.has(step.id) && this.activeStepIndex < this.steps.length - 1) {
|
|
8681
10324
|
// Advance to next step and jump to its target symbol/TODO
|
|
@@ -8683,6 +10326,453 @@ int main() {
|
|
|
8683
10326
|
}
|
|
8684
10327
|
}
|
|
8685
10328
|
|
|
10329
|
+
setSqlSchema(schema) {
|
|
10330
|
+
this.sqlSchema = schema || null;
|
|
10331
|
+
if (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.setSchema === 'function') {
|
|
10332
|
+
this._sqlWorkbenchEditor.setSchema(this.sqlSchema);
|
|
10333
|
+
}
|
|
10334
|
+
return this;
|
|
10335
|
+
}
|
|
10336
|
+
|
|
10337
|
+
setSqlDialect(dialect) {
|
|
10338
|
+
this.sqlDialect = dialect === 'sqlite' ? 'sqlite' : 'postgres';
|
|
10339
|
+
this.runtimeStatusText = `Ready · ${this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18'}`;
|
|
10340
|
+
if (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.setDialect === 'function') {
|
|
10341
|
+
this._sqlWorkbenchEditor.setDialect(this.sqlDialect);
|
|
10342
|
+
}
|
|
10343
|
+
this._updateStatusBar();
|
|
10344
|
+
return this;
|
|
10345
|
+
}
|
|
10346
|
+
|
|
10347
|
+
async runSql(modeOverride = 'run', payloadOverride = null) {
|
|
10348
|
+
if (this.isRunning) return null;
|
|
10349
|
+
const runMode = (modeOverride === 'verify' || modeOverride === 'explain') ? modeOverride : 'run';
|
|
10350
|
+
const targetFile = (this.activeFile && /\.sql$/i.test(this.activeFile))
|
|
10351
|
+
? this.activeFile
|
|
10352
|
+
: (this._findEntryFile('demo') || this._pickDefaultFile() || 'query.sql');
|
|
10353
|
+
const fullSql = (payloadOverride && typeof payloadOverride.sql === 'string')
|
|
10354
|
+
? payloadOverride.sql
|
|
10355
|
+
: String(this.files[targetFile] ?? '');
|
|
10356
|
+
const selectedSql = (payloadOverride && typeof payloadOverride.selectedSql === 'string')
|
|
10357
|
+
? payloadOverride.selectedSql
|
|
10358
|
+
: (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.getSelection === 'function'
|
|
10359
|
+
? this._sqlWorkbenchEditor.getSelection()
|
|
10360
|
+
: '');
|
|
10361
|
+
const effectiveSql = (payloadOverride && typeof payloadOverride.effectiveSql === 'string')
|
|
10362
|
+
? payloadOverride.effectiveSql
|
|
10363
|
+
: ((selectedSql && selectedSql.trim()) ? selectedSql : fullSql);
|
|
10364
|
+
|
|
10365
|
+
const stepObj = (this.steps && this.steps[this.activeStepIndex]) ? this.steps[this.activeStepIndex] : null;
|
|
10366
|
+
const stepInfo = stepObj
|
|
10367
|
+
? { index: this.activeStepIndex, id: stepObj.id, title: stepObj.title }
|
|
10368
|
+
: null;
|
|
10369
|
+
|
|
10370
|
+
this.isRunning = true;
|
|
10371
|
+
this._updateRunStateUI();
|
|
10372
|
+
this._setRuntimeStatus('running', runMode === 'explain' ? 'Explaining SQL plan...' : 'Running SQL query...');
|
|
10373
|
+
const t0 = typeof performance !== 'undefined' ? performance.now() : Date.now();
|
|
10374
|
+
const sqlPack = getSqlPack();
|
|
10375
|
+
|
|
10376
|
+
let res = null;
|
|
10377
|
+
let caughtErr = null;
|
|
10378
|
+
try {
|
|
10379
|
+
if (typeof this.sqlRunner === 'function') {
|
|
10380
|
+
res = await this.sqlRunner({
|
|
10381
|
+
sql: fullSql,
|
|
10382
|
+
selectedSql,
|
|
10383
|
+
effectiveSql,
|
|
10384
|
+
dialect: this.sqlDialect,
|
|
10385
|
+
mode: runMode,
|
|
10386
|
+
step: stepInfo
|
|
10387
|
+
});
|
|
10388
|
+
} else if (root.CodeLabRuntime && typeof root.CodeLabRuntime.createSqliteDatabase === 'function') {
|
|
10389
|
+
const SqliteDb = root.CodeLabRuntime.createSqliteDatabase(this.shell ? this.shell.vfs : null, () => this.cwd || '/workspace');
|
|
10390
|
+
const db = new SqliteDb(':memory:');
|
|
10391
|
+
if (this.files['schema.sql'] && targetFile !== 'schema.sql') {
|
|
10392
|
+
db.exec(this.files['schema.sql']);
|
|
10393
|
+
}
|
|
10394
|
+
if (this.files['seed.sql'] && targetFile !== 'seed.sql') {
|
|
10395
|
+
db.exec(this.files['seed.sql']);
|
|
10396
|
+
}
|
|
10397
|
+
const trimmedSql = String(effectiveSql || '').trim();
|
|
10398
|
+
if (!trimmedSql) {
|
|
10399
|
+
res = { columns: [], rows: [], rowCount: 0, execMs: 0 };
|
|
10400
|
+
} else if (runMode === 'explain') {
|
|
10401
|
+
const explainStmt = /^EXPLAIN\b/i.test(trimmedSql)
|
|
10402
|
+
? trimmedSql
|
|
10403
|
+
: `EXPLAIN QUERY PLAN ${trimmedSql.replace(/;\s*$/, '')}`;
|
|
10404
|
+
const planRows = db.query(explainStmt).all();
|
|
10405
|
+
const planText = planRows.map((r) => r.detail || JSON.stringify(r)).join('\n');
|
|
10406
|
+
res = {
|
|
10407
|
+
columns: planRows.length > 0 ? Object.keys(planRows[0]) : ['id', 'parent', 'detail'],
|
|
10408
|
+
rows: planRows,
|
|
10409
|
+
rowCount: planRows.length,
|
|
10410
|
+
plan: planText
|
|
10411
|
+
};
|
|
10412
|
+
} else {
|
|
10413
|
+
const stmts = trimmedSql.split(';').map((s) => s.trim()).filter(Boolean);
|
|
10414
|
+
let lastRows = [];
|
|
10415
|
+
for (let i = 0; i < stmts.length; i++) {
|
|
10416
|
+
const st = stmts[i];
|
|
10417
|
+
if (/^(SELECT|WITH|PRAGMA|EXPLAIN)\b/i.test(st)) {
|
|
10418
|
+
lastRows = db.query(st).all();
|
|
10419
|
+
} else {
|
|
10420
|
+
db.run(st);
|
|
10421
|
+
}
|
|
10422
|
+
}
|
|
10423
|
+
const columns = lastRows.length > 0 ? Object.keys(lastRows[0]) : [];
|
|
10424
|
+
res = {
|
|
10425
|
+
columns,
|
|
10426
|
+
rows: lastRows,
|
|
10427
|
+
rowCount: lastRows.length
|
|
10428
|
+
};
|
|
10429
|
+
}
|
|
10430
|
+
} else {
|
|
10431
|
+
throw new Error('No SQL runner configured and built-in SQLite engine is unavailable.');
|
|
10432
|
+
}
|
|
10433
|
+
} catch (err) {
|
|
10434
|
+
caughtErr = err;
|
|
10435
|
+
} finally {
|
|
10436
|
+
this.isRunning = false;
|
|
10437
|
+
this._updateRunStateUI();
|
|
10438
|
+
}
|
|
10439
|
+
|
|
10440
|
+
const elapsed = Math.max(0, Math.round((typeof performance !== 'undefined' ? performance.now() : Date.now()) - t0));
|
|
10441
|
+
const rawError = caughtErr || (res && res.error ? res.error : null);
|
|
10442
|
+
|
|
10443
|
+
const diagMod = root.CodeLabDiagnostics;
|
|
10444
|
+
if (!this._diagnosticsStore && diagMod && typeof diagMod.createDiagnosticsStore === 'function') {
|
|
10445
|
+
this._diagnosticsStore = diagMod.createDiagnosticsStore();
|
|
10446
|
+
}
|
|
10447
|
+
|
|
10448
|
+
if (rawError) {
|
|
10449
|
+
const parsedDiag = (sqlPack && typeof sqlPack.parseSqlEngineError === 'function')
|
|
10450
|
+
? sqlPack.parseSqlEngineError(rawError, effectiveSql, this.sqlDialect)
|
|
10451
|
+
: {
|
|
10452
|
+
severity: 'error',
|
|
10453
|
+
message: rawError && rawError.message ? String(rawError.message) : String(rawError),
|
|
10454
|
+
line: 1,
|
|
10455
|
+
column: 1
|
|
10456
|
+
};
|
|
10457
|
+
if (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.setDiagnostics === 'function') {
|
|
10458
|
+
this._sqlWorkbenchEditor.setDiagnostics([parsedDiag]);
|
|
10459
|
+
}
|
|
10460
|
+
if (this._diagnosticsStore && typeof this._diagnosticsStore.setFileDiagnostics === 'function') {
|
|
10461
|
+
this._diagnosticsStore.setFileDiagnostics(targetFile, [{
|
|
10462
|
+
file: targetFile,
|
|
10463
|
+
line: parsedDiag.line || 1,
|
|
10464
|
+
column: parsedDiag.column || 1,
|
|
10465
|
+
severity: 'error',
|
|
10466
|
+
message: parsedDiag.hint ? `${parsedDiag.message} (Hint: ${parsedDiag.hint})` : parsedDiag.message,
|
|
10467
|
+
source: 'sql'
|
|
10468
|
+
}], 'sql');
|
|
10469
|
+
}
|
|
10470
|
+
this.lastSqlResult = {
|
|
10471
|
+
columns: [],
|
|
10472
|
+
rows: [],
|
|
10473
|
+
rowCount: 0,
|
|
10474
|
+
execMs: (res && typeof res.execMs === 'number') ? res.execMs : elapsed,
|
|
10475
|
+
error: parsedDiag.hint ? `${parsedDiag.message}\nHint: ${parsedDiag.hint}` : parsedDiag.message,
|
|
10476
|
+
verification: res && res.verification ? res.verification : undefined
|
|
10477
|
+
};
|
|
10478
|
+
this._setRuntimeStatus('error', 'SQL query error');
|
|
10479
|
+
} else {
|
|
10480
|
+
if (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.clearDiagnostics === 'function') {
|
|
10481
|
+
this._sqlWorkbenchEditor.clearDiagnostics();
|
|
10482
|
+
}
|
|
10483
|
+
if (this._diagnosticsStore && typeof this._diagnosticsStore.setFileDiagnostics === 'function') {
|
|
10484
|
+
this._diagnosticsStore.setFileDiagnostics(targetFile, [], 'sql');
|
|
10485
|
+
}
|
|
10486
|
+
const rows = (res && Array.isArray(res.rows)) ? res.rows : [];
|
|
10487
|
+
let cols = (res && Array.isArray(res.columns)) ? [...res.columns] : [];
|
|
10488
|
+
if (cols.length === 0 && rows.length > 0 && rows[0] && typeof rows[0] === 'object' && !Array.isArray(rows[0])) {
|
|
10489
|
+
cols = Object.keys(rows[0]);
|
|
10490
|
+
}
|
|
10491
|
+
const normalizedRows = rows.map((r) => {
|
|
10492
|
+
if (Array.isArray(r)) return r;
|
|
10493
|
+
if (r && typeof r === 'object') return cols.map((c) => r[c]);
|
|
10494
|
+
return [r];
|
|
10495
|
+
});
|
|
10496
|
+
this.lastSqlResult = {
|
|
10497
|
+
columns: cols,
|
|
10498
|
+
rows: normalizedRows,
|
|
10499
|
+
rowCount: (res && typeof res.rowCount === 'number') ? res.rowCount : normalizedRows.length,
|
|
10500
|
+
execMs: (res && typeof res.execMs === 'number') ? res.execMs : elapsed,
|
|
10501
|
+
plan: res && res.plan !== undefined
|
|
10502
|
+
? (typeof res.plan === 'string' ? res.plan : JSON.stringify(res.plan, null, 2))
|
|
10503
|
+
: undefined,
|
|
10504
|
+
verification: res && res.verification ? res.verification : undefined,
|
|
10505
|
+
error: null
|
|
10506
|
+
};
|
|
10507
|
+
this._setRuntimeStatus('idle', `Ready · ${this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18'}`);
|
|
10508
|
+
}
|
|
10509
|
+
|
|
10510
|
+
this.lastRunDurationMs = this.lastSqlResult.execMs;
|
|
10511
|
+
this.lastDurationMs = this.lastSqlResult.execMs;
|
|
10512
|
+
this.drawerTab = 'sql-results';
|
|
10513
|
+
this._refreshDrawerTabs();
|
|
10514
|
+
this._updateTelemetryHud();
|
|
10515
|
+
|
|
10516
|
+
if (
|
|
10517
|
+
!rawError &&
|
|
10518
|
+
(runMode === 'verify' || (this.hasGuidedLab && this.mode === 'guided')) &&
|
|
10519
|
+
stepObj &&
|
|
10520
|
+
(!this.lastSqlResult.verification || this.lastSqlResult.verification.passed !== false)
|
|
10521
|
+
) {
|
|
10522
|
+
if (!this.completedSteps.has(stepObj.id)) {
|
|
10523
|
+
this.completedSteps.add(stepObj.id);
|
|
10524
|
+
this._saveState();
|
|
10525
|
+
if (this.onStepComplete) {
|
|
10526
|
+
try { this.onStepComplete(stepObj, this.activeStepIndex); } catch (cbErr) { this.logger.error('onStepComplete callback threw.', cbErr); }
|
|
10527
|
+
}
|
|
10528
|
+
const stepDetail = {
|
|
10529
|
+
labId: this.labId,
|
|
10530
|
+
step: stepObj,
|
|
10531
|
+
stepId: stepObj.id,
|
|
10532
|
+
stepIndex: this.activeStepIndex,
|
|
10533
|
+
index: this.activeStepIndex,
|
|
10534
|
+
completedSteps: Array.from(this.completedSteps)
|
|
10535
|
+
};
|
|
10536
|
+
this._emitEvent('codelab:step-complete', stepDetail);
|
|
10537
|
+
this._emitEvent('codelab:step:pass', stepDetail);
|
|
10538
|
+
if (this.steps.length > 0 && this.completedSteps.size >= this.steps.length) {
|
|
10539
|
+
if (this.onLabComplete) {
|
|
10540
|
+
try { this.onLabComplete(this.labId); } catch (cbErr) { this.logger.error('onLabComplete callback threw.', cbErr); }
|
|
10541
|
+
}
|
|
10542
|
+
this._emitEvent('codelab:lab-complete', {
|
|
10543
|
+
labId: this.labId,
|
|
10544
|
+
completedSteps: Array.from(this.completedSteps)
|
|
10545
|
+
});
|
|
10546
|
+
}
|
|
10547
|
+
}
|
|
10548
|
+
}
|
|
10549
|
+
|
|
10550
|
+
this._renderStepPills();
|
|
10551
|
+
this._renderGuidePane();
|
|
10552
|
+
this._renderDrawerBody();
|
|
10553
|
+
this._updateStatusBar();
|
|
10554
|
+
|
|
10555
|
+
if (this.onRun) {
|
|
10556
|
+
try { this.onRun(this.lastSqlResult); } catch (cbErr) { this.logger.error('onRun callback threw.', cbErr); }
|
|
10557
|
+
}
|
|
10558
|
+
this._emitEvent('codelab:sql-run', { labId: this.labId, mode: runMode, result: this.lastSqlResult });
|
|
10559
|
+
this._emitEvent('codelab:run', { labId: this.labId, mode: runMode, entry: targetFile, result: this.lastSqlResult });
|
|
10560
|
+
return this.lastSqlResult;
|
|
10561
|
+
}
|
|
10562
|
+
|
|
10563
|
+
_syncDotCodelabConfig({ isInitialMount = false } = {}) {
|
|
10564
|
+
const mod = getModular();
|
|
10565
|
+
if (!mod || !this.configuration) return;
|
|
10566
|
+
|
|
10567
|
+
const diagMod = root.CodeLabDiagnostics;
|
|
10568
|
+
if (!this._diagnosticsStore && diagMod && typeof diagMod.createDiagnosticsStore === 'function') {
|
|
10569
|
+
this._diagnosticsStore = diagMod.createDiagnosticsStore();
|
|
10570
|
+
}
|
|
10571
|
+
|
|
10572
|
+
// 1. .codelab/settings.json
|
|
10573
|
+
const rawSettings = Object.prototype.hasOwnProperty.call(this.files, '.codelab/settings.json')
|
|
10574
|
+
? this.files['.codelab/settings.json']
|
|
10575
|
+
: '';
|
|
10576
|
+
const settingsDiags = this.configuration.loadWorkspaceSettingsJson(rawSettings || '', '.codelab/settings.json');
|
|
10577
|
+
if (this._diagnosticsStore && typeof this._diagnosticsStore.setFileDiagnostics === 'function') {
|
|
10578
|
+
this._diagnosticsStore.setFileDiagnostics(
|
|
10579
|
+
'.codelab/settings.json',
|
|
10580
|
+
settingsDiags.map((d) => ({
|
|
10581
|
+
file: d.file || '.codelab/settings.json',
|
|
10582
|
+
line: d.line || 1,
|
|
10583
|
+
column: d.column || 1,
|
|
10584
|
+
severity: d.severity || 'warning',
|
|
10585
|
+
message: d.message,
|
|
10586
|
+
source: 'settings'
|
|
10587
|
+
})),
|
|
10588
|
+
'settings'
|
|
10589
|
+
);
|
|
10590
|
+
}
|
|
10591
|
+
|
|
10592
|
+
// 2. .codelab/keybindings.json
|
|
10593
|
+
if (this.keybindings && typeof this.keybindings.setUserKeybindings === 'function') {
|
|
10594
|
+
const rawKb = Object.prototype.hasOwnProperty.call(this.files, '.codelab/keybindings.json')
|
|
10595
|
+
? this.files['.codelab/keybindings.json']
|
|
10596
|
+
: '';
|
|
10597
|
+
if (rawKb && rawKb.trim() && typeof mod.parseJsonc === 'function') {
|
|
10598
|
+
const parsedKb = mod.parseJsonc(rawKb);
|
|
10599
|
+
if (Array.isArray(parsedKb.value)) {
|
|
10600
|
+
const validRules = parsedKb.value.filter(
|
|
10601
|
+
(r) => r && typeof r === 'object' && typeof r.key === 'string' && typeof r.command === 'string'
|
|
10602
|
+
);
|
|
10603
|
+
this.keybindings.setUserKeybindings(validRules);
|
|
10604
|
+
}
|
|
10605
|
+
} else {
|
|
10606
|
+
this.keybindings.setUserKeybindings([]);
|
|
10607
|
+
}
|
|
10608
|
+
}
|
|
10609
|
+
|
|
10610
|
+
// 3. .codelab/tasks.json
|
|
10611
|
+
const rawTasks = Object.prototype.hasOwnProperty.call(this.files, '.codelab/tasks.json')
|
|
10612
|
+
? this.files['.codelab/tasks.json']
|
|
10613
|
+
: '';
|
|
10614
|
+
if (rawTasks && rawTasks.trim() && typeof mod.parseTasksConfig === 'function') {
|
|
10615
|
+
const parsedTasks = mod.parseTasksConfig(rawTasks, '.codelab/tasks.json');
|
|
10616
|
+
this._workspaceTasks = parsedTasks.tasks || [];
|
|
10617
|
+
if (this._diagnosticsStore && typeof this._diagnosticsStore.setFileDiagnostics === 'function') {
|
|
10618
|
+
this._diagnosticsStore.setFileDiagnostics(
|
|
10619
|
+
'.codelab/tasks.json',
|
|
10620
|
+
(parsedTasks.diagnostics || []).map((d) => ({
|
|
10621
|
+
file: '.codelab/tasks.json',
|
|
10622
|
+
line: d.line || 1,
|
|
10623
|
+
column: d.column || 1,
|
|
10624
|
+
severity: d.severity || 'warning',
|
|
10625
|
+
message: d.message,
|
|
10626
|
+
source: 'tasks'
|
|
10627
|
+
})),
|
|
10628
|
+
'tasks'
|
|
10629
|
+
);
|
|
10630
|
+
}
|
|
10631
|
+
if (isInitialMount) {
|
|
10632
|
+
for (const task of this._workspaceTasks) {
|
|
10633
|
+
if (task.runOn === 'folderOpen' && task.command) {
|
|
10634
|
+
Promise.resolve().then(() => this.runTask(task.id)).catch((err) => {
|
|
10635
|
+
this.logger.warn(`Auto-task "${task.label}" failed on folderOpen.`, err);
|
|
10636
|
+
});
|
|
10637
|
+
}
|
|
10638
|
+
}
|
|
10639
|
+
}
|
|
10640
|
+
} else {
|
|
10641
|
+
this._workspaceTasks = [];
|
|
10642
|
+
}
|
|
10643
|
+
|
|
10644
|
+
// 4. .codelab/extensions.json
|
|
10645
|
+
const rawExt = Object.prototype.hasOwnProperty.call(this.files, '.codelab/extensions.json')
|
|
10646
|
+
? this.files['.codelab/extensions.json']
|
|
10647
|
+
: '';
|
|
10648
|
+
if (rawExt && rawExt.trim() && typeof mod.parseExtensionsConfig === 'function' && this.plugins) {
|
|
10649
|
+
const parsedExt = mod.parseExtensionsConfig(rawExt, '.codelab/extensions.json');
|
|
10650
|
+
const toActivate = [
|
|
10651
|
+
...(parsedExt.config.autoActivate || []),
|
|
10652
|
+
...(parsedExt.config.recommendations || [])
|
|
10653
|
+
];
|
|
10654
|
+
for (const pluginId of toActivate) {
|
|
10655
|
+
this.plugins.activatePlugin(pluginId).catch(() => {});
|
|
10656
|
+
}
|
|
10657
|
+
}
|
|
10658
|
+
}
|
|
10659
|
+
|
|
10660
|
+
_applyConfigurationChanges(changeEvent) {
|
|
10661
|
+
if (!this.configuration) return;
|
|
10662
|
+
const affects = (key) => !changeEvent || typeof changeEvent.affectsConfiguration !== 'function' || changeEvent.affectsConfiguration(key);
|
|
10663
|
+
|
|
10664
|
+
if (affects('workbench.colorTheme') && changeEvent) {
|
|
10665
|
+
const rawTheme = String(this.configuration.get('workbench.colorTheme', 'dark'));
|
|
10666
|
+
const mapped = (rawTheme === 'light' || rawTheme === 'codelab-light')
|
|
10667
|
+
? 'light'
|
|
10668
|
+
: (rawTheme === 'high-contrast' || rawTheme === 'hc-dark' || rawTheme === 'codelab-hc-dark')
|
|
10669
|
+
? 'high-contrast'
|
|
10670
|
+
: (rawTheme === 'auto' ? 'auto' : 'dark');
|
|
10671
|
+
if (this.theme !== mapped) {
|
|
10672
|
+
this.setTheme(mapped);
|
|
10673
|
+
}
|
|
10674
|
+
}
|
|
10675
|
+
|
|
10676
|
+
if (affects('editor')) {
|
|
10677
|
+
const fontSize = Number(this.configuration.get('editor.fontSize', 13)) || 13;
|
|
10678
|
+
const fontFamily = String(this.configuration.get('editor.fontFamily', '') || '');
|
|
10679
|
+
const tabSize = Number(this.configuration.get('editor.tabSize', 2)) || 2;
|
|
10680
|
+
const wordWrap = String(this.configuration.get('editor.wordWrap', 'off'));
|
|
10681
|
+
const lineNumbers = String(this.configuration.get('editor.lineNumbers', 'on'));
|
|
10682
|
+
const minimapEnabled = Boolean(this.configuration.get('editor.minimap.enabled', false));
|
|
10683
|
+
|
|
10684
|
+
const shellEl = this.container ? this.container.querySelector('.codelab') : null;
|
|
10685
|
+
if (shellEl) {
|
|
10686
|
+
shellEl.style.setProperty('--cl-editor-font-size', `${fontSize}px`);
|
|
10687
|
+
if (fontFamily) {
|
|
10688
|
+
shellEl.style.setProperty('--cl-editor-font-family', fontFamily);
|
|
10689
|
+
}
|
|
10690
|
+
}
|
|
10691
|
+
const fallbackEl = this.container ? this.container.querySelector('#cl-fallback-editor') : null;
|
|
10692
|
+
if (fallbackEl) {
|
|
10693
|
+
fallbackEl.style.fontSize = `${fontSize}px`;
|
|
10694
|
+
}
|
|
10695
|
+
if (this.editor && typeof this.editor.updateOptions === 'function') {
|
|
10696
|
+
this.editor.updateOptions({
|
|
10697
|
+
fontSize,
|
|
10698
|
+
...(fontFamily ? { fontFamily } : {}),
|
|
10699
|
+
tabSize,
|
|
10700
|
+
wordWrap,
|
|
10701
|
+
lineNumbers,
|
|
10702
|
+
minimap: { enabled: minimapEnabled }
|
|
10703
|
+
});
|
|
10704
|
+
}
|
|
10705
|
+
}
|
|
10706
|
+
|
|
10707
|
+
if (affects('sql.dialect') && changeEvent) {
|
|
10708
|
+
const cfgDialect = this.configuration.get('sql.dialect', this.sqlDialect);
|
|
10709
|
+
if (cfgDialect === 'postgres' || cfgDialect === 'sqlite') {
|
|
10710
|
+
this.setSqlDialect(cfgDialect);
|
|
10711
|
+
}
|
|
10712
|
+
}
|
|
10713
|
+
}
|
|
10714
|
+
|
|
10715
|
+
openSettings() {
|
|
10716
|
+
const mod = getModular();
|
|
10717
|
+
if (!mod || typeof mod.SettingsDialogController !== 'function' || !this.configuration) {
|
|
10718
|
+
return this.openWorkspaceSettingsJson();
|
|
10719
|
+
}
|
|
10720
|
+
const host = (this.container && this.container.querySelector('.codelab')) || this.container;
|
|
10721
|
+
if (!host) return;
|
|
10722
|
+
if (!this._settingsDialog) {
|
|
10723
|
+
this._settingsDialog = new mod.SettingsDialogController(host, {
|
|
10724
|
+
configuration: this.configuration,
|
|
10725
|
+
onOpenSettingsJson: () => this.openWorkspaceSettingsJson(),
|
|
10726
|
+
onExportSettings: (jsonStr) => {
|
|
10727
|
+
if (typeof navigator !== 'undefined' && navigator.clipboard && typeof navigator.clipboard.writeText === 'function') {
|
|
10728
|
+
navigator.clipboard.writeText(jsonStr).catch(() => {});
|
|
10729
|
+
}
|
|
10730
|
+
this._showToast('Settings profile copied to clipboard', 'success');
|
|
10731
|
+
}
|
|
10732
|
+
});
|
|
10733
|
+
}
|
|
10734
|
+
this._settingsDialog.open();
|
|
10735
|
+
}
|
|
10736
|
+
|
|
10737
|
+
closeSettings() {
|
|
10738
|
+
if (this._settingsDialog && typeof this._settingsDialog.close === 'function') {
|
|
10739
|
+
this._settingsDialog.close();
|
|
10740
|
+
}
|
|
10741
|
+
}
|
|
10742
|
+
|
|
10743
|
+
openWorkspaceSettingsJson() {
|
|
10744
|
+
if (!Object.prototype.hasOwnProperty.call(this.files, '.codelab/settings.json')) {
|
|
10745
|
+
const defaultContent = this.configuration && typeof this.configuration.toWorkspaceJsonString === 'function'
|
|
10746
|
+
? this.configuration.toWorkspaceJsonString()
|
|
10747
|
+
: '{\n}\n';
|
|
10748
|
+
this.setFile('.codelab/settings.json', defaultContent, { open: true });
|
|
10749
|
+
} else {
|
|
10750
|
+
this.openFile('.codelab/settings.json');
|
|
10751
|
+
}
|
|
10752
|
+
}
|
|
10753
|
+
|
|
10754
|
+
async runTask(idOrLabel) {
|
|
10755
|
+
const tasks = Array.isArray(this._workspaceTasks) ? this._workspaceTasks : [];
|
|
10756
|
+
const found = tasks.find((t) => t.id === idOrLabel || t.label === idOrLabel);
|
|
10757
|
+
const commandStr = found ? found.command : (typeof idOrLabel === 'string' ? idOrLabel : '');
|
|
10758
|
+
if (!commandStr) return null;
|
|
10759
|
+
this.switchDrawerTab('terminal');
|
|
10760
|
+
return this._handleReplCommand(commandStr);
|
|
10761
|
+
}
|
|
10762
|
+
|
|
10763
|
+
registerPlugin(manifest) {
|
|
10764
|
+
if (!manifest || !this.plugins || typeof this.plugins.registerPlugin !== 'function') {
|
|
10765
|
+
return { dispose() {} };
|
|
10766
|
+
}
|
|
10767
|
+
const disp = this.plugins.registerPlugin(manifest);
|
|
10768
|
+
const events = Array.isArray(manifest.activationEvents) ? manifest.activationEvents : ['*'];
|
|
10769
|
+
if (events.includes(`onLanguage:${this.lang}`)) {
|
|
10770
|
+
this.plugins.activatePlugin(manifest.id).catch(() => {});
|
|
10771
|
+
}
|
|
10772
|
+
this._refreshDrawerTabs();
|
|
10773
|
+
return disp;
|
|
10774
|
+
}
|
|
10775
|
+
|
|
8686
10776
|
_resolveShellPath(rawPath) {
|
|
8687
10777
|
if (!rawPath || rawPath === '.') return this.cwd || '/workspace';
|
|
8688
10778
|
if (rawPath === '~') return '/workspace';
|
|
@@ -9015,7 +11105,7 @@ int main() {
|
|
|
9015
11105
|
if (data.mode === 'guided' || data.mode === 'sandbox') {
|
|
9016
11106
|
this.mode = data.mode;
|
|
9017
11107
|
}
|
|
9018
|
-
if (data.language === 'js' || data.language === 'ts' || data.language === 'cpp') {
|
|
11108
|
+
if (data.language === 'js' || data.language === 'ts' || data.language === 'cpp' || data.language === 'py' || data.language === 'sql') {
|
|
9019
11109
|
this.lang = data.language;
|
|
9020
11110
|
}
|
|
9021
11111
|
if (data.files && typeof data.files === 'object') {
|
|
@@ -9066,20 +11156,28 @@ int main() {
|
|
|
9066
11156
|
return this.exportProjectZip(options);
|
|
9067
11157
|
}
|
|
9068
11158
|
|
|
9069
|
-
importProjectZip(zipBytes) {
|
|
11159
|
+
importProjectZip(zipBytes, options = {}) {
|
|
9070
11160
|
const zipMod = root.CodeLabZip;
|
|
9071
11161
|
if (!zipMod || typeof zipMod.extractZip !== 'function') {
|
|
9072
11162
|
throw new Error('CodeLabZip engine is not loaded');
|
|
9073
11163
|
}
|
|
9074
11164
|
const extracted = zipMod.extractZip(zipBytes);
|
|
9075
11165
|
if (!extracted || typeof extracted !== 'object') return false;
|
|
9076
|
-
this.setFiles(extracted);
|
|
11166
|
+
this.setFiles(extracted, options);
|
|
9077
11167
|
this._syncFilesToShellVfs();
|
|
9078
11168
|
return true;
|
|
9079
11169
|
}
|
|
9080
11170
|
|
|
9081
|
-
importZip(zipBytes) {
|
|
9082
|
-
|
|
11171
|
+
importZip(zipBytes, options = {}) {
|
|
11172
|
+
const zipMod = root.CodeLabZip;
|
|
11173
|
+
if (!zipMod || typeof zipMod.extractZip !== 'function') {
|
|
11174
|
+
throw new Error('CodeLabZip engine is not loaded');
|
|
11175
|
+
}
|
|
11176
|
+
const extracted = zipMod.extractZip(zipBytes);
|
|
11177
|
+
if (!extracted || typeof extracted !== 'object') return 0;
|
|
11178
|
+
this.setFiles(extracted, options);
|
|
11179
|
+
this._syncFilesToShellVfs();
|
|
11180
|
+
return Object.keys(extracted).length;
|
|
9083
11181
|
}
|
|
9084
11182
|
|
|
9085
11183
|
async saveProjectToStorage(id) {
|
|
@@ -9303,6 +11401,7 @@ int main() {
|
|
|
9303
11401
|
replaceBtn.addEventListener('click', triggerReplace);
|
|
9304
11402
|
replaceInput.addEventListener('keydown', (e) => {
|
|
9305
11403
|
if (e.key === 'Enter') {
|
|
11404
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
9306
11405
|
e.preventDefault();
|
|
9307
11406
|
triggerReplace();
|
|
9308
11407
|
}
|
|
@@ -9501,6 +11600,10 @@ int main() {
|
|
|
9501
11600
|
this.activeFile = this._pickDefaultFile();
|
|
9502
11601
|
}
|
|
9503
11602
|
this._saveState();
|
|
11603
|
+
if (this.kernel && this.kernel.fs) {
|
|
11604
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
11605
|
+
}
|
|
11606
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
9504
11607
|
this._syncAllModels();
|
|
9505
11608
|
this._syncActiveFileToView();
|
|
9506
11609
|
}
|
|
@@ -9569,9 +11672,13 @@ int main() {
|
|
|
9569
11672
|
if (fallbackEl && this.activeFile === clean) {
|
|
9570
11673
|
fallbackEl.value = updated;
|
|
9571
11674
|
}
|
|
9572
|
-
if (this.shell && this.shell.vfs && typeof this.shell.vfs.writeFile === 'function') {
|
|
11675
|
+
if (this.shell && this.shell.vfs && (typeof this.shell.vfs.writeFileSync === 'function' || typeof this.shell.vfs.writeFile === 'function')) {
|
|
9573
11676
|
try {
|
|
9574
|
-
this.shell.vfs.
|
|
11677
|
+
if (typeof this.shell.vfs.writeFileSync === 'function') {
|
|
11678
|
+
this.shell.vfs.writeFileSync('/workspace/' + clean, updated);
|
|
11679
|
+
} else {
|
|
11680
|
+
this.shell.vfs.writeFile('/workspace/' + clean, updated);
|
|
11681
|
+
}
|
|
9575
11682
|
} catch (err) {
|
|
9576
11683
|
this.logger.warn(`Failed to sync markdown task toggle for "${clean}" to VFS.`, err);
|
|
9577
11684
|
}
|
|
@@ -9611,6 +11718,7 @@ int main() {
|
|
|
9611
11718
|
input.focus();
|
|
9612
11719
|
input.addEventListener('keydown', (e) => {
|
|
9613
11720
|
if (e.key === 'Enter' && input.value.trim()) {
|
|
11721
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
9614
11722
|
e.preventDefault();
|
|
9615
11723
|
const val = input.value.trim();
|
|
9616
11724
|
this.closeModal();
|
|
@@ -9788,6 +11896,8 @@ int main() {
|
|
|
9788
11896
|
plugin(this, pluginOptions);
|
|
9789
11897
|
} else if (typeof plugin === 'object' && typeof plugin.install === 'function') {
|
|
9790
11898
|
plugin.install(this, pluginOptions);
|
|
11899
|
+
} else if (typeof plugin === 'object' && typeof plugin.id === 'string' && typeof plugin.name === 'string') {
|
|
11900
|
+
this.registerPlugin(plugin);
|
|
9791
11901
|
}
|
|
9792
11902
|
if (this.enabledLanguages instanceof Set && this.enabledLanguages.size > 1) {
|
|
9793
11903
|
this.hasMultipleLanguages = true;
|
|
@@ -9801,11 +11911,65 @@ int main() {
|
|
|
9801
11911
|
}
|
|
9802
11912
|
|
|
9803
11913
|
destroy() {
|
|
11914
|
+
this._destroyed = true;
|
|
11915
|
+
this.flushState();
|
|
9804
11916
|
this.stopExecution();
|
|
11917
|
+
if (this._settingsDialog && typeof this._settingsDialog.dispose === 'function') {
|
|
11918
|
+
try { this._settingsDialog.dispose(); } catch (err) { this.logger.debug('settingsDialog dispose skipped.', err); }
|
|
11919
|
+
this._settingsDialog = null;
|
|
11920
|
+
}
|
|
11921
|
+
if (this._sqlWorkbenchEditor && typeof this._sqlWorkbenchEditor.destroy === 'function') {
|
|
11922
|
+
try { this._sqlWorkbenchEditor.destroy(); } catch (err) { this.logger.debug('sqlWorkbenchEditor destroy skipped.', err); }
|
|
11923
|
+
this._sqlWorkbenchEditor = null;
|
|
11924
|
+
}
|
|
11925
|
+
if (Array.isArray(this._pluginPanelDisposables)) {
|
|
11926
|
+
for (const d of this._pluginPanelDisposables) {
|
|
11927
|
+
if (d && typeof d.dispose === 'function') {
|
|
11928
|
+
try { d.dispose(); } catch (_err) { void _err; }
|
|
11929
|
+
}
|
|
11930
|
+
}
|
|
11931
|
+
this._pluginPanelDisposables = [];
|
|
11932
|
+
}
|
|
11933
|
+
if (this._errorBoundary && typeof this._errorBoundary.clear === 'function') {
|
|
11934
|
+
this._errorBoundary.clear();
|
|
11935
|
+
this._errorBoundary = null;
|
|
11936
|
+
}
|
|
11937
|
+
if (this.kernel && typeof this.kernel.dispose === 'function') {
|
|
11938
|
+
try { this.kernel.dispose(); } catch (err) { this.logger.debug('kernel dispose skipped.', err); }
|
|
11939
|
+
this.kernel = null;
|
|
11940
|
+
}
|
|
11941
|
+
if (this._saveDebounceTimer) {
|
|
11942
|
+
clearTimeout(this._saveDebounceTimer);
|
|
11943
|
+
this._saveDebounceTimer = null;
|
|
11944
|
+
}
|
|
11945
|
+
if (this._breadcrumbRafId && typeof cancelAnimationFrame === 'function') {
|
|
11946
|
+
cancelAnimationFrame(this._breadcrumbRafId);
|
|
11947
|
+
this._breadcrumbRafId = null;
|
|
11948
|
+
}
|
|
9805
11949
|
if (this._previewReloadTimer) {
|
|
9806
11950
|
clearTimeout(this._previewReloadTimer);
|
|
9807
11951
|
this._previewReloadTimer = null;
|
|
9808
11952
|
}
|
|
11953
|
+
if (Array.isArray(this._portListenerUnsubs)) {
|
|
11954
|
+
for (const unsub of this._portListenerUnsubs) {
|
|
11955
|
+
if (typeof unsub === 'function') {
|
|
11956
|
+
try { unsub(); } catch (err) { this.logger.debug('portTable listener unsubscribe skipped.', err); }
|
|
11957
|
+
}
|
|
11958
|
+
}
|
|
11959
|
+
this._portListenerUnsubs = [];
|
|
11960
|
+
this._portListenersBound = false;
|
|
11961
|
+
}
|
|
11962
|
+
if (this._portToasts instanceof Map) {
|
|
11963
|
+
for (const entry of this._portToasts.values()) {
|
|
11964
|
+
if (entry && entry.timer) clearTimeout(entry.timer);
|
|
11965
|
+
if (entry && entry.el && typeof entry.el.remove === 'function') entry.el.remove();
|
|
11966
|
+
}
|
|
11967
|
+
this._portToasts.clear();
|
|
11968
|
+
}
|
|
11969
|
+
if (this._markerDisposable && typeof this._markerDisposable.dispose === 'function') {
|
|
11970
|
+
try { this._markerDisposable.dispose(); } catch (err) { this.logger.debug('markerDisposable dispose skipped.', err); }
|
|
11971
|
+
this._markerDisposable = null;
|
|
11972
|
+
}
|
|
9809
11973
|
if (this._escHandler && typeof document !== 'undefined') {
|
|
9810
11974
|
document.removeEventListener('keydown', this._escHandler);
|
|
9811
11975
|
}
|
|
@@ -9861,12 +12025,10 @@ int main() {
|
|
|
9861
12025
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
9862
12026
|
if (!this._instance || oldVal === newVal) return;
|
|
9863
12027
|
if (name === 'theme') {
|
|
9864
|
-
this._instance.
|
|
9865
|
-
const rootEl = this.querySelector('.codelab');
|
|
9866
|
-
if (rootEl) rootEl.setAttribute('data-cl-theme', this._instance._resolvedTheme());
|
|
12028
|
+
this._instance.setTheme(newVal || 'auto');
|
|
9867
12029
|
} else if (name === 'mode' && (newVal === 'guided' || newVal === 'sandbox')) {
|
|
9868
12030
|
this._instance.switchMode(newVal);
|
|
9869
|
-
} else if ((name === 'language' || name === 'lang') && (newVal === 'js' || newVal === 'ts' || newVal === 'cpp')) {
|
|
12031
|
+
} else if ((name === 'language' || name === 'lang') && (newVal === 'js' || newVal === 'ts' || newVal === 'cpp' || newVal === 'py' || newVal === 'sql')) {
|
|
9870
12032
|
this._instance.switchLang(newVal);
|
|
9871
12033
|
} else if (name === 'title' && newVal) {
|
|
9872
12034
|
this._instance.title = newVal;
|
|
@@ -9923,35 +12085,51 @@ int main() {
|
|
|
9923
12085
|
}
|
|
9924
12086
|
|
|
9925
12087
|
getFiles() { return this._instance ? this._instance.getFiles() : {}; }
|
|
9926
|
-
setFiles(filesMap) {
|
|
9927
|
-
getFile(path) { return this._instance ? this._instance.getFile(path) :
|
|
9928
|
-
setFile(path, content, opts) {
|
|
9929
|
-
createFile(path, content) {
|
|
12088
|
+
setFiles(filesMap, opts) { return this._instance ? this._instance.setFiles(filesMap, opts) : undefined; }
|
|
12089
|
+
getFile(path) { return this._instance ? this._instance.getFile(path) : null; }
|
|
12090
|
+
setFile(path, content, opts) { return this._instance ? this._instance.setFile(path, content, opts) : undefined; }
|
|
12091
|
+
createFile(path, content) { return this._instance ? this._instance.createFile(path, content) : null; }
|
|
9930
12092
|
deleteFile(path) { return this._instance ? this._instance.deleteFile(path) : false; }
|
|
9931
12093
|
renameFile(oldPath, newPath) { return this._instance ? this._instance.renameFile(oldPath, newPath) : false; }
|
|
9932
12094
|
createFolder(path) { return this._instance ? this._instance.createFolder(path) : false; }
|
|
9933
12095
|
deleteFolder(path) { return this._instance ? this._instance.deleteFolder(path) : false; }
|
|
9934
12096
|
renameFolder(oldPath, newPath) { return this._instance ? this._instance.renameFolder(oldPath, newPath) : false; }
|
|
12097
|
+
moveFile(oldPath, newPath) { return this._instance ? this._instance.moveFile(oldPath, newPath) : false; }
|
|
12098
|
+
movePath(sourcePath, targetFolder) { return this._instance ? this._instance.movePath(sourcePath, targetFolder) : false; }
|
|
12099
|
+
startInlineCreate(type, folderPrefix) { if (this._instance) this._instance.startInlineCreate(type, folderPrefix); }
|
|
12100
|
+
startInlineRename(typeOrPath, maybeTarget) { if (this._instance) this._instance.startInlineRename(typeOrPath, maybeTarget); }
|
|
12101
|
+
promptNewFile(folderPrefix) { if (this._instance) this._instance.promptNewFile(folderPrefix); }
|
|
12102
|
+
promptNewFolder(folderPrefix) { if (this._instance) this._instance.promptNewFolder(folderPrefix); }
|
|
9935
12103
|
openFile(path, sym) { if (this._instance) this._instance.openFile(path, sym); }
|
|
9936
12104
|
closeTab(path) { if (this._instance) this._instance.closeTab(path); }
|
|
9937
12105
|
getOpenTabs() { return this._instance ? this._instance.getOpenTabs() : []; }
|
|
12106
|
+
setTheme(theme) { return this._instance ? this._instance.setTheme(theme) : undefined; }
|
|
12107
|
+
getTheme() { return this._instance ? this._instance.getTheme() : 'auto'; }
|
|
12108
|
+
switchDrawerTab(tab) { if (this._instance) this._instance.switchDrawerTab(tab); }
|
|
12109
|
+
toggleWebPreview() { if (this._instance) this._instance.toggleWebPreview(); }
|
|
9938
12110
|
openCommandPalette(mode) { if (this._instance) this._instance.openCommandPalette(mode); }
|
|
12111
|
+
closeCommandPalette() { if (this._instance) this._instance.closeCommandPalette(); }
|
|
9939
12112
|
showDiffModal(file, target) { if (this._instance) this._instance.showDiffModal(file, target); }
|
|
9940
12113
|
cloneRepo(repoInput, opts) { return this._instance ? this._instance.cloneRepo(repoInput, opts) : Promise.reject(new Error('Workbench not mounted')); }
|
|
9941
12114
|
runCode() { return this._instance ? this._instance.runCode() : Promise.resolve(); }
|
|
12115
|
+
runProject() { return this._instance ? this._instance.runProject() : Promise.resolve(); }
|
|
9942
12116
|
runEntry() { return this._instance ? this._instance.runEntry() : Promise.resolve(); }
|
|
9943
12117
|
runActiveFile() { return this._instance ? this._instance.runActiveFile() : Promise.resolve(); }
|
|
12118
|
+
runSelectedCode() { return this._instance ? this._instance.runSelectedCode() : Promise.resolve(null); }
|
|
9944
12119
|
runDemo() { return this._instance ? this._instance.runDemo() : Promise.resolve(); }
|
|
9945
12120
|
runTests(filter) { return this._instance ? this._instance.runTests(filter) : Promise.resolve(); }
|
|
9946
12121
|
formatActiveDocument() { return this._instance ? this._instance.formatActiveDocument() : Promise.resolve(); }
|
|
9947
12122
|
shareSnapshot() { return this._instance ? this._instance.shareSnapshot() : Promise.resolve(); }
|
|
9948
12123
|
previewApp() { return this._instance ? this._instance.previewApp() : Promise.resolve(null); }
|
|
9949
12124
|
stopExecution() { if (this._instance) this._instance.stopExecution(); }
|
|
9950
|
-
|
|
12125
|
+
cancelExecution() { if (this._instance) this._instance.cancelExecution(); }
|
|
12126
|
+
reset() { return this._instance ? this._instance.reset() : undefined; }
|
|
9951
12127
|
exportWorkspace(opts) { return this._instance ? this._instance.exportWorkspace(opts) : null; }
|
|
9952
12128
|
importWorkspace(snap) { return this._instance ? this._instance.importWorkspace(snap) : false; }
|
|
9953
12129
|
exportProjectZip(opts) { return this._instance ? this._instance.exportProjectZip(opts) : null; }
|
|
9954
|
-
importProjectZip(bytes) { return this._instance ? this._instance.importProjectZip(bytes) : false; }
|
|
12130
|
+
importProjectZip(bytes, opts) { return this._instance ? this._instance.importProjectZip(bytes, opts) : false; }
|
|
12131
|
+
exportZip(opts) { return this._instance ? this._instance.exportZip(opts) : null; }
|
|
12132
|
+
importZip(bytes, opts) { return this._instance ? this._instance.importZip(bytes, opts) : 0; }
|
|
9955
12133
|
searchWorkspace(opts) { return this._instance ? this._instance.searchWorkspace(opts) : null; }
|
|
9956
12134
|
replaceInWorkspace(opts) { return this._instance ? this._instance.replaceInWorkspace(opts) : null; }
|
|
9957
12135
|
getGitStatus() { return this._instance ? this._instance.getGitStatus() : []; }
|
|
@@ -9963,6 +12141,14 @@ int main() {
|
|
|
9963
12141
|
createTerminalSession(name) { return this._instance ? this._instance.createTerminalSession(name) : null; }
|
|
9964
12142
|
switchTerminalSession(id) { return this._instance ? this._instance.switchTerminalSession(id) : false; }
|
|
9965
12143
|
closeTerminalSession(id) { return this._instance ? this._instance.closeTerminalSession(id) : false; }
|
|
12144
|
+
openSettings() { if (this._instance) this._instance.openSettings(); }
|
|
12145
|
+
closeSettings() { if (this._instance) this._instance.closeSettings(); }
|
|
12146
|
+
openWorkspaceSettingsJson() { if (this._instance) this._instance.openWorkspaceSettingsJson(); }
|
|
12147
|
+
runSql(mode, payload) { return this._instance ? this._instance.runSql(mode, payload) : Promise.resolve(null); }
|
|
12148
|
+
setSqlSchema(schema) { if (this._instance) this._instance.setSqlSchema(schema); return this; }
|
|
12149
|
+
setSqlDialect(dialect) { if (this._instance) this._instance.setSqlDialect(dialect); return this; }
|
|
12150
|
+
runTask(idOrLabel) { return this._instance ? this._instance.runTask(idOrLabel) : Promise.resolve(null); }
|
|
12151
|
+
registerPlugin(manifest) { return this._instance ? this._instance.registerPlugin(manifest) : { dispose() {} }; }
|
|
9966
12152
|
on(ev, fn) { return this._instance ? this._instance.on(ev, fn) : () => {}; }
|
|
9967
12153
|
off(ev, fn) { if (this._instance) this._instance.off(ev, fn); }
|
|
9968
12154
|
use(plugin, opts) { if (this._instance) this._instance.use(plugin, opts); return this; }
|
|
@@ -10009,6 +12195,10 @@ int main() {
|
|
|
10009
12195
|
Runtime: root.CodeLabRuntime,
|
|
10010
12196
|
Shell: root.CodeLabShell,
|
|
10011
12197
|
Terminal: root.CodeLabTerminal,
|
|
12198
|
+
Modular: getModular(),
|
|
12199
|
+
sql: getSqlPack(),
|
|
12200
|
+
createSqlEditor: getSqlPack() ? getSqlPack().createSqlEditor : null,
|
|
12201
|
+
formatSql: getSqlPack() ? getSqlPack().formatSql : null,
|
|
10012
12202
|
zip: root.CodeLabZip || null,
|
|
10013
12203
|
createZip: root.CodeLabZip ? root.CodeLabZip.createZip : null,
|
|
10014
12204
|
extractZip: root.CodeLabZip ? root.CodeLabZip.extractZip : null,
|