@innovatorved/code-lab 0.3.1 → 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 +8 -4
- package/CHANGELOG.md +45 -0
- package/README.md +70 -158
- 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 +298 -2
- package/dist/code-lab.d.ts +110 -15
- package/dist/code-lab.esm.js +35284 -18253
- package/dist/code-lab.js +40434 -23431
- package/dist/code-lab.umd.js +65502 -0
- package/dist/diagnostics.d.ts +5 -0
- package/dist/extensions/cpp.esm.js +19532 -3772
- package/dist/extensions/cpp.js +19529 -3769
- 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 +19666 -3843
- package/dist/extensions/python.js +19668 -3845
- 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 +82 -24
- package/dist/runtime.d.ts +3 -3
- package/dist/runtime.esm.js +503 -73
- package/dist/runtime.js +501 -73
- package/dist/schemas.d.ts +234 -814
- package/dist/schemas.esm.js +19401 -3725
- package/dist/schemas.js +19404 -3728
- package/dist/scm.d.ts +13 -2
- package/dist/search.d.ts +5 -1
- package/dist/shell.d.ts +1 -1
- package/dist/shell.esm.js +435 -54
- package/dist/shell.js +435 -54
- package/dist/terminal.esm.js +242 -54
- package/dist/terminal.js +242 -54
- package/dist/workbench/diff-editor.d.ts +1 -0
- package/dist/workbench/index.d.ts +1 -1
- package/dist/workbench/styles.d.ts +1 -1
- package/dist/zip.d.ts +4 -3
- 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 +298 -2
- package/src/csp.ts +7 -10
- package/src/diagnostics.ts +42 -3
- package/src/extensions/cpp.ts +105 -24
- package/src/extensions/python.ts +260 -116
- 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 +73 -12
- package/src/runtime.ts +501 -74
- package/src/schemas.ts +62 -62
- package/src/scm.ts +106 -19
- package/src/search.ts +71 -27
- package/src/shell.ts +433 -53
- package/src/terminal.ts +239 -52
- package/src/workbench/diff-editor.ts +106 -18
- package/src/workbench/drawer.ts +17 -4
- package/src/workbench/guided-pane.ts +12 -2
- package/src/workbench/icons.ts +5 -2
- package/src/workbench/share.ts +37 -8
- package/src/workbench/styles.ts +2 -1
- package/src/workbench/toolbar.ts +15 -4
- package/src/workbench.ts +2877 -284
- package/src/zip.ts +29 -7
- 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 = `
|
|
@@ -632,11 +634,16 @@ declare module 'bun:sqlite' {
|
|
|
632
634
|
if (!str) return '';
|
|
633
635
|
let text = String(str);
|
|
634
636
|
|
|
635
|
-
// Markdown Links: [label](url "title") or [label](url) —
|
|
636
|
-
|
|
637
|
+
// Markdown Links: [label](url "title") or [label](url) — stash anchors before emphasis regexes
|
|
638
|
+
// so underscores/asterisks inside URLs or titles are not mangled, and use non-nested quantifiers.
|
|
639
|
+
const inlineLinks = [];
|
|
640
|
+
text = text.replace(/\[([^\]]+)\]\(([^\s()]+(?:\([^\s()]*\)[^\s()]*)*)(?:\s+"([^"]*)")?\)/g, (_, label, url, title) => {
|
|
637
641
|
const cleanUrl = sanitizeUrl(url);
|
|
638
642
|
const titleAttr = title ? raw(` title="${escapeHtml(title)}"`) : '';
|
|
639
|
-
|
|
643
|
+
const formattedLabel = renderInlineFormatting(label);
|
|
644
|
+
const idx = inlineLinks.length;
|
|
645
|
+
inlineLinks.push(String(html`<a href="${cleanUrl}" class="codelab-link" target="_blank" rel="noopener noreferrer"${titleAttr}>${raw(formattedLabel)}</a>`));
|
|
646
|
+
return `\x00CLLINK${idx}\x00`;
|
|
640
647
|
});
|
|
641
648
|
|
|
642
649
|
// Strikethrough: ~~del~~
|
|
@@ -654,6 +661,10 @@ declare module 'bun:sqlite' {
|
|
|
654
661
|
text = text.replace(/\*([^*\n]+)\*/g, '<em>$1</em>');
|
|
655
662
|
text = text.replace(/(^|[\s(])_([^_]+)_(?=[\s).,!?:;]|$)/g, '$1<em>$2</em>');
|
|
656
663
|
|
|
664
|
+
if (inlineLinks.length > 0) {
|
|
665
|
+
text = text.replace(/\x00CLLINK(\d+)\x00/g, (_, i) => inlineLinks[Number(i)] || '');
|
|
666
|
+
}
|
|
667
|
+
|
|
657
668
|
return text;
|
|
658
669
|
}
|
|
659
670
|
|
|
@@ -841,7 +852,7 @@ declare module 'bun:sqlite' {
|
|
|
841
852
|
const lang = (info || '').trim().split(/\s+/)[0] || '';
|
|
842
853
|
const idx = codeBlocks.length;
|
|
843
854
|
codeBlocks.push(renderCodeBlock(code || '', lang));
|
|
844
|
-
return `\n\n\
|
|
855
|
+
return `\n\n\x00CLCODEBLOCK${idx}\x00\n\n`;
|
|
845
856
|
});
|
|
846
857
|
|
|
847
858
|
// Phase 2: Inline Code Span Extraction
|
|
@@ -853,7 +864,7 @@ declare module 'bun:sqlite' {
|
|
|
853
864
|
}
|
|
854
865
|
const idx = inlineCodes.length;
|
|
855
866
|
inlineCodes.push(`<code class="codelab-inline-code">${escapeHtml(clean)}</code>`);
|
|
856
|
-
return `\
|
|
867
|
+
return `\x00CLINLINECODE${idx}\x00`;
|
|
857
868
|
});
|
|
858
869
|
|
|
859
870
|
// Phase 2b: Autolinks are the only inline construct that uses angle
|
|
@@ -866,7 +877,7 @@ declare module 'bun:sqlite' {
|
|
|
866
877
|
autolinks.push(
|
|
867
878
|
`<a href="${escapeHtml(safe)}" class="codelab-link" target="_blank" rel="noopener noreferrer">${escapeHtml(url)}</a>`
|
|
868
879
|
);
|
|
869
|
-
return `\
|
|
880
|
+
return `\x00CLAUTOLINK${idx}\x00`;
|
|
870
881
|
});
|
|
871
882
|
|
|
872
883
|
// Phase 2c: Neutralize all remaining raw HTML. Every tag needs a `<`, so
|
|
@@ -901,7 +912,7 @@ declare module 'bun:sqlite' {
|
|
|
901
912
|
}
|
|
902
913
|
const idx = calloutBlocks.length;
|
|
903
914
|
calloutBlocks.push(blockHtml);
|
|
904
|
-
return `\n\n\
|
|
915
|
+
return `\n\n\x00CLCALLOUT${idx}\x00\n\n`;
|
|
905
916
|
});
|
|
906
917
|
|
|
907
918
|
// Phase 4: GFM Tables with Column Alignments
|
|
@@ -911,7 +922,7 @@ declare module 'bun:sqlite' {
|
|
|
911
922
|
if (rendered === tableText) return match;
|
|
912
923
|
const idx = tableBlocks.length;
|
|
913
924
|
tableBlocks.push(rendered);
|
|
914
|
-
return `\n\n\
|
|
925
|
+
return `\n\n\x00CLTABLE${idx}\x00\n\n`;
|
|
915
926
|
});
|
|
916
927
|
|
|
917
928
|
// Phase 5: Task Lists & Nested Lists
|
|
@@ -920,7 +931,7 @@ declare module 'bun:sqlite' {
|
|
|
920
931
|
text = text.replace(/(?:^[ ]*(?:[-*+]|\d+\.)[ ]+[^\n]*(?:\n[ ]*(?:[-*+]|\d+\.)[ ]+[^\n]*|\n[ ]{2,}[^\n]*)*)+/gm, (match) => {
|
|
921
932
|
const idx = listBlocks.length;
|
|
922
933
|
listBlocks.push(renderListBlock(match, taskCounter));
|
|
923
|
-
return `\n\n\
|
|
934
|
+
return `\n\n\x00CLLIST${idx}\x00\n\n`;
|
|
924
935
|
});
|
|
925
936
|
|
|
926
937
|
// Phase 6: Headings, Horizontal Rules, Paragraphs & Inline Spans
|
|
@@ -942,18 +953,18 @@ declare module 'bun:sqlite' {
|
|
|
942
953
|
const trimmed = p.trim();
|
|
943
954
|
if (!trimmed) return '';
|
|
944
955
|
if (/^<(h[1-6]|hr|pre|div|blockquote|table|ul|ol)/i.test(trimmed)) return trimmed;
|
|
945
|
-
if (/^\
|
|
956
|
+
if (/^\x00CL(CODEBLOCK|CALLOUT|TABLE|LIST)\d+\x00$/.test(trimmed)) return trimmed;
|
|
946
957
|
return `<p>${renderInlineFormatting(trimmed).replace(/\n/g, '<br>')}</p>`;
|
|
947
958
|
}).filter(Boolean).join('\n');
|
|
948
959
|
|
|
949
960
|
// Phase 7: Placeholder Restoration (Reverse order)
|
|
950
961
|
let finalHtml = paras
|
|
951
|
-
.replace(/\
|
|
952
|
-
.replace(/\
|
|
953
|
-
.replace(/\
|
|
954
|
-
.replace(/\
|
|
955
|
-
.replace(/\
|
|
956
|
-
.replace(/\
|
|
962
|
+
.replace(/\x00CLLIST(\d+)\x00/g, (_, i) => listBlocks[Number(i)] || '')
|
|
963
|
+
.replace(/\x00CLTABLE(\d+)\x00/g, (_, i) => tableBlocks[Number(i)] || '')
|
|
964
|
+
.replace(/\x00CLCALLOUT(\d+)\x00/g, (_, i) => calloutBlocks[Number(i)] || '')
|
|
965
|
+
.replace(/\x00CLCODEBLOCK(\d+)\x00/g, (_, i) => codeBlocks[Number(i)] || '')
|
|
966
|
+
.replace(/\x00CLINLINECODE(\d+)\x00/g, (_, i) => inlineCodes[Number(i)] || '')
|
|
967
|
+
.replace(/\x00CLAUTOLINK(\d+)\x00/g, (_, i) => autolinks[Number(i)] || '');
|
|
957
968
|
|
|
958
969
|
return finalHtml;
|
|
959
970
|
}
|
|
@@ -971,8 +982,8 @@ declare module 'bun:sqlite' {
|
|
|
971
982
|
root.MonacoEnvironment = {
|
|
972
983
|
getWorkerUrl: function () {
|
|
973
984
|
const blobCode = `
|
|
974
|
-
self.MonacoEnvironment = { baseUrl:
|
|
975
|
-
importScripts(
|
|
985
|
+
self.MonacoEnvironment = { baseUrl: ${JSON.stringify(amdBaseUrl)} };
|
|
986
|
+
importScripts(${JSON.stringify(baseUrl + '/base/worker/workerMain.js')});
|
|
976
987
|
`;
|
|
977
988
|
return URL.createObjectURL(new Blob([blobCode], { type: 'application/javascript' }));
|
|
978
989
|
}
|
|
@@ -1135,18 +1146,49 @@ int main() {
|
|
|
1135
1146
|
`
|
|
1136
1147
|
};
|
|
1137
1148
|
|
|
1138
|
-
|
|
1139
|
-
|
|
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
|
+
}
|
|
1140
1182
|
if (lang === 'ts' && explicitTsFiles && Object.keys(explicitTsFiles).length > 0) {
|
|
1141
|
-
return { ...explicitTsFiles };
|
|
1183
|
+
return preserveConfigFiles({ ...explicitTsFiles });
|
|
1142
1184
|
}
|
|
1143
1185
|
if (lang === 'cpp') {
|
|
1144
1186
|
if (explicitCppFiles && Object.keys(explicitCppFiles).length > 0) {
|
|
1145
|
-
return { ...explicitCppFiles };
|
|
1187
|
+
return preserveConfigFiles({ ...explicitCppFiles });
|
|
1146
1188
|
}
|
|
1147
1189
|
const existingCpp = {};
|
|
1148
1190
|
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1149
|
-
if (/\.(cpp|cc|cxx|h|hpp|md)$/i.test(name)) {
|
|
1191
|
+
if (/\.(cpp|cc|cxx|h|hpp|md)$/i.test(name) || name.startsWith('.codelab/')) {
|
|
1150
1192
|
existingCpp[name] = content;
|
|
1151
1193
|
}
|
|
1152
1194
|
}
|
|
@@ -1157,15 +1199,15 @@ int main() {
|
|
|
1157
1199
|
if (filesObj && filesObj['README.md']) {
|
|
1158
1200
|
outCpp['README.md'] = filesObj['README.md'];
|
|
1159
1201
|
}
|
|
1160
|
-
return outCpp;
|
|
1202
|
+
return preserveConfigFiles(outCpp);
|
|
1161
1203
|
}
|
|
1162
1204
|
if (lang === 'py') {
|
|
1163
1205
|
if (explicitPyFiles && Object.keys(explicitPyFiles).length > 0) {
|
|
1164
|
-
return { ...explicitPyFiles };
|
|
1206
|
+
return preserveConfigFiles({ ...explicitPyFiles });
|
|
1165
1207
|
}
|
|
1166
1208
|
const existingPy = {};
|
|
1167
1209
|
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
1168
|
-
if (/\.(py|md)$/i.test(name)) {
|
|
1210
|
+
if (/\.(py|md)$/i.test(name) || name.startsWith('.codelab/')) {
|
|
1169
1211
|
existingPy[name] = content;
|
|
1170
1212
|
}
|
|
1171
1213
|
}
|
|
@@ -1176,7 +1218,7 @@ int main() {
|
|
|
1176
1218
|
if (filesObj && filesObj['README.md']) {
|
|
1177
1219
|
outPy['README.md'] = filesObj['README.md'];
|
|
1178
1220
|
}
|
|
1179
|
-
return outPy;
|
|
1221
|
+
return preserveConfigFiles(outPy);
|
|
1180
1222
|
}
|
|
1181
1223
|
const out = {};
|
|
1182
1224
|
for (const [name, content] of Object.entries(filesObj || {})) {
|
|
@@ -1193,8 +1235,8 @@ int main() {
|
|
|
1193
1235
|
}
|
|
1194
1236
|
|
|
1195
1237
|
const DEFAULT_STANDALONE_PYTHON_FILES = {
|
|
1196
|
-
'main.py': `"""
|
|
1197
|
-
'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`
|
|
1198
1240
|
};
|
|
1199
1241
|
|
|
1200
1242
|
const DEFAULT_STANDALONE_FILES = {
|
|
@@ -1243,8 +1285,11 @@ int main() {
|
|
|
1243
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>',
|
|
1244
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>',
|
|
1245
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>',
|
|
1246
|
-
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>',
|
|
1247
|
-
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>'
|
|
1248
1293
|
};
|
|
1249
1294
|
|
|
1250
1295
|
let _workbenchInstanceCounter = 0;
|
|
@@ -1411,7 +1456,21 @@ int main() {
|
|
|
1411
1456
|
const implData = root.IMPLEMENTATIONS_DATA?.[this.labId];
|
|
1412
1457
|
const guidedData = root.GUIDED_LABS_DATA?.[this.labId];
|
|
1413
1458
|
|
|
1414
|
-
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 || {};
|
|
1415
1474
|
this.referenceFiles = Object.keys(rawRefFiles).length > 0 ? { ...rawRefFiles } : { ...DEFAULT_STANDALONE_FILES };
|
|
1416
1475
|
|
|
1417
1476
|
this.guidedConfig = {
|
|
@@ -1423,7 +1482,9 @@ int main() {
|
|
|
1423
1482
|
...(options.cppStarterFiles ? { cppStarterFiles: options.cppStarterFiles } : {}),
|
|
1424
1483
|
...((options.cppSolutionFiles || options.cppFiles) ? { cppSolutionFiles: options.cppSolutionFiles || options.cppFiles } : {}),
|
|
1425
1484
|
...(options.pyStarterFiles ? { pyStarterFiles: options.pyStarterFiles } : {}),
|
|
1426
|
-
...((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 } : {})
|
|
1427
1488
|
};
|
|
1428
1489
|
this.steps = options.steps || this.guidedConfig?.steps || [];
|
|
1429
1490
|
this.hasGuidedLab = Boolean(
|
|
@@ -1431,11 +1492,25 @@ int main() {
|
|
|
1431
1492
|
options.guidedLab ||
|
|
1432
1493
|
(this.steps && this.steps.length > 0)
|
|
1433
1494
|
);
|
|
1434
|
-
|
|
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']);
|
|
1435
1508
|
if (Array.isArray(options.languages)) {
|
|
1509
|
+
this.enabledLanguages = new Set();
|
|
1436
1510
|
for (const l of options.languages) {
|
|
1437
|
-
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);
|
|
1438
1512
|
}
|
|
1513
|
+
if (this.enabledLanguages.size === 0) this.enabledLanguages.add('js');
|
|
1439
1514
|
}
|
|
1440
1515
|
if (
|
|
1441
1516
|
options.hasMultipleLanguages ||
|
|
@@ -1465,9 +1540,19 @@ int main() {
|
|
|
1465
1540
|
) {
|
|
1466
1541
|
this.enabledLanguages.add('py');
|
|
1467
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
|
+
}
|
|
1468
1553
|
this.hasMultipleLanguages = Boolean(
|
|
1469
1554
|
options.hasMultipleLanguages ||
|
|
1470
|
-
options.languages ||
|
|
1555
|
+
(Array.isArray(options.languages) && options.languages.length > 1) ||
|
|
1471
1556
|
this.enabledLanguages.size > 1 ||
|
|
1472
1557
|
this.guidedConfig.tsStarterFiles ||
|
|
1473
1558
|
this.guidedConfig.tsSolutionFiles ||
|
|
@@ -1478,7 +1563,7 @@ int main() {
|
|
|
1478
1563
|
this.guidedConfig.pyStarterFiles ||
|
|
1479
1564
|
this.guidedConfig.pySolutionFiles ||
|
|
1480
1565
|
this.guidedConfig.pyFiles ||
|
|
1481
|
-
(this.hasGuidedLab && (options.lang || options.language))
|
|
1566
|
+
(!isPureSqlInit && this.hasGuidedLab && (options.lang || options.language))
|
|
1482
1567
|
);
|
|
1483
1568
|
this.showWebPreviewOption = Boolean(options.showWebPreview);
|
|
1484
1569
|
this._diffManager = null;
|
|
@@ -1488,6 +1573,21 @@ int main() {
|
|
|
1488
1573
|
|
|
1489
1574
|
this.mode = options.mode || this.savedState.mode || (this.hasGuidedLab ? 'guided' : 'sandbox');
|
|
1490
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
|
+
|
|
1491
1591
|
this.activeStepIndex = typeof options.stepIndex === 'number' ? options.stepIndex : (this.savedState.activeStepIndex || 0);
|
|
1492
1592
|
if (this.activeStepIndex >= this.steps.length || this.activeStepIndex < 0) this.activeStepIndex = 0;
|
|
1493
1593
|
|
|
@@ -1508,7 +1608,9 @@ int main() {
|
|
|
1508
1608
|
this.renamingItem = null;
|
|
1509
1609
|
this._draggedFile = null;
|
|
1510
1610
|
this.guideTab = 'steps'; // 'steps' | 'readme'
|
|
1511
|
-
this.drawerTab =
|
|
1611
|
+
this.drawerTab = this.lang === 'sql'
|
|
1612
|
+
? 'sql-results'
|
|
1613
|
+
: ((this.hasGuidedLab && this.mode === 'guided') ? 'tests' : 'terminal');
|
|
1512
1614
|
this.testSuiteVisible = Boolean(this.hasGuidedLab && this.mode === 'guided');
|
|
1513
1615
|
this.lastDurationMs = null;
|
|
1514
1616
|
this.lastPeakMemoryBytes = null;
|
|
@@ -1551,7 +1653,9 @@ int main() {
|
|
|
1551
1653
|
this.cursorPos = { lineNumber: 1, column: 1 };
|
|
1552
1654
|
this.lastRunDurationMs = null;
|
|
1553
1655
|
this.runtimeStatusState = 'idle';
|
|
1554
|
-
this.runtimeStatusText =
|
|
1656
|
+
this.runtimeStatusText = this.lang === 'sql'
|
|
1657
|
+
? `${this.sqlDialect === 'sqlite' ? 'SQLite 3' : 'PostgreSQL 18'} · Idle`
|
|
1658
|
+
: 'Node.js v22 Worker · Idle';
|
|
1555
1659
|
|
|
1556
1660
|
// Initialize working files for current mode & language
|
|
1557
1661
|
this.files = this._computeInitialFiles();
|
|
@@ -1647,11 +1751,20 @@ int main() {
|
|
|
1647
1751
|
this.monaco = null;
|
|
1648
1752
|
this.editor = null;
|
|
1649
1753
|
this.models = new Map();
|
|
1650
|
-
|
|
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();
|
|
1651
1762
|
this._renderShell();
|
|
1652
1763
|
this._bindEvents();
|
|
1653
1764
|
this._initEditor();
|
|
1765
|
+
this._syncDotCodelabConfig({ isInitialMount: true });
|
|
1654
1766
|
this._checkUrlSnapshot();
|
|
1767
|
+
this._hydrateFromAsyncStorage();
|
|
1655
1768
|
|
|
1656
1769
|
const initialPlugins = [
|
|
1657
1770
|
...(Array.isArray(options.extensions) ? options.extensions : []),
|
|
@@ -1661,6 +1774,12 @@ int main() {
|
|
|
1661
1774
|
this.use(plugin);
|
|
1662
1775
|
}
|
|
1663
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
|
+
|
|
1664
1783
|
if (options.repo && typeof options.repo === 'string') {
|
|
1665
1784
|
this.cloneRepo(options.repo, {
|
|
1666
1785
|
intoRoot: options.cloneIntoRoot !== false,
|
|
@@ -1670,6 +1789,169 @@ int main() {
|
|
|
1670
1789
|
}
|
|
1671
1790
|
}
|
|
1672
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
|
+
|
|
1673
1955
|
_initShell() {
|
|
1674
1956
|
this._wrapPortTable();
|
|
1675
1957
|
this._initPortListeners();
|
|
@@ -1858,16 +2140,99 @@ int main() {
|
|
|
1858
2140
|
}
|
|
1859
2141
|
|
|
1860
2142
|
_resolvedTheme() {
|
|
1861
|
-
if (this.themeOption === 'light' || this.themeOption === 'dark') {
|
|
2143
|
+
if (this.themeOption === 'light' || this.themeOption === 'dark' || this.themeOption === 'high-contrast') {
|
|
1862
2144
|
return this.themeOption;
|
|
1863
2145
|
}
|
|
1864
|
-
if (typeof document !== 'undefined') {
|
|
2146
|
+
if (typeof document !== 'undefined' && document.documentElement && typeof document.documentElement.getAttribute === 'function') {
|
|
1865
2147
|
const docTheme = document.documentElement.getAttribute('data-theme');
|
|
1866
|
-
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
|
+
}
|
|
1867
2157
|
}
|
|
1868
2158
|
return 'dark';
|
|
1869
2159
|
}
|
|
1870
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
|
+
|
|
1871
2236
|
_storageKey() {
|
|
1872
2237
|
return `${STORAGE_PREFIX}${this.labId}`;
|
|
1873
2238
|
}
|
|
@@ -1910,33 +2275,124 @@ int main() {
|
|
|
1910
2275
|
return error;
|
|
1911
2276
|
}
|
|
1912
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
|
+
|
|
1913
2389
|
_saveState() {
|
|
1914
2390
|
try {
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
(this.savedState && this.savedState.hasSnapshot) || {},
|
|
1921
|
-
{ [key]: true }
|
|
1922
|
-
);
|
|
1923
|
-
const completedArr = Array.from(this.completedSteps);
|
|
1924
|
-
const state = {
|
|
1925
|
-
mode: this.mode,
|
|
1926
|
-
lang: this.lang,
|
|
1927
|
-
activeStepIndex: this.activeStepIndex,
|
|
1928
|
-
completedSteps: completedArr,
|
|
1929
|
-
customFiles,
|
|
1930
|
-
hasSnapshot,
|
|
1931
|
-
openTabs: Array.isArray(this.openTabs) ? [...this.openTabs] : undefined,
|
|
1932
|
-
activeFile: this.activeFile,
|
|
1933
|
-
folders: Array.from(this.folders || []),
|
|
1934
|
-
collapsedFolders: Array.from(this.collapsedFolders || []),
|
|
1935
|
-
explorerFolder: this.explorerFolder || '',
|
|
1936
|
-
explorerWidth: typeof this.explorerWidth === 'number' ? this.explorerWidth : undefined,
|
|
1937
|
-
previewSplitWidth: this.previewSplitWidth || undefined
|
|
1938
|
-
};
|
|
1939
|
-
this.savedState = state;
|
|
2391
|
+
if (this._saveDebounceTimer) {
|
|
2392
|
+
clearTimeout(this._saveDebounceTimer);
|
|
2393
|
+
this._saveDebounceTimer = null;
|
|
2394
|
+
}
|
|
2395
|
+
const { state, completedArr } = this._buildSavedStateSnapshot();
|
|
1940
2396
|
if (this.options && this.options.persistState === false) {
|
|
1941
2397
|
this.saveStatusState = 'saved';
|
|
1942
2398
|
this.saveStatusError = null;
|
|
@@ -1947,22 +2403,43 @@ int main() {
|
|
|
1947
2403
|
const serialized = JSON.stringify(state);
|
|
1948
2404
|
safeStorageSet._lastError = null;
|
|
1949
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
|
+
});
|
|
1950
2414
|
const persisted = [
|
|
1951
2415
|
safeStorageSet(this._storageKey(), serialized, this.logger, recordErr),
|
|
1952
|
-
// Sync with host app sidebar
|
|
2416
|
+
// Sync lightweight step-completion progress & compact metadata with host app sidebar trackers
|
|
1953
2417
|
safeStorageSet('codelab_progress_' + this.labId, JSON.stringify(completedArr), this.logger, recordErr),
|
|
1954
|
-
safeStorageSet('sd_codelab_' + this.labId,
|
|
2418
|
+
safeStorageSet('sd_codelab_' + this.labId, hostMirrorSummary, this.logger, recordErr)
|
|
1955
2419
|
];
|
|
1956
2420
|
if (root.CodeLabStorage && typeof root.CodeLabStorage.createWorkspaceStorage === 'function') {
|
|
1957
2421
|
try {
|
|
1958
2422
|
if (!this._idbStorage) {
|
|
1959
|
-
this._idbStorage = root.CodeLabStorage.createWorkspaceStorage(
|
|
1960
|
-
}
|
|
1961
|
-
if (this._idbStorage && typeof this._idbStorage.save === 'function') {
|
|
1962
|
-
Promise.resolve(this._idbStorage.save(this.labId, state)).catch((err) => {
|
|
1963
|
-
this.logger.debug('Async WorkspaceStorage save skipped.', err);
|
|
1964
|
-
});
|
|
2423
|
+
this._idbStorage = root.CodeLabStorage.createWorkspaceStorage();
|
|
1965
2424
|
}
|
|
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
|
+
});
|
|
1966
2443
|
} catch (err) {
|
|
1967
2444
|
this.logger.debug('WorkspaceStorage initialization skipped.', err);
|
|
1968
2445
|
}
|
|
@@ -2097,13 +2574,15 @@ int main() {
|
|
|
2097
2574
|
curEl.textContent = `Ln ${this.cursorPos.lineNumber || 1}, Col ${this.cursorPos.column || 1}`;
|
|
2098
2575
|
}
|
|
2099
2576
|
if (langEl) {
|
|
2100
|
-
langEl.textContent = this.lang === '
|
|
2101
|
-
? '
|
|
2102
|
-
: this.lang === '
|
|
2103
|
-
? '
|
|
2104
|
-
: this.lang === '
|
|
2105
|
-
? '
|
|
2106
|
-
:
|
|
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)';
|
|
2107
2586
|
}
|
|
2108
2587
|
this._updateTelemetryHud();
|
|
2109
2588
|
}
|
|
@@ -2114,13 +2593,23 @@ int main() {
|
|
|
2114
2593
|
...this.referenceFiles,
|
|
2115
2594
|
...(this.guidedConfig?.starterFiles || {})
|
|
2116
2595
|
};
|
|
2117
|
-
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
|
+
) {
|
|
2118
2606
|
return mapFilesToLanguage(
|
|
2119
2607
|
baseJsStarter,
|
|
2120
2608
|
lang,
|
|
2121
2609
|
this.guidedConfig?.tsStarterFiles,
|
|
2122
2610
|
this.guidedConfig?.cppStarterFiles,
|
|
2123
|
-
this.guidedConfig?.pyStarterFiles
|
|
2611
|
+
this.guidedConfig?.pyStarterFiles,
|
|
2612
|
+
this.guidedConfig?.sqlStarterFiles
|
|
2124
2613
|
);
|
|
2125
2614
|
}
|
|
2126
2615
|
return mapFilesToLanguage(
|
|
@@ -2128,7 +2617,8 @@ int main() {
|
|
|
2128
2617
|
lang,
|
|
2129
2618
|
this.guidedConfig?.tsSolutionFiles,
|
|
2130
2619
|
this.guidedConfig?.cppSolutionFiles,
|
|
2131
|
-
this.guidedConfig?.pySolutionFiles
|
|
2620
|
+
this.guidedConfig?.pySolutionFiles,
|
|
2621
|
+
this.guidedConfig?.sqlSolutionFiles
|
|
2132
2622
|
);
|
|
2133
2623
|
}
|
|
2134
2624
|
|
|
@@ -2150,8 +2640,29 @@ int main() {
|
|
|
2150
2640
|
return base;
|
|
2151
2641
|
}
|
|
2152
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
|
+
|
|
2153
2651
|
_pickDefaultFile() {
|
|
2154
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
|
+
}
|
|
2155
2666
|
if (this.lang === 'py') {
|
|
2156
2667
|
if (this.guidedConfig?.mainFile) {
|
|
2157
2668
|
const pyMain = this.guidedConfig.mainFile.replace(/\.(js|ts|cpp)$/, '.py');
|
|
@@ -2197,6 +2708,28 @@ int main() {
|
|
|
2197
2708
|
|
|
2198
2709
|
_findEntryFile(kind) {
|
|
2199
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
|
+
}
|
|
2200
2733
|
if (this.lang === 'py') {
|
|
2201
2734
|
if (kind === 'test') {
|
|
2202
2735
|
if (this.explicitTestEntry) {
|
|
@@ -2285,6 +2818,7 @@ int main() {
|
|
|
2285
2818
|
this.container.querySelectorAll('[data-cl-action="run-code"], [data-cl-action="run-entry"], [data-cl-action="run-active-file"], [data-cl-action="run-demo"], [data-cl-action="run-tests"], [data-cl-action="verify-step"]').forEach(btn => {
|
|
2286
2819
|
btn.disabled = this.isRunning;
|
|
2287
2820
|
});
|
|
2821
|
+
this._updatePtyActiveLine();
|
|
2288
2822
|
}
|
|
2289
2823
|
|
|
2290
2824
|
_hasWebContent() {
|
|
@@ -2301,19 +2835,22 @@ int main() {
|
|
|
2301
2835
|
(this.enabledLanguages && this.enabledLanguages.size > 1)
|
|
2302
2836
|
);
|
|
2303
2837
|
if (!hasMulti) return '';
|
|
2838
|
+
const showJs = Boolean(!this.enabledLanguages || this.enabledLanguages.has('js'));
|
|
2304
2839
|
const showTs = Boolean(
|
|
2305
2840
|
!this.enabledLanguages ||
|
|
2306
2841
|
this.enabledLanguages.has('ts') ||
|
|
2307
|
-
!this.enabledLanguages.has('cpp')
|
|
2842
|
+
(!this.enabledLanguages.has('cpp') && !this.enabledLanguages.has('py') && !this.enabledLanguages.has('sql'))
|
|
2308
2843
|
);
|
|
2309
2844
|
const showCpp = Boolean(this.enabledLanguages && this.enabledLanguages.has('cpp'));
|
|
2310
2845
|
const showPy = Boolean(this.enabledLanguages && this.enabledLanguages.has('py'));
|
|
2846
|
+
const showSql = Boolean(this.enabledLanguages && this.enabledLanguages.has('sql'));
|
|
2311
2847
|
return `
|
|
2312
2848
|
<div class="codelab-lang-switch" role="group" aria-label="Language Selector">
|
|
2313
|
-
|
|
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>` : ''}
|
|
2314
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>` : ''}
|
|
2315
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>` : ''}
|
|
2316
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>` : ''}
|
|
2317
2854
|
</div>
|
|
2318
2855
|
`;
|
|
2319
2856
|
}
|
|
@@ -2364,17 +2901,36 @@ int main() {
|
|
|
2364
2901
|
const drawerTabs = this.container.querySelector('.codelab-drawer__tabs');
|
|
2365
2902
|
if (!drawerTabs) return;
|
|
2366
2903
|
|
|
2367
|
-
const
|
|
2368
|
-
const
|
|
2369
|
-
const hasWeb = this._hasWebContent();
|
|
2904
|
+
const isSingleSql = this._isSingleFileSqlMode();
|
|
2905
|
+
const showSqlTab = Boolean(this.lang === 'sql' || this.lastSqlResult);
|
|
2370
2906
|
const problemsCount = this._diagnosticsStore && typeof this._diagnosticsStore.getAll === 'function'
|
|
2371
2907
|
? this._diagnosticsStore.getAll().length
|
|
2372
2908
|
: 0;
|
|
2373
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
|
+
|
|
2374
2930
|
let probTab = drawerTabs.querySelector('[data-cl-drawertab="problems"]');
|
|
2375
2931
|
if (!probTab) {
|
|
2376
2932
|
const termTab = drawerTabs.querySelector('[data-cl-drawertab="terminal"]');
|
|
2377
|
-
if (termTab) {
|
|
2933
|
+
if (termTab && typeof termTab.insertAdjacentHTML === 'function') {
|
|
2378
2934
|
termTab.insertAdjacentHTML('afterend', `
|
|
2379
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">
|
|
2380
2936
|
${CL_ICONS.warning}
|
|
@@ -2388,11 +2944,11 @@ int main() {
|
|
|
2388
2944
|
if (countSpan) countSpan.textContent = String(problemsCount);
|
|
2389
2945
|
}
|
|
2390
2946
|
|
|
2391
|
-
|
|
2392
2947
|
let stdinTab = drawerTabs.querySelector('[data-cl-drawertab="stdin"]');
|
|
2393
2948
|
if (!stdinTab) {
|
|
2949
|
+
const testTab = drawerTabs.querySelector('[data-cl-drawertab="tests"]');
|
|
2394
2950
|
const afterTab = testTab || drawerTabs.querySelector('[data-cl-drawertab="problems"]') || drawerTabs.querySelector('[data-cl-drawertab="terminal"]');
|
|
2395
|
-
if (afterTab) {
|
|
2951
|
+
if (afterTab && typeof afterTab.insertAdjacentHTML === 'function') {
|
|
2396
2952
|
afterTab.insertAdjacentHTML('afterend', `
|
|
2397
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">
|
|
2398
2954
|
${CL_ICONS.keyboard}
|
|
@@ -2402,6 +2958,43 @@ int main() {
|
|
|
2402
2958
|
}
|
|
2403
2959
|
}
|
|
2404
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
|
+
}
|
|
2405
2998
|
}
|
|
2406
2999
|
|
|
2407
3000
|
// ── Render Workbench DOM ───────────────────────────────────────────────
|
|
@@ -2413,11 +3006,20 @@ int main() {
|
|
|
2413
3006
|
const themeAttr = this.themeOption !== 'auto' ? `data-theme="${escapeHtml(this.themeOption)}"` : '';
|
|
2414
3007
|
const brandLabel = (this.title && this.title !== 'custom-lab' && this.title !== this.labId) ? this.title : 'code-lab';
|
|
2415
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
|
+
: '';
|
|
2416
3018
|
const shellVars = [`--cl-explorer-width:${Math.round(this.explorerWidth || 196)}px`];
|
|
2417
3019
|
if (this.previewSplitWidth) shellVars.push(`--cl-preview-split-width:${Math.round(this.previewSplitWidth)}px`);
|
|
2418
3020
|
const explorerStyle = `style="${shellVars.join(';')}"`;
|
|
2419
3021
|
this.container.innerHTML = `
|
|
2420
|
-
<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}>
|
|
2421
3023
|
<!-- Top Bar -->
|
|
2422
3024
|
<div class="codelab-topbar codelab-toolbar">
|
|
2423
3025
|
<div class="codelab-topbar__left">
|
|
@@ -2459,9 +3061,9 @@ int main() {
|
|
|
2459
3061
|
<span>Stop</span>
|
|
2460
3062
|
</button>
|
|
2461
3063
|
${(this.hasGuidedLab && this.mode === 'guided') ? `
|
|
2462
|
-
<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)'}">
|
|
2463
3065
|
${CL_ICONS.play}
|
|
2464
|
-
<span
|
|
3066
|
+
<span>${this.lang === 'sql' ? 'Run Query' : 'Run Demo'}</span>
|
|
2465
3067
|
<span class="codelab-btn__kbd">⇧⌘↵</span>
|
|
2466
3068
|
</button>
|
|
2467
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)">
|
|
@@ -2471,9 +3073,9 @@ int main() {
|
|
|
2471
3073
|
</button>
|
|
2472
3074
|
` : `
|
|
2473
3075
|
<div class="codelab-btn-split">
|
|
2474
|
-
<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 (⌘↵)'}">
|
|
2475
3077
|
${CL_ICONS.play}
|
|
2476
|
-
<span
|
|
3078
|
+
<span>${this.lang === 'sql' ? 'Run SQL' : 'Run Code'}</span>
|
|
2477
3079
|
<span class="codelab-btn__kbd">⌘↵</span>
|
|
2478
3080
|
</button>
|
|
2479
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">
|
|
@@ -2486,6 +3088,11 @@ int main() {
|
|
|
2486
3088
|
<button type="button" class="codelab-split-menu__item" data-cl-action="run-active-file">
|
|
2487
3089
|
<span>▶ Run Active File (${escapeHtml(this.activeFile || 'active')})</span> <kbd style="opacity:0.6">⇧⌘↵</kbd>
|
|
2488
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
|
+
` : ''}
|
|
2489
3096
|
${this._findEntryFile('test') ? `
|
|
2490
3097
|
<button type="button" class="codelab-split-menu__item" data-cl-action="run-tests">
|
|
2491
3098
|
<span>✓ Run Test Suite</span>
|
|
@@ -2506,18 +3113,21 @@ int main() {
|
|
|
2506
3113
|
<span class="codelab-toolbar__sep" aria-hidden="true"></span>
|
|
2507
3114
|
${this.hasGuidedLab ? `
|
|
2508
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'}">
|
|
2509
|
-
<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>
|
|
2510
3117
|
</button>
|
|
2511
3118
|
` : ''}
|
|
2512
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">
|
|
2513
|
-
<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}
|
|
2514
3124
|
</button>
|
|
2515
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">
|
|
2516
|
-
<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>
|
|
2517
3127
|
</button>
|
|
2518
3128
|
${this.onClose ? `
|
|
2519
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">
|
|
2520
|
-
<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>
|
|
2521
3131
|
<span class="codelab-btn__label">Exit Lab</span>
|
|
2522
3132
|
</button>
|
|
2523
3133
|
` : ''}
|
|
@@ -2539,7 +3149,7 @@ int main() {
|
|
|
2539
3149
|
<span>Architecture Brief</span>
|
|
2540
3150
|
</button>
|
|
2541
3151
|
<button type="button" class="codelab-guide__collapse-btn" data-cl-action="toggle-guide" title="Collapse sidebar" aria-label="Collapse sidebar">
|
|
2542
|
-
<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">
|
|
2543
3153
|
<polyline points="15 18 9 12 15 6"></polyline>
|
|
2544
3154
|
</svg>
|
|
2545
3155
|
</button>
|
|
@@ -2578,6 +3188,7 @@ int main() {
|
|
|
2578
3188
|
<div class="codelab-breadcrumbs" id="cl-breadcrumbs" aria-label="Editor Breadcrumbs"></div>
|
|
2579
3189
|
<div class="codelab-editor-wrap">
|
|
2580
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>
|
|
2581
3192
|
<div class="codelab-fallback-wrap" id="cl-fallback-wrap" style="display:none">
|
|
2582
3193
|
<div class="codelab-fallback-gutter" id="cl-fallback-gutter" aria-hidden="true">1</div>
|
|
2583
3194
|
<textarea class="codelab-fallback-editor" id="cl-fallback-editor" spellcheck="false" aria-label="Code Editor"></textarea>
|
|
@@ -2599,7 +3210,11 @@ int main() {
|
|
|
2599
3210
|
<div class="codelab-drawer codelab-bottom" id="cl-drawer">
|
|
2600
3211
|
<div class="codelab-drawer__bar">
|
|
2601
3212
|
<div class="codelab-drawer__tabs" role="tablist" aria-label="Execution Output Panels">
|
|
2602
|
-
<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' : ''}">
|
|
2603
3218
|
${CL_ICONS.terminal}
|
|
2604
3219
|
<span>Terminal & REPL</span>
|
|
2605
3220
|
</button>
|
|
@@ -2608,38 +3223,47 @@ int main() {
|
|
|
2608
3223
|
<span>Problems</span>
|
|
2609
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>
|
|
2610
3225
|
</button>
|
|
2611
|
-
<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' : ''}">
|
|
2612
3227
|
${CL_ICONS.check}
|
|
2613
3228
|
<span>Test Suite</span>
|
|
2614
3229
|
<span class="codelab-drawer__pill" id="cl-test-pill">Ready</span>
|
|
2615
3230
|
</button>
|
|
2616
|
-
<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' : ''}">
|
|
2617
3232
|
${CL_ICONS.keyboard}
|
|
2618
3233
|
<span>Stdin</span>
|
|
2619
3234
|
</button>
|
|
2620
|
-
<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' : ''}">
|
|
2621
3236
|
${CL_ICONS.radio}
|
|
2622
3237
|
<span>Ports</span>
|
|
2623
3238
|
<span class="codelab-drawer__pill" id="cl-ports-pill">${this.portTable && typeof this.portTable.listServers === 'function' ? this.portTable.listServers().length : 0} open</span>
|
|
2624
3239
|
</button>
|
|
2625
|
-
<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' : ''}">
|
|
2626
3241
|
${CL_ICONS.globe}
|
|
2627
3242
|
<span>Web Preview</span>
|
|
2628
3243
|
</button>
|
|
2629
|
-
<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' : ''}">
|
|
2630
3245
|
${CL_ICONS.activity}
|
|
2631
3246
|
<span>Network</span>
|
|
2632
3247
|
<span class="codelab-drawer__pill" id="cl-network-pill">${(this.lastHttpTrace || []).length} reqs</span>
|
|
2633
3248
|
</button>
|
|
2634
|
-
<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' : ''}">
|
|
2635
3250
|
${CL_ICONS.database}
|
|
2636
3251
|
<span>Virtual Disk & HTTP</span>
|
|
2637
3252
|
<span class="codelab-drawer__pill" id="cl-vfs-pill">0 files</span>
|
|
2638
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}
|
|
2639
3261
|
</div>
|
|
2640
3262
|
<div class="codelab-hud-pill" id="cl-telemetry-hud" style="display:none;" title="Last Execution Telemetry"></div>
|
|
2641
3263
|
<div style="display:flex;align-items:center;gap:6px;">
|
|
2642
|
-
<
|
|
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>
|
|
2643
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>
|
|
2644
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>
|
|
2645
3269
|
</div>
|
|
@@ -2654,7 +3278,7 @@ int main() {
|
|
|
2654
3278
|
<div class="codelab-statusbar__left">
|
|
2655
3279
|
<span class="codelab-statusbar__item" id="cl-status-runtime">
|
|
2656
3280
|
<span class="codelab-statusbar__dot" id="cl-status-dot"></span>
|
|
2657
|
-
<span id="cl-status-text"
|
|
3281
|
+
<span id="cl-status-text">${escapeHtml(this.runtimeStatusText || 'Node.js v22 Worker · Idle')}</span>
|
|
2658
3282
|
</span>
|
|
2659
3283
|
<span class="codelab-statusbar__sep">·</span>
|
|
2660
3284
|
<span class="codelab-statusbar__item" id="cl-status-file">${escapeHtml(this.activeFile || 'workspace')}</span>
|
|
@@ -2666,7 +3290,7 @@ int main() {
|
|
|
2666
3290
|
<span class="codelab-statusbar__sep">·</span>
|
|
2667
3291
|
<span class="codelab-statusbar__item">UTF-8</span>
|
|
2668
3292
|
<span class="codelab-statusbar__sep">·</span>
|
|
2669
|
-
<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>
|
|
2670
3294
|
</div>
|
|
2671
3295
|
</footer>
|
|
2672
3296
|
|
|
@@ -2689,6 +3313,14 @@ int main() {
|
|
|
2689
3313
|
|
|
2690
3314
|
_resolveStepTargetFile(rawTarget) {
|
|
2691
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
|
+
}
|
|
2692
3324
|
if (this.lang === 'cpp') {
|
|
2693
3325
|
const asHpp = rawTarget.replace(/\.(js|ts)$/, '.hpp');
|
|
2694
3326
|
if (this.files && this.files[asHpp] !== undefined) return asHpp;
|
|
@@ -3087,6 +3719,10 @@ int main() {
|
|
|
3087
3719
|
}
|
|
3088
3720
|
|
|
3089
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
|
+
}
|
|
3090
3726
|
const explorerEl = this.container.querySelector('#cl-explorer-list');
|
|
3091
3727
|
const tabsEl = this.container.querySelector('#cl-file-tabs');
|
|
3092
3728
|
const explorerLangEl = this.container.querySelector('#cl-explorer-lang');
|
|
@@ -3107,20 +3743,34 @@ int main() {
|
|
|
3107
3743
|
for (const fNode of sortedFolders) {
|
|
3108
3744
|
const isCollapsed = this.collapsedFolders.has(fNode.fullPath);
|
|
3109
3745
|
const indent = depth * 14 + 10;
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
<div class="codelab-
|
|
3118
|
-
<
|
|
3119
|
-
<
|
|
3120
|
-
<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" />
|
|
3121
3756
|
</div>
|
|
3122
|
-
|
|
3123
|
-
|
|
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
|
+
}
|
|
3124
3774
|
|
|
3125
3775
|
if (this.creatingItem && this.creatingItem.parentFolder === fNode.fullPath && !isCollapsed) {
|
|
3126
3776
|
const createIndent = (depth + 1) * 14 + 10;
|
|
@@ -3140,17 +3790,31 @@ int main() {
|
|
|
3140
3790
|
const sortedFiles = Array.from(node.files.entries()).sort((a, b) => a[0].localeCompare(b[0]));
|
|
3141
3791
|
for (const [baseName, fullPath] of sortedFiles) {
|
|
3142
3792
|
const isActive = fullPath === this.activeFile;
|
|
3143
|
-
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';
|
|
3144
|
-
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';
|
|
3145
|
-
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;
|
|
3146
3796
|
const indent = depth * 14 + 10;
|
|
3147
|
-
|
|
3148
|
-
|
|
3149
|
-
|
|
3150
|
-
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
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
|
+
}
|
|
3154
3818
|
}
|
|
3155
3819
|
};
|
|
3156
3820
|
|
|
@@ -3230,14 +3894,19 @@ int main() {
|
|
|
3230
3894
|
// Tree inline creation input listeners
|
|
3231
3895
|
const treeInput = explorerEl.querySelector('#cl-tree-create-input');
|
|
3232
3896
|
if (treeInput) {
|
|
3897
|
+
let createSettled = false;
|
|
3233
3898
|
treeInput.focus();
|
|
3234
3899
|
treeInput.addEventListener('keydown', e => {
|
|
3235
3900
|
if (e.key === 'Escape') {
|
|
3236
3901
|
e.stopPropagation();
|
|
3902
|
+
createSettled = true;
|
|
3237
3903
|
this.creatingItem = null;
|
|
3238
3904
|
this._renderFileLists();
|
|
3239
3905
|
} else if (e.key === 'Enter') {
|
|
3240
3906
|
e.preventDefault();
|
|
3907
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
3908
|
+
if (createSettled) return;
|
|
3909
|
+
createSettled = true;
|
|
3241
3910
|
const val = (treeInput.value || '').trim();
|
|
3242
3911
|
const item = this.creatingItem;
|
|
3243
3912
|
this.creatingItem = null;
|
|
@@ -3254,27 +3923,97 @@ int main() {
|
|
|
3254
3923
|
}
|
|
3255
3924
|
});
|
|
3256
3925
|
treeInput.addEventListener('blur', () => {
|
|
3926
|
+
if (createSettled) return;
|
|
3927
|
+
createSettled = true;
|
|
3257
3928
|
if (this.creatingItem) {
|
|
3929
|
+
const val = (treeInput.value || '').trim();
|
|
3930
|
+
const item = this.creatingItem;
|
|
3258
3931
|
this.creatingItem = null;
|
|
3259
|
-
|
|
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
|
+
}
|
|
3260
3942
|
}
|
|
3261
3943
|
});
|
|
3262
3944
|
}
|
|
3263
3945
|
|
|
3264
|
-
//
|
|
3265
|
-
const
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3273
|
-
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
|
|
3277
|
-
|
|
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
|
+
|
|
3278
4017
|
const newFileControl = this.isCreatingFile
|
|
3279
4018
|
? `<form class="codelab-new-file-form" id="cl-new-file-form">
|
|
3280
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" />
|
|
@@ -3405,7 +4144,97 @@ int main() {
|
|
|
3405
4144
|
}
|
|
3406
4145
|
|
|
3407
4146
|
renameFile(oldPath, newPath) {
|
|
3408
|
-
|
|
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);
|
|
3409
4238
|
}
|
|
3410
4239
|
|
|
3411
4240
|
renameFolder(oldFolder, newFolder) {
|
|
@@ -3522,13 +4351,13 @@ int main() {
|
|
|
3522
4351
|
|
|
3523
4352
|
createFile(rawName, initialContent = null) {
|
|
3524
4353
|
let clean = String(rawName).trim().replace(/^\/+/, '');
|
|
3525
|
-
if (!clean) return;
|
|
3526
|
-
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('.')) {
|
|
3527
4356
|
clean += `.${this.lang}`;
|
|
3528
4357
|
}
|
|
3529
4358
|
if (this.files[clean] !== undefined) {
|
|
3530
4359
|
this.openFile(clean);
|
|
3531
|
-
return;
|
|
4360
|
+
return clean;
|
|
3532
4361
|
}
|
|
3533
4362
|
const parts = clean.split('/');
|
|
3534
4363
|
let cur = '';
|
|
@@ -3541,16 +4370,22 @@ int main() {
|
|
|
3541
4370
|
} else {
|
|
3542
4371
|
this.files[clean] = clean.endsWith('.json')
|
|
3543
4372
|
? '{\n "name": "' + this.labId + '",\n "dependencies": {}\n}\n'
|
|
3544
|
-
:
|
|
3545
|
-
? `#
|
|
3546
|
-
:
|
|
3547
|
-
? `#
|
|
3548
|
-
:
|
|
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`;
|
|
3549
4382
|
}
|
|
3550
4383
|
this._saveState();
|
|
3551
4384
|
this._getOrCreateModel(clean);
|
|
4385
|
+
this._syncFilesToShellVfs();
|
|
3552
4386
|
this._emitEvent('codelab:file-create', { labId: this.labId, filename: clean, content: this.files[clean] });
|
|
3553
4387
|
this.openFile(clean);
|
|
4388
|
+
return clean;
|
|
3554
4389
|
}
|
|
3555
4390
|
|
|
3556
4391
|
duplicateFile(filename) {
|
|
@@ -3727,16 +4562,27 @@ int main() {
|
|
|
3727
4562
|
${problems.map(p => {
|
|
3728
4563
|
const icon = p.severity === 'error' ? '✖' : (p.severity === 'warning' ? '⚠' : 'ℹ');
|
|
3729
4564
|
const cls = p.severity === 'error' ? 'codelab-problem-item--error' : (p.severity === 'warning' ? 'codelab-problem-item--warning' : 'codelab-problem-item--info');
|
|
4565
|
+
const col = p.col || p.column || 1;
|
|
3730
4566
|
return `
|
|
3731
|
-
<div class="codelab-problem-item ${cls}" data-cl-problem-file="${escapeHtml(p.file || '')}" data-cl-problem-line="${p.line || 1}" data-cl-problem-col="${
|
|
4567
|
+
<div class="codelab-problem-item ${cls}" data-cl-problem-file="${escapeHtml(p.file || '')}" data-cl-problem-line="${p.line || 1}" data-cl-problem-col="${col}" role="button" tabindex="0">
|
|
3732
4568
|
<span class="codelab-problem-item__icon">${icon}</span>
|
|
3733
4569
|
<span class="codelab-problem-item__msg">${escapeHtml(p.message || '')}</span>
|
|
3734
|
-
<span class="codelab-problem-item__loc">${escapeHtml(p.file || '')}:${p.line || 1}:${
|
|
4570
|
+
<span class="codelab-problem-item__location codelab-problem-item__loc">${escapeHtml(p.file || '')}:${p.line || 1}:${col}</span>
|
|
3735
4571
|
</div>
|
|
3736
4572
|
`;
|
|
3737
4573
|
}).join('')}
|
|
3738
4574
|
</div>
|
|
3739
4575
|
`;
|
|
4576
|
+
if (typeof bodyEl.querySelectorAll === 'function') {
|
|
4577
|
+
bodyEl.querySelectorAll('.codelab-problem-item').forEach((item) => {
|
|
4578
|
+
item.addEventListener('keydown', (e) => {
|
|
4579
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
4580
|
+
e.preventDefault();
|
|
4581
|
+
item.click();
|
|
4582
|
+
}
|
|
4583
|
+
});
|
|
4584
|
+
});
|
|
4585
|
+
}
|
|
3740
4586
|
return;
|
|
3741
4587
|
}
|
|
3742
4588
|
|
|
@@ -3808,6 +4654,7 @@ int main() {
|
|
|
3808
4654
|
}
|
|
3809
4655
|
|
|
3810
4656
|
if (this.drawerTab === 'terminal') {
|
|
4657
|
+
this._renderTerminalSessionsBar();
|
|
3811
4658
|
const logsHtml = this.terminalLogs
|
|
3812
4659
|
.map(item => {
|
|
3813
4660
|
const html = ansiToHtml ? ansiToHtml(item.text || '') : escapeHtml(item.text || '');
|
|
@@ -3816,7 +4663,13 @@ int main() {
|
|
|
3816
4663
|
.join('');
|
|
3817
4664
|
const cwdShort = (this.cwd || '/workspace').replace(/^\/workspace\/?/, '') || '~';
|
|
3818
4665
|
const promptLabel = this.inRepl ? '> ' : `codelab:${cwdShort}$`;
|
|
3819
|
-
|
|
4666
|
+
const busyAttr = this.isRunning ? ' data-busy="true" style="display:none;"' : '';
|
|
4667
|
+
const promptHtml = this.isRunning ? '' : `${escapeHtml(promptLabel)} `;
|
|
4668
|
+
const beforeHtml = this.isRunning ? '' : escapeHtml(this._ptyInputBeforeCursor || '');
|
|
4669
|
+
const afterHtml = this.isRunning ? '' : escapeHtml(this._ptyInputAfterCursor || '');
|
|
4670
|
+
const cursorClass = this.isRunning ? 'codelab-pty__cursor' : 'codelab-pty__cursor blink';
|
|
4671
|
+
const cursorCharHtml = this.isRunning ? '' : '█';
|
|
4672
|
+
bodyEl.innerHTML = `<div class="codelab-terminal" id="cl-terminal-surface" tabindex="0"><div class="codelab-terminal__log" id="cl-terminal-log">${logsHtml}</div><div class="codelab-pty__active-line" id="cl-pty-active-line"${busyAttr}><span class="codelab-pty__prompt">${promptHtml}</span><span class="codelab-pty__before">${beforeHtml}</span><span class="${cursorClass}">${cursorCharHtml}</span><span class="codelab-pty__after">${afterHtml}</span></div><form class="codelab-repl" id="cl-repl-form" style="position:absolute;width:1px;height:1px;overflow:hidden;opacity:0;"><span class="codelab-repl__prompt">${escapeHtml(promptLabel)}</span><input type="text" class="codelab-repl__input" id="cl-repl-input" placeholder="ls, pwd, cat file.js, node demo.js, node test.js, or JS/TS expression…" autocomplete="off" spellcheck="false" aria-label="REPL command input"></form></div>`;
|
|
3820
4673
|
bodyEl.scrollTop = bodyEl.scrollHeight;
|
|
3821
4674
|
const termSurface = bodyEl.querySelector('#cl-terminal-surface');
|
|
3822
4675
|
const input = bodyEl.querySelector('#cl-repl-input');
|
|
@@ -3828,15 +4681,43 @@ int main() {
|
|
|
3828
4681
|
});
|
|
3829
4682
|
}
|
|
3830
4683
|
if (input) {
|
|
3831
|
-
input.value = (this._ptyInputBeforeCursor || '') + (this._ptyInputAfterCursor || '');
|
|
3832
|
-
|
|
4684
|
+
input.value = this.isRunning ? '' : ((this._ptyInputBeforeCursor || '') + (this._ptyInputAfterCursor || ''));
|
|
4685
|
+
const syncCaretFromInput = () => {
|
|
4686
|
+
if (this.isRunning) {
|
|
4687
|
+
input.value = '';
|
|
4688
|
+
return;
|
|
4689
|
+
}
|
|
3833
4690
|
const val = input.value || '';
|
|
3834
4691
|
const pos = (input.selectionStart !== undefined && input.selectionStart !== null) ? input.selectionStart : val.length;
|
|
3835
4692
|
this._ptyInputBeforeCursor = val.slice(0, pos);
|
|
3836
4693
|
this._ptyInputAfterCursor = val.slice(pos);
|
|
3837
4694
|
this._updatePtyActiveLine();
|
|
4695
|
+
};
|
|
4696
|
+
input.addEventListener('input', syncCaretFromInput);
|
|
4697
|
+
input.addEventListener('click', syncCaretFromInput);
|
|
4698
|
+
input.addEventListener('keyup', e => {
|
|
4699
|
+
if (e.key === 'ArrowLeft' || e.key === 'ArrowRight' || e.key === 'Home' || e.key === 'End') {
|
|
4700
|
+
syncCaretFromInput();
|
|
4701
|
+
}
|
|
3838
4702
|
});
|
|
3839
4703
|
input.addEventListener('keydown', e => {
|
|
4704
|
+
if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
|
|
4705
|
+
e.preventDefault();
|
|
4706
|
+
this._handleInterrupt();
|
|
4707
|
+
return;
|
|
4708
|
+
}
|
|
4709
|
+
if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
|
|
4710
|
+
e.preventDefault();
|
|
4711
|
+
this._clearTerminalLogs();
|
|
4712
|
+
this._renderDrawerBody();
|
|
4713
|
+
const nextInput = this.container.querySelector('#cl-repl-input');
|
|
4714
|
+
if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
|
|
4715
|
+
return;
|
|
4716
|
+
}
|
|
4717
|
+
if (this.isRunning) {
|
|
4718
|
+
e.preventDefault();
|
|
4719
|
+
return;
|
|
4720
|
+
}
|
|
3840
4721
|
if (e.key === 'Tab') {
|
|
3841
4722
|
e.preventDefault();
|
|
3842
4723
|
this._handlePtyTabCompletion(input);
|
|
@@ -3867,9 +4748,6 @@ int main() {
|
|
|
3867
4748
|
this._ptyInputAfterCursor = '';
|
|
3868
4749
|
this._updatePtyActiveLine();
|
|
3869
4750
|
}
|
|
3870
|
-
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'c') {
|
|
3871
|
-
e.preventDefault();
|
|
3872
|
-
this._handleInterrupt();
|
|
3873
4751
|
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'd') {
|
|
3874
4752
|
e.preventDefault();
|
|
3875
4753
|
if (this.inRepl) {
|
|
@@ -3879,12 +4757,6 @@ int main() {
|
|
|
3879
4757
|
const nextInput = this.container.querySelector('#cl-repl-input');
|
|
3880
4758
|
if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
|
|
3881
4759
|
}
|
|
3882
|
-
} else if (e.ctrlKey && !e.metaKey && e.key.toLowerCase() === 'l') {
|
|
3883
|
-
e.preventDefault();
|
|
3884
|
-
this.terminalLogs = [];
|
|
3885
|
-
this._renderDrawerBody();
|
|
3886
|
-
const nextInput = this.container.querySelector('#cl-repl-input');
|
|
3887
|
-
if (nextInput && typeof nextInput.focus === 'function') nextInput.focus();
|
|
3888
4760
|
} else if (e.ctrlKey && e.key.toLowerCase() === 'u') {
|
|
3889
4761
|
e.preventDefault();
|
|
3890
4762
|
this._ptyInputBeforeCursor = '';
|
|
@@ -3915,6 +4787,7 @@ int main() {
|
|
|
3915
4787
|
if (replForm) {
|
|
3916
4788
|
replForm.addEventListener('submit', e => {
|
|
3917
4789
|
e.preventDefault();
|
|
4790
|
+
if (this.isRunning) return;
|
|
3918
4791
|
const rawCmd = (input && input.value !== undefined ? input.value : '') ||
|
|
3919
4792
|
((this._ptyInputBeforeCursor || '') + (this._ptyInputAfterCursor || ''));
|
|
3920
4793
|
const cmd = rawCmd.trim();
|
|
@@ -3989,6 +4862,113 @@ int main() {
|
|
|
3989
4862
|
</div>
|
|
3990
4863
|
</div>
|
|
3991
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
|
+
}
|
|
3992
4972
|
}
|
|
3993
4973
|
}
|
|
3994
4974
|
|
|
@@ -3996,7 +4976,7 @@ int main() {
|
|
|
3996
4976
|
if (chunk === null || chunk === undefined || chunk === '') return;
|
|
3997
4977
|
const rawText = String(chunk);
|
|
3998
4978
|
|
|
3999
|
-
if (this.ptyEngine && typeof this.ptyEngine.writeStreamChunk === 'function') {
|
|
4979
|
+
if (this.ptyEngine && this.ptyEngine.container && typeof this.ptyEngine.writeStreamChunk === 'function') {
|
|
4000
4980
|
try {
|
|
4001
4981
|
this.ptyEngine.writeStreamChunk(rawText, type);
|
|
4002
4982
|
} catch (err) {
|
|
@@ -4037,6 +5017,14 @@ int main() {
|
|
|
4037
5017
|
// A newline completes the current line: commit it to the log + DOM, then begin a fresh line.
|
|
4038
5018
|
const commitActiveLine = () => {
|
|
4039
5019
|
this.terminalLogs.push({ type: this._activeStreamType || type, text: this._activeStreamLine });
|
|
5020
|
+
if (this.terminalLogs.length > 2000) {
|
|
5021
|
+
this.terminalLogs.splice(0, this.terminalLogs.length - 2000);
|
|
5022
|
+
if (canPatchDom && termLogEl) {
|
|
5023
|
+
while (termLogEl.childElementCount > 2000 && termLogEl.firstElementChild) {
|
|
5024
|
+
termLogEl.removeChild(termLogEl.firstElementChild);
|
|
5025
|
+
}
|
|
5026
|
+
}
|
|
5027
|
+
}
|
|
4040
5028
|
patchLineInDom(this._activeStreamLine);
|
|
4041
5029
|
this._activeStreamLine = '';
|
|
4042
5030
|
this._activeStreamEl = null;
|
|
@@ -4204,15 +5192,39 @@ int main() {
|
|
|
4204
5192
|
|
|
4205
5193
|
_updatePtyActiveLine() {
|
|
4206
5194
|
if (!this.container) return;
|
|
5195
|
+
const activeLine = this.container.querySelector('#cl-pty-active-line');
|
|
4207
5196
|
const beforeEl = this.container.querySelector('.codelab-pty__before');
|
|
4208
5197
|
const afterEl = this.container.querySelector('.codelab-pty__after');
|
|
4209
5198
|
const promptEl = this.container.querySelector('.codelab-pty__prompt');
|
|
5199
|
+
const cursorEl = this.container.querySelector('.codelab-pty__cursor');
|
|
4210
5200
|
const cwdShort = (this.cwd || '/workspace').replace(/^\/workspace\/?/, '') || '~';
|
|
4211
5201
|
const promptLabel = this.inRepl ? '> ' : `codelab:${cwdShort}$`;
|
|
4212
5202
|
|
|
4213
|
-
if (
|
|
4214
|
-
|
|
4215
|
-
|
|
5203
|
+
if (this.isRunning) {
|
|
5204
|
+
if (activeLine) {
|
|
5205
|
+
activeLine.setAttribute('data-busy', 'true');
|
|
5206
|
+
if (activeLine.style) activeLine.style.display = 'none';
|
|
5207
|
+
}
|
|
5208
|
+
if (promptEl) promptEl.textContent = '';
|
|
5209
|
+
if (beforeEl) beforeEl.textContent = '';
|
|
5210
|
+
if (cursorEl) {
|
|
5211
|
+
cursorEl.textContent = '';
|
|
5212
|
+
if (cursorEl.classList) cursorEl.classList.remove('blink');
|
|
5213
|
+
}
|
|
5214
|
+
if (afterEl) afterEl.textContent = '';
|
|
5215
|
+
} else {
|
|
5216
|
+
if (activeLine) {
|
|
5217
|
+
activeLine.removeAttribute('data-busy');
|
|
5218
|
+
if (activeLine.style) activeLine.style.display = '';
|
|
5219
|
+
}
|
|
5220
|
+
if (promptEl) promptEl.textContent = promptLabel + ' ';
|
|
5221
|
+
if (beforeEl) beforeEl.textContent = this._ptyInputBeforeCursor || '';
|
|
5222
|
+
if (cursorEl) {
|
|
5223
|
+
if (!cursorEl.textContent) cursorEl.textContent = '\u2588';
|
|
5224
|
+
if (cursorEl.classList) cursorEl.classList.add('blink');
|
|
5225
|
+
}
|
|
5226
|
+
if (afterEl) afterEl.textContent = this._ptyInputAfterCursor || '';
|
|
5227
|
+
}
|
|
4216
5228
|
}
|
|
4217
5229
|
|
|
4218
5230
|
_handlePtyTabCompletion(input) {
|
|
@@ -4392,7 +5404,7 @@ int main() {
|
|
|
4392
5404
|
} else if (httpState.activeResponseTab === 'preview') {
|
|
4393
5405
|
const isHtml = lastRes.headers && Object.entries(lastRes.headers).some(([k, v]) => k.toLowerCase() === 'content-type' && String(v).includes('text/html'));
|
|
4394
5406
|
if (isHtml || lastRes.body.includes('<html') || lastRes.body.includes('<!DOCTYPE') || lastRes.body.includes('<div') || lastRes.body.includes('<body')) {
|
|
4395
|
-
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>`;
|
|
4396
5408
|
} else {
|
|
4397
5409
|
responseBodyView = `<pre class="codelab-response-raw"><code>${escapeHtml(lastRes.formattedBody || lastRes.body)}</code></pre>`;
|
|
4398
5410
|
}
|
|
@@ -4753,23 +5765,23 @@ int main() {
|
|
|
4753
5765
|
<option value="5xx" ${filter.status === '5xx' ? 'selected' : ''}>5xx / Network Fault</option>
|
|
4754
5766
|
</select>
|
|
4755
5767
|
<button type="button" class="codelab-btn" data-cl-action="clear-net-traces">Clear</button>
|
|
4756
|
-
<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>
|
|
4757
5769
|
</div>
|
|
4758
5770
|
<div class="codelab-net-main">
|
|
4759
5771
|
<div class="codelab-net-table-container">
|
|
4760
5772
|
<table class="codelab-net-table">
|
|
4761
5773
|
<thead>
|
|
4762
5774
|
<tr>
|
|
4763
|
-
<th style="width:85px;">Status</th>
|
|
4764
|
-
<th style="width:65px;">Method</th>
|
|
4765
|
-
<th>Path</th>
|
|
4766
|
-
<th style="width:95px;">Route</th>
|
|
4767
|
-
<th style="width:75px;">Time</th>
|
|
4768
|
-
<th style="width:70px;">Size</th>
|
|
4769
|
-
<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>
|
|
4770
5782
|
</tr>
|
|
4771
5783
|
</thead>
|
|
4772
|
-
<tbody>
|
|
5784
|
+
<tbody id="cl-net-tbody">
|
|
4773
5785
|
${rowsHtml}
|
|
4774
5786
|
</tbody>
|
|
4775
5787
|
</table>
|
|
@@ -4782,13 +5794,82 @@ int main() {
|
|
|
4782
5794
|
this._bindNetworkEvents(bodyEl);
|
|
4783
5795
|
}
|
|
4784
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
|
+
|
|
4785
5864
|
_bindNetworkEvents(bodyEl) {
|
|
4786
5865
|
if (!bodyEl) return;
|
|
4787
5866
|
const searchInput = bodyEl.querySelector('#cl-net-search');
|
|
4788
5867
|
if (searchInput) {
|
|
4789
5868
|
searchInput.addEventListener('input', e => {
|
|
4790
5869
|
this.networkFilter.search = e.target.value;
|
|
4791
|
-
this.
|
|
5870
|
+
if (!this._updateNetworkRowsInPlace(bodyEl)) {
|
|
5871
|
+
this._renderDrawerBody();
|
|
5872
|
+
}
|
|
4792
5873
|
});
|
|
4793
5874
|
}
|
|
4794
5875
|
const methodSelect = bodyEl.querySelector('#cl-net-method');
|
|
@@ -4938,6 +6019,14 @@ int main() {
|
|
|
4938
6019
|
const active = b.dataset.clDrawertab === this.drawerTab;
|
|
4939
6020
|
b.classList.toggle('active', active);
|
|
4940
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
|
+
}
|
|
4941
6030
|
});
|
|
4942
6031
|
const drawer = this.container.querySelector('#cl-drawer');
|
|
4943
6032
|
if (drawer) drawer.classList.remove('is-minimized');
|
|
@@ -5193,9 +6282,10 @@ int main() {
|
|
|
5193
6282
|
_injectPreviewCsp(html, port) {
|
|
5194
6283
|
if (typeof html !== 'string' || !html) return html;
|
|
5195
6284
|
|
|
6285
|
+
const csp = String(this._previewPolicy() || '').replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
5196
6286
|
const tags = [];
|
|
5197
6287
|
if (!/<meta[^>]+http-equiv=["']?content-security-policy/i.test(html)) {
|
|
5198
|
-
tags.push(`<meta http-equiv="Content-Security-Policy" content="${
|
|
6288
|
+
tags.push(`<meta http-equiv="Content-Security-Policy" content="${csp}">`);
|
|
5199
6289
|
}
|
|
5200
6290
|
if (!/<base\b/i.test(html)) {
|
|
5201
6291
|
tags.push(`<base href="/__preview/${Number(port) || 3000}/">`);
|
|
@@ -6065,7 +7155,7 @@ int main() {
|
|
|
6065
7155
|
this.files[this.activeFile] = fallbackEl.value;
|
|
6066
7156
|
this._updateFallbackGutter();
|
|
6067
7157
|
updateFallbackCursor();
|
|
6068
|
-
this.
|
|
7158
|
+
this._scheduleSaveState();
|
|
6069
7159
|
this._notifyCodeChange(this.activeFile, fallbackEl.value);
|
|
6070
7160
|
}
|
|
6071
7161
|
});
|
|
@@ -6103,6 +7193,56 @@ int main() {
|
|
|
6103
7193
|
loadMonaco(this.monacoUrl).then(m => {
|
|
6104
7194
|
this.monaco = m;
|
|
6105
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
|
+
|
|
6106
7246
|
const isDark = this._resolvedTheme() !== 'light';
|
|
6107
7247
|
|
|
6108
7248
|
// Create models for all code files
|
|
@@ -6112,12 +7252,14 @@ int main() {
|
|
|
6112
7252
|
this.editor = m.editor.create(monacoHost, {
|
|
6113
7253
|
model: currentModel,
|
|
6114
7254
|
theme: isDark ? 'codelab-dark' : 'codelab-light',
|
|
6115
|
-
fontFamily: '"Geist Mono", ui-monospace, SFMono-Regular, Menlo, Monaco, monospace',
|
|
6116
|
-
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,
|
|
6117
7257
|
lineHeight: 20,
|
|
6118
|
-
tabSize: 2,
|
|
7258
|
+
tabSize: this.configuration ? this.configuration.get('editor.tabSize', 2) : 2,
|
|
6119
7259
|
insertSpaces: true,
|
|
6120
|
-
|
|
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 },
|
|
6121
7263
|
scrollBeyondLastLine: false,
|
|
6122
7264
|
automaticLayout: true,
|
|
6123
7265
|
padding: { top: 12, bottom: 12 },
|
|
@@ -6127,6 +7269,8 @@ int main() {
|
|
|
6127
7269
|
bracketPairColorization: { enabled: true }
|
|
6128
7270
|
});
|
|
6129
7271
|
|
|
7272
|
+
this._applyConfigurationChanges(null);
|
|
7273
|
+
|
|
6130
7274
|
// Dynamic ResizeObserver to guarantee 100% width on layout shifts
|
|
6131
7275
|
if (typeof ResizeObserver !== 'undefined' && monacoHost) {
|
|
6132
7276
|
this._editorResizeObserver = new ResizeObserver(() => {
|
|
@@ -6142,6 +7286,8 @@ int main() {
|
|
|
6142
7286
|
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyCode.Enter, () => {
|
|
6143
7287
|
if (this.mode === 'guided') {
|
|
6144
7288
|
this.verifyCurrentStep();
|
|
7289
|
+
} else if (this.lang === 'sql' || (this.activeFile && /\.sql$/i.test(this.activeFile))) {
|
|
7290
|
+
this.runSql('run');
|
|
6145
7291
|
} else {
|
|
6146
7292
|
this.runTests();
|
|
6147
7293
|
}
|
|
@@ -6149,6 +7295,11 @@ int main() {
|
|
|
6149
7295
|
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyMod.Shift | m.KeyCode.Enter, () => {
|
|
6150
7296
|
this.runDemo();
|
|
6151
7297
|
});
|
|
7298
|
+
if (m.KeyCode.Comma) {
|
|
7299
|
+
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyCode.Comma, () => {
|
|
7300
|
+
this.openSettings();
|
|
7301
|
+
});
|
|
7302
|
+
}
|
|
6152
7303
|
if (m.KeyCode.KeyP) {
|
|
6153
7304
|
this.editor.addCommand(m.KeyMod.CtrlCmd | m.KeyMod.Shift | m.KeyCode.KeyP, () => {
|
|
6154
7305
|
this.openCommandPalette('commands');
|
|
@@ -6174,11 +7325,17 @@ int main() {
|
|
|
6174
7325
|
col: e.position.column
|
|
6175
7326
|
};
|
|
6176
7327
|
this._updateStatusBar();
|
|
6177
|
-
this.
|
|
7328
|
+
this._scheduleBreadcrumbs();
|
|
6178
7329
|
}
|
|
6179
7330
|
});
|
|
6180
7331
|
}
|
|
6181
7332
|
|
|
7333
|
+
if (m.editor && typeof m.editor.onDidChangeMarkers === 'function') {
|
|
7334
|
+
this._markerDisposable = m.editor.onDidChangeMarkers(() => {
|
|
7335
|
+
this._syncMonacoMarkersToDiagnostics();
|
|
7336
|
+
});
|
|
7337
|
+
}
|
|
7338
|
+
|
|
6182
7339
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
6183
7340
|
this._syncActiveFileToView();
|
|
6184
7341
|
|
|
@@ -6203,18 +7360,30 @@ int main() {
|
|
|
6203
7360
|
}
|
|
6204
7361
|
|
|
6205
7362
|
_notifyCodeChange(filename, code) {
|
|
6206
|
-
|
|
7363
|
+
const cleanRel = filename ? String(filename).replace(/^\/+/, '') : '';
|
|
7364
|
+
if (this.shell && this.shell.vfs && cleanRel && typeof this.shell.vfs.writeFileSync === 'function') {
|
|
6207
7365
|
try {
|
|
6208
|
-
const
|
|
6209
|
-
const parts = clean.split('/');
|
|
7366
|
+
const parts = cleanRel.split('/');
|
|
6210
7367
|
if (parts.length > 1 && typeof this.shell.vfs.mkdirSync === 'function') {
|
|
6211
7368
|
this.shell.vfs.mkdirSync('/workspace/' + parts.slice(0, -1).join('/'), { recursive: true });
|
|
6212
7369
|
}
|
|
6213
|
-
this.shell.vfs.writeFileSync('/workspace/' +
|
|
7370
|
+
this.shell.vfs.writeFileSync('/workspace/' + cleanRel, String(code ?? ''));
|
|
6214
7371
|
} catch (err) {
|
|
6215
7372
|
this.logger.debug(`Could not sync "${filename}" to shell VFS on edit.`, err);
|
|
6216
7373
|
}
|
|
6217
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
|
+
}
|
|
6218
7387
|
if ((this.drawerTab === 'preview' || (this.previewState && this.previewState.dockMode === 'split')) && this.previewState && this.previewState.port) {
|
|
6219
7388
|
if (this._previewReloadTimer) {
|
|
6220
7389
|
clearTimeout(this._previewReloadTimer);
|
|
@@ -6234,6 +7403,61 @@ int main() {
|
|
|
6234
7403
|
this._renderBreadcrumbs();
|
|
6235
7404
|
}
|
|
6236
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
|
+
|
|
6237
7461
|
_getOrCreateModel(filename) {
|
|
6238
7462
|
if (!filename || !this.monaco || !this.monaco.editor) return null;
|
|
6239
7463
|
const uriParser = (this.monaco.Uri && typeof this.monaco.Uri.parse === 'function')
|
|
@@ -6241,31 +7465,33 @@ int main() {
|
|
|
6241
7465
|
: (this.monaco.editor.Uri && typeof this.monaco.editor.Uri.parse === 'function')
|
|
6242
7466
|
? this.monaco.editor.Uri
|
|
6243
7467
|
: null;
|
|
6244
|
-
const rawUri = `file:///${this.
|
|
7468
|
+
const rawUri = `file:///${encodeURIComponent(this.instanceId)}/${filename}`;
|
|
6245
7469
|
const uri = uriParser ? uriParser.parse(rawUri) : { toString: () => rawUri };
|
|
6246
7470
|
let model = typeof this.monaco.editor.getModel === 'function' ? this.monaco.editor.getModel(uri) : null;
|
|
6247
7471
|
const lang = /\.(cpp|cc|cxx|hpp|h)$/i.test(filename)
|
|
6248
7472
|
? 'cpp'
|
|
6249
7473
|
: /\.py$/i.test(filename)
|
|
6250
7474
|
? 'python'
|
|
6251
|
-
:
|
|
6252
|
-
? '
|
|
6253
|
-
: filename.endsWith('.
|
|
6254
|
-
? '
|
|
6255
|
-
: filename.endsWith('.
|
|
6256
|
-
? '
|
|
6257
|
-
: filename.endsWith('.
|
|
6258
|
-
? '
|
|
6259
|
-
: filename.endsWith('.
|
|
6260
|
-
? '
|
|
6261
|
-
: '
|
|
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';
|
|
6262
7488
|
if (!model) {
|
|
6263
7489
|
model = this.monaco.editor.createModel(this.files[filename] || '', lang, uri);
|
|
6264
7490
|
if (model && typeof model.onDidChangeContent === 'function') {
|
|
6265
7491
|
model.onDidChangeContent(() => {
|
|
6266
7492
|
const val = model.getValue();
|
|
6267
7493
|
this.files[filename] = val;
|
|
6268
|
-
this.
|
|
7494
|
+
this._scheduleSaveState();
|
|
6269
7495
|
this._notifyCodeChange(filename, val);
|
|
6270
7496
|
if (this.lang === 'py' && typeof this._pyLintHandler === 'function') {
|
|
6271
7497
|
this._pyLintHandler(filename, val);
|
|
@@ -6284,13 +7510,26 @@ int main() {
|
|
|
6284
7510
|
|
|
6285
7511
|
_syncAllModels() {
|
|
6286
7512
|
if (!this.monaco) return;
|
|
6287
|
-
|
|
6288
|
-
|
|
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
|
+
}
|
|
6289
7527
|
}
|
|
6290
7528
|
}
|
|
6291
7529
|
|
|
6292
7530
|
_syncActiveFileToView() {
|
|
6293
7531
|
const monacoHost = this.container.querySelector('#cl-monaco-host');
|
|
7532
|
+
const sqlHost = this.container.querySelector('#cl-sql-editor-host');
|
|
6294
7533
|
const fallbackWrap = this.container.querySelector('#cl-fallback-wrap');
|
|
6295
7534
|
const fallbackEl = this.container.querySelector('#cl-fallback-editor');
|
|
6296
7535
|
const mdPreview = this.container.querySelector('#cl-md-preview');
|
|
@@ -6298,6 +7537,7 @@ int main() {
|
|
|
6298
7537
|
|
|
6299
7538
|
if (!this.activeFile || !this.openTabs || this.openTabs.length === 0) {
|
|
6300
7539
|
if (monacoHost) monacoHost.style.display = 'none';
|
|
7540
|
+
if (sqlHost) sqlHost.style.display = 'none';
|
|
6301
7541
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
6302
7542
|
if (mdPreview) mdPreview.style.display = 'none';
|
|
6303
7543
|
if (this.editor) {
|
|
@@ -6313,20 +7553,103 @@ int main() {
|
|
|
6313
7553
|
return;
|
|
6314
7554
|
}
|
|
6315
7555
|
|
|
6316
|
-
|
|
6317
|
-
|
|
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
|
+
|
|
7588
|
+
if (emptyEl) {
|
|
7589
|
+
emptyEl.style.display = 'none';
|
|
6318
7590
|
}
|
|
6319
7591
|
|
|
6320
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
|
+
|
|
6321
7603
|
if (isMd) {
|
|
6322
7604
|
if (monacoHost) monacoHost.style.display = 'none';
|
|
7605
|
+
if (sqlHost) sqlHost.style.display = 'none';
|
|
6323
7606
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
6324
7607
|
if (mdPreview) {
|
|
6325
7608
|
mdPreview.style.display = 'block';
|
|
6326
7609
|
mdPreview.innerHTML = renderSimpleMarkdown(this.files[this.activeFile] || '');
|
|
6327
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
|
+
}
|
|
6328
7650
|
} else {
|
|
6329
7651
|
if (mdPreview) mdPreview.style.display = 'none';
|
|
7652
|
+
if (sqlHost) sqlHost.style.display = 'none';
|
|
6330
7653
|
if (this.editor && this.monaco) {
|
|
6331
7654
|
if (monacoHost) monacoHost.style.display = 'block';
|
|
6332
7655
|
if (fallbackWrap) fallbackWrap.style.display = 'none';
|
|
@@ -6432,10 +7755,31 @@ int main() {
|
|
|
6432
7755
|
? e.target.closest('#cl-preview-url-input')
|
|
6433
7756
|
: null;
|
|
6434
7757
|
if (previewInput && e.key === 'Enter') {
|
|
7758
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
6435
7759
|
e.preventDefault();
|
|
6436
7760
|
this._previewGo(previewInput.value);
|
|
6437
7761
|
return;
|
|
6438
7762
|
}
|
|
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
|
+
}
|
|
6439
7783
|
if (e.key === 'Escape' && this.folderSwitcherOpen) {
|
|
6440
7784
|
this.folderSwitcherOpen = false;
|
|
6441
7785
|
this._renderBreadcrumbs();
|
|
@@ -6446,6 +7790,15 @@ int main() {
|
|
|
6446
7790
|
this.openCommandPalette('commands');
|
|
6447
7791
|
return;
|
|
6448
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
|
+
}
|
|
6449
7802
|
if ((e.metaKey || e.ctrlKey) && keyLower === 'k') {
|
|
6450
7803
|
e.preventDefault();
|
|
6451
7804
|
this.openCommandPalette('commands');
|
|
@@ -6470,6 +7823,9 @@ int main() {
|
|
|
6470
7823
|
}
|
|
6471
7824
|
}
|
|
6472
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
|
+
}
|
|
6473
7829
|
e.preventDefault();
|
|
6474
7830
|
if (e.shiftKey) {
|
|
6475
7831
|
if (this.mode === 'guided') {
|
|
@@ -6761,21 +8117,29 @@ int main() {
|
|
|
6761
8117
|
if (splitTrigger) {
|
|
6762
8118
|
e.stopPropagation();
|
|
6763
8119
|
const menu = this.container.querySelector('#cl-split-run-menu');
|
|
6764
|
-
if (menu)
|
|
8120
|
+
if (menu) {
|
|
8121
|
+
const isOpen = !(menu.classList.contains('active') || menu.classList.contains('open'));
|
|
8122
|
+
menu.classList.toggle('active', isOpen);
|
|
8123
|
+
menu.classList.toggle('open', isOpen);
|
|
8124
|
+
}
|
|
6765
8125
|
return;
|
|
6766
8126
|
}
|
|
6767
8127
|
|
|
6768
8128
|
const splitMenu = this.container.querySelector('#cl-split-run-menu');
|
|
6769
|
-
if (splitMenu && splitMenu.classList.contains('active') && !e.target.closest('.codelab-btn-split')) {
|
|
8129
|
+
if (splitMenu && (splitMenu.classList.contains('active') || splitMenu.classList.contains('open')) && !e.target.closest('.codelab-btn-split')) {
|
|
6770
8130
|
splitMenu.classList.remove('active');
|
|
8131
|
+
splitMenu.classList.remove('open');
|
|
6771
8132
|
}
|
|
6772
8133
|
|
|
6773
|
-
const problemItem = e.target.closest('[data-cl-problem-file]');
|
|
8134
|
+
const problemItem = e.target.closest('[data-cl-problem-file], [data-problem-file]');
|
|
6774
8135
|
if (problemItem) {
|
|
6775
8136
|
e.stopPropagation();
|
|
6776
|
-
const pFile = problemItem.dataset.clProblemFile;
|
|
6777
|
-
const pLine = Number(problemItem.dataset.clProblemLine || 1);
|
|
6778
|
-
const pCol = Number(problemItem.dataset.clProblemCol || 1);
|
|
8137
|
+
const pFile = problemItem.dataset.clProblemFile || problemItem.dataset.problemFile;
|
|
8138
|
+
const pLine = Number(problemItem.dataset.clProblemLine || problemItem.dataset.problemLine || 1);
|
|
8139
|
+
const pCol = Number(problemItem.dataset.clProblemCol || problemItem.dataset.problemCol || 1);
|
|
8140
|
+
if (problemItem.closest('#cl-modal-slot')) {
|
|
8141
|
+
this.closeModal();
|
|
8142
|
+
}
|
|
6779
8143
|
if (pFile) {
|
|
6780
8144
|
this.openFile(pFile);
|
|
6781
8145
|
if (this.editor && typeof this.editor.revealLineInCenter === 'function') {
|
|
@@ -6787,6 +8151,24 @@ int main() {
|
|
|
6787
8151
|
return;
|
|
6788
8152
|
}
|
|
6789
8153
|
|
|
8154
|
+
const searchMatch = e.target.closest('[data-cl-search-file]');
|
|
8155
|
+
if (searchMatch) {
|
|
8156
|
+
e.stopPropagation();
|
|
8157
|
+
const sFile = searchMatch.dataset.clSearchFile;
|
|
8158
|
+
const sLine = Number(searchMatch.dataset.clSearchLine || 1);
|
|
8159
|
+
const sCol = Number(searchMatch.dataset.clSearchCol || 1);
|
|
8160
|
+
this.closeModal();
|
|
8161
|
+
if (sFile) {
|
|
8162
|
+
this.openFile(sFile);
|
|
8163
|
+
if (this.editor && typeof this.editor.revealLineInCenter === 'function') {
|
|
8164
|
+
this.editor.revealLineInCenter(sLine);
|
|
8165
|
+
this.editor.setPosition({ lineNumber: sLine, column: sCol });
|
|
8166
|
+
this.editor.focus();
|
|
8167
|
+
}
|
|
8168
|
+
}
|
|
8169
|
+
return;
|
|
8170
|
+
}
|
|
8171
|
+
|
|
6790
8172
|
const drawerTabBtn = e.target.closest('[data-cl-drawertab]');
|
|
6791
8173
|
if (drawerTabBtn) {
|
|
6792
8174
|
this.switchDrawerTab(drawerTabBtn.dataset.clDrawertab);
|
|
@@ -6795,13 +8177,17 @@ int main() {
|
|
|
6795
8177
|
|
|
6796
8178
|
const actionBtn = e.target.closest('[data-cl-action], [data-action]');
|
|
6797
8179
|
if (actionBtn) {
|
|
6798
|
-
if (splitMenu && splitMenu.classList.contains('active')) {
|
|
8180
|
+
if (splitMenu && (splitMenu.classList.contains('active') || splitMenu.classList.contains('open'))) {
|
|
6799
8181
|
splitMenu.classList.remove('active');
|
|
8182
|
+
splitMenu.classList.remove('open');
|
|
6800
8183
|
}
|
|
6801
8184
|
const action = actionBtn.dataset.clAction || actionBtn.dataset.action;
|
|
6802
8185
|
if (action === 'run-code') this.runCode();
|
|
6803
8186
|
else if (action === 'run-entry') this.runEntry();
|
|
6804
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();
|
|
6805
8191
|
else if (action === 'open-stdin') this.switchDrawerTab('stdin');
|
|
6806
8192
|
else if (action === 'share-snapshot') this.shareSnapshot();
|
|
6807
8193
|
else if (action === 'run-demo') this.runDemo();
|
|
@@ -6899,9 +8285,49 @@ int main() {
|
|
|
6899
8285
|
if (drawer) drawer.classList.toggle('is-minimized');
|
|
6900
8286
|
if (this.editor) setTimeout(() => this.editor.layout(), 50);
|
|
6901
8287
|
} else if (action === 'clear-terminal') {
|
|
6902
|
-
this.
|
|
8288
|
+
this._clearTerminalLogs();
|
|
6903
8289
|
this.lastTestResults = [];
|
|
6904
8290
|
this._renderDrawerBody();
|
|
8291
|
+
} else if (action === 'new-terminal-session') {
|
|
8292
|
+
this.createTerminalSession();
|
|
8293
|
+
if (this.drawerTab !== 'terminal') this.switchDrawerTab('terminal');
|
|
8294
|
+
} else if (action === 'switch-terminal-session') {
|
|
8295
|
+
const sid = actionBtn.dataset.sessionId;
|
|
8296
|
+
if (sid) this.switchTerminalSession(sid);
|
|
8297
|
+
} else if (action === 'close-terminal-session') {
|
|
8298
|
+
e.stopPropagation();
|
|
8299
|
+
const sid = actionBtn.dataset.sessionId;
|
|
8300
|
+
if (sid) this.closeTerminalSession(sid);
|
|
8301
|
+
} else if (action === 'scm-stage-file') {
|
|
8302
|
+
e.stopPropagation();
|
|
8303
|
+
const p = actionBtn.dataset.scmPath;
|
|
8304
|
+
if (p) {
|
|
8305
|
+
this.stageGitFile(p);
|
|
8306
|
+
this.showScmModal();
|
|
8307
|
+
}
|
|
8308
|
+
} else if (action === 'scm-unstage-file') {
|
|
8309
|
+
e.stopPropagation();
|
|
8310
|
+
const p = actionBtn.dataset.scmPath;
|
|
8311
|
+
if (p) {
|
|
8312
|
+
this.unstageGitFile(p);
|
|
8313
|
+
this.showScmModal();
|
|
8314
|
+
}
|
|
8315
|
+
} else if (action === 'scm-stage-all') {
|
|
8316
|
+
this.stageAllGitFiles();
|
|
8317
|
+
this.showScmModal();
|
|
8318
|
+
} else if (action === 'scm-commit') {
|
|
8319
|
+
const msgInput = this.container.querySelector('#cl-scm-commit-input');
|
|
8320
|
+
const msg = msgInput ? msgInput.value.trim() : '';
|
|
8321
|
+
if (msg) {
|
|
8322
|
+
this.commitGitChanges(msg);
|
|
8323
|
+
this.showScmModal();
|
|
8324
|
+
}
|
|
8325
|
+
} else if (action === 'scm-open-file') {
|
|
8326
|
+
const p = actionBtn.dataset.scmPath;
|
|
8327
|
+
this.closeModal();
|
|
8328
|
+
if (p && Object.prototype.hasOwnProperty.call(this.files, p)) {
|
|
8329
|
+
this.openFile(p);
|
|
8330
|
+
}
|
|
6905
8331
|
} else if (action === 'toggle-hint') {
|
|
6906
8332
|
const box = this.container.querySelector('#cl-hint-box');
|
|
6907
8333
|
if (box) box.classList.toggle('open');
|
|
@@ -7018,6 +8444,12 @@ int main() {
|
|
|
7018
8444
|
this.logger.debug('Quick load test failed.', err);
|
|
7019
8445
|
});
|
|
7020
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
|
+
}
|
|
7021
8453
|
}
|
|
7022
8454
|
return;
|
|
7023
8455
|
}
|
|
@@ -7091,13 +8523,21 @@ int main() {
|
|
|
7091
8523
|
|
|
7092
8524
|
// ── VS Code Command Palette & Quick Open ────────────────────────────────
|
|
7093
8525
|
_getPaletteCommands() {
|
|
7094
|
-
|
|
8526
|
+
const builtin = [
|
|
7095
8527
|
{ id: 'run-code', label: 'CodeLab: Run Code (Entry or Active File)', shortcut: '⌘↵', action: () => this.runCode() },
|
|
7096
8528
|
{ id: 'run-active', label: 'CodeLab: Run Active File', shortcut: '⇧⌘↵', action: () => this.runActiveFile() },
|
|
7097
8529
|
{ id: 'run-demo', label: 'CodeLab: Run Demo Script', shortcut: '⇧⌘↵', action: () => this.runDemo() },
|
|
7098
8530
|
{ id: 'run-tests', label: 'CodeLab: Run Unit Tests', shortcut: '⌘↵', action: () => this.runTests() },
|
|
7099
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') },
|
|
7100
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') },
|
|
7101
8541
|
{ id: 'share-snapshot', label: 'CodeLab: Share Snapshot Link (#codelab=...)', action: () => this.shareSnapshot() },
|
|
7102
8542
|
{ id: 'open-stdin', label: 'View: Open Stdin / Custom Input Panel', action: () => this.switchDrawerTab('stdin') },
|
|
7103
8543
|
{ id: 'view-problems-tab', label: 'View: Focus Problems Drawer Tab', action: () => this.switchDrawerTab('problems') },
|
|
@@ -7111,10 +8551,11 @@ int main() {
|
|
|
7111
8551
|
{ id: 'export-workspace', label: 'Workspace: Export Workspace as JSON', action: () => this.exportWorkspace({ download: true }) },
|
|
7112
8552
|
{ id: 'export-workspace-zip', label: 'Workspace: Export Project as ZIP Archive', action: () => this.exportProjectZip({ download: true }) },
|
|
7113
8553
|
{ id: 'reset-workspace', label: 'Workspace: Reset Workspace to Clean State', action: () => this.resetLab() },
|
|
7114
|
-
{ id: 'switch-lang', label: 'Language: Switch JavaScript / TypeScript / C++ / Python', action: () => {
|
|
8554
|
+
{ id: 'switch-lang', label: 'Language: Switch JavaScript / TypeScript / C++ / Python / SQL', action: () => {
|
|
7115
8555
|
const order = ['js', 'ts'];
|
|
7116
8556
|
if (this.enabledLanguages && this.enabledLanguages.has('cpp')) order.push('cpp');
|
|
7117
8557
|
if (this.enabledLanguages && this.enabledLanguages.has('py')) order.push('py');
|
|
8558
|
+
if (this.enabledLanguages && this.enabledLanguages.has('sql')) order.push('sql');
|
|
7118
8559
|
const next = order[(order.indexOf(this.lang) + 1) % order.length] || 'js';
|
|
7119
8560
|
this.setLanguage(next);
|
|
7120
8561
|
} },
|
|
@@ -7132,6 +8573,55 @@ int main() {
|
|
|
7132
8573
|
{ id: 'open-packages', label: 'Packages: Manage NPM Dependencies & Runtime', action: () => this.showPackagesModal() },
|
|
7133
8574
|
{ id: 'git-clone', label: 'Git: Clone Public GitHub Repository...', action: () => this.showCloneRepoModal() }
|
|
7134
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;
|
|
7135
8625
|
}
|
|
7136
8626
|
|
|
7137
8627
|
openCommandPalette(mode = 'commands') {
|
|
@@ -7185,6 +8675,7 @@ int main() {
|
|
|
7185
8675
|
this._renderPaletteList(input.value);
|
|
7186
8676
|
}
|
|
7187
8677
|
} else if (e.key === 'Enter') {
|
|
8678
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
7188
8679
|
e.preventDefault();
|
|
7189
8680
|
this._executePaletteSelection(this.paletteSelectedIndex);
|
|
7190
8681
|
} else if (e.key === 'Escape') {
|
|
@@ -7216,8 +8707,12 @@ int main() {
|
|
|
7216
8707
|
}));
|
|
7217
8708
|
} else {
|
|
7218
8709
|
const files = this._orderedFileNames();
|
|
7219
|
-
|
|
7220
|
-
|
|
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
|
|
7221
8716
|
.map(f => ({
|
|
7222
8717
|
type: 'file',
|
|
7223
8718
|
id: f,
|
|
@@ -7660,10 +9155,17 @@ int main() {
|
|
|
7660
9155
|
if (newMode !== 'guided' && newMode !== 'sandbox') return;
|
|
7661
9156
|
if (this.mode === newMode) return;
|
|
7662
9157
|
this.mode = newMode;
|
|
9158
|
+
if (this.contextKeys) {
|
|
9159
|
+
this.contextKeys.setContext('workbenchMode', this.mode);
|
|
9160
|
+
}
|
|
7663
9161
|
this.files = this._computeInitialFiles();
|
|
7664
9162
|
this.openTabs = this._orderedFileNames();
|
|
7665
9163
|
this.activeFile = this._pickDefaultFile();
|
|
7666
9164
|
this._saveState();
|
|
9165
|
+
if (this.kernel && this.kernel.fs) {
|
|
9166
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
9167
|
+
}
|
|
9168
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
7667
9169
|
|
|
7668
9170
|
this.container.querySelectorAll('[data-cl-mode]').forEach(btn => {
|
|
7669
9171
|
const isActive = btn.dataset.clMode === this.mode;
|
|
@@ -7677,6 +9179,10 @@ int main() {
|
|
|
7677
9179
|
primaryBtn.setAttribute('data-cl-action', 'verify-step');
|
|
7678
9180
|
primaryBtn.setAttribute('title', 'Verify Current Step (⌘+Enter)');
|
|
7679
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>`;
|
|
7680
9186
|
} else {
|
|
7681
9187
|
primaryBtn.setAttribute('data-cl-action', 'run-tests');
|
|
7682
9188
|
primaryBtn.setAttribute('title', 'Run Test Suite (⌘+Enter)');
|
|
@@ -7720,22 +9226,36 @@ int main() {
|
|
|
7720
9226
|
}
|
|
7721
9227
|
|
|
7722
9228
|
setLanguage(newLang) {
|
|
7723
|
-
if (newLang !== 'js' && newLang !== 'ts' && newLang !== 'cpp' && newLang !== 'py') return;
|
|
9229
|
+
if (newLang !== 'js' && newLang !== 'ts' && newLang !== 'cpp' && newLang !== 'py' && newLang !== 'sql') return;
|
|
7724
9230
|
if (this.lang === newLang) return;
|
|
7725
9231
|
this.lang = newLang;
|
|
7726
9232
|
if (this.enabledLanguages instanceof Set) {
|
|
7727
9233
|
this.enabledLanguages.add(newLang);
|
|
7728
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
|
+
}
|
|
7729
9241
|
this.files = this._computeInitialFiles();
|
|
7730
9242
|
this.openTabs = this._orderedFileNames();
|
|
7731
9243
|
this.activeFile = this._pickDefaultFile();
|
|
9244
|
+
if (this.lang === 'sql') {
|
|
9245
|
+
this.drawerTab = 'sql-results';
|
|
9246
|
+
}
|
|
7732
9247
|
this._saveState();
|
|
9248
|
+
if (this.kernel && this.kernel.fs) {
|
|
9249
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
9250
|
+
}
|
|
9251
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
7733
9252
|
|
|
7734
9253
|
if (typeof this._refreshToolbarAndTabs === 'function') {
|
|
7735
9254
|
this._refreshToolbarAndTabs();
|
|
7736
9255
|
} else {
|
|
7737
9256
|
this._refreshLanguageSwitcher();
|
|
7738
9257
|
}
|
|
9258
|
+
this._refreshDrawerTabs();
|
|
7739
9259
|
this.container.querySelectorAll('[data-cl-lang]').forEach(btn => {
|
|
7740
9260
|
const isActive = btn.dataset.clLang === this.lang;
|
|
7741
9261
|
btn.classList.toggle('active', isActive);
|
|
@@ -7745,6 +9265,7 @@ int main() {
|
|
|
7745
9265
|
this._syncAllModels();
|
|
7746
9266
|
this._syncActiveFileToView();
|
|
7747
9267
|
this._renderGuidePane();
|
|
9268
|
+
this._renderDrawerBody();
|
|
7748
9269
|
this._updateStatusBar();
|
|
7749
9270
|
}
|
|
7750
9271
|
|
|
@@ -7775,7 +9296,7 @@ int main() {
|
|
|
7775
9296
|
if (mode === 'guided' || mode === 'sandbox') {
|
|
7776
9297
|
this.setMode(mode);
|
|
7777
9298
|
}
|
|
7778
|
-
if (lang === 'js' || lang === 'ts' || lang === 'cpp' || lang === 'py') {
|
|
9299
|
+
if (lang === 'js' || lang === 'ts' || lang === 'cpp' || lang === 'py' || lang === 'sql') {
|
|
7779
9300
|
this.setLanguage(lang);
|
|
7780
9301
|
}
|
|
7781
9302
|
if (typeof stepIndex === 'number' && !Number.isNaN(stepIndex)) {
|
|
@@ -7829,6 +9350,32 @@ int main() {
|
|
|
7829
9350
|
this._handleInterrupt();
|
|
7830
9351
|
}
|
|
7831
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
|
+
|
|
7832
9379
|
resetLab() {
|
|
7833
9380
|
this.completedSteps = new Set();
|
|
7834
9381
|
this.folders = new Set();
|
|
@@ -7850,6 +9397,10 @@ int main() {
|
|
|
7850
9397
|
delete this.savedState.hasSnapshot[key];
|
|
7851
9398
|
}
|
|
7852
9399
|
this._saveState();
|
|
9400
|
+
if (this.kernel && this.kernel.fs) {
|
|
9401
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
9402
|
+
}
|
|
9403
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
7853
9404
|
this._syncAllModels();
|
|
7854
9405
|
this._syncActiveFileToView();
|
|
7855
9406
|
this._renderStepPills();
|
|
@@ -7933,6 +9484,7 @@ int main() {
|
|
|
7933
9484
|
input.focus();
|
|
7934
9485
|
input.addEventListener('keydown', e => {
|
|
7935
9486
|
if (e.key === 'Enter' && input.value.trim()) {
|
|
9487
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
7936
9488
|
e.preventDefault();
|
|
7937
9489
|
this.addNpmPackage(input.value.trim());
|
|
7938
9490
|
}
|
|
@@ -8005,6 +9557,10 @@ int main() {
|
|
|
8005
9557
|
if (slot) slot.innerHTML = '';
|
|
8006
9558
|
}
|
|
8007
9559
|
|
|
9560
|
+
closeCommandPalette() {
|
|
9561
|
+
this.closeModal();
|
|
9562
|
+
}
|
|
9563
|
+
|
|
8008
9564
|
applyReferenceSolution() {
|
|
8009
9565
|
const refFiles = this._getBaseFilesForModeAndLang('sandbox', this.lang);
|
|
8010
9566
|
const targetFile = refFiles[this.activeFile] ? this.activeFile : this._pickDefaultFile();
|
|
@@ -8084,6 +9640,9 @@ int main() {
|
|
|
8084
9640
|
this.lastRunDurationMs = res && typeof res.durationMs === 'number' ? res.durationMs : elapsed;
|
|
8085
9641
|
this.lastDurationMs = this.lastRunDurationMs;
|
|
8086
9642
|
this.lastPeakMemoryBytes = res && typeof res.peakMemoryBytes === 'number' ? res.peakMemoryBytes : null;
|
|
9643
|
+
if (res && res.vfsChanges) {
|
|
9644
|
+
this._applyWorkerVfsDiffToWorkspace(res.vfsChanges);
|
|
9645
|
+
}
|
|
8087
9646
|
this._updateTelemetryHud();
|
|
8088
9647
|
this._setRuntimeStatus('idle', 'Ready · Node v22 VFS');
|
|
8089
9648
|
return res;
|
|
@@ -8097,7 +9656,127 @@ int main() {
|
|
|
8097
9656
|
}
|
|
8098
9657
|
}
|
|
8099
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
|
+
|
|
8100
9776
|
async runCode() {
|
|
9777
|
+
if (this.lang === 'sql' || (this.activeFile && /\.sql$/i.test(this.activeFile))) {
|
|
9778
|
+
return this.runSql('run');
|
|
9779
|
+
}
|
|
8101
9780
|
const entry = this._findEntryFile('demo') || this.activeFile || this._pickDefaultFile();
|
|
8102
9781
|
if (!entry) {
|
|
8103
9782
|
this.terminalLogs.push({ type: 'stderr', text: 'No entry file or active file to run.' });
|
|
@@ -8105,9 +9784,95 @@ int main() {
|
|
|
8105
9784
|
this._renderDrawerBody();
|
|
8106
9785
|
return;
|
|
8107
9786
|
}
|
|
9787
|
+
if (/\.sql$/i.test(entry)) {
|
|
9788
|
+
return this.runSql('run');
|
|
9789
|
+
}
|
|
8108
9790
|
return this._executeEntryFile(entry);
|
|
8109
9791
|
}
|
|
8110
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
|
+
|
|
8111
9876
|
async runEntry() {
|
|
8112
9877
|
return this.runCode();
|
|
8113
9878
|
}
|
|
@@ -8120,6 +9885,9 @@ int main() {
|
|
|
8120
9885
|
this._renderDrawerBody();
|
|
8121
9886
|
return;
|
|
8122
9887
|
}
|
|
9888
|
+
if (/\.sql$/i.test(file) || this.lang === 'sql') {
|
|
9889
|
+
return this.runSql('run');
|
|
9890
|
+
}
|
|
8123
9891
|
return this._executeEntryFile(file);
|
|
8124
9892
|
}
|
|
8125
9893
|
|
|
@@ -8211,6 +9979,9 @@ int main() {
|
|
|
8211
9979
|
|
|
8212
9980
|
async runDemo() {
|
|
8213
9981
|
if (this.isRunning) return;
|
|
9982
|
+
if (this.lang === 'sql') {
|
|
9983
|
+
return this.runSql('run');
|
|
9984
|
+
}
|
|
8214
9985
|
const entry = this._findEntryFile('demo') || this._findEntryFile('entry') || this.activeFile;
|
|
8215
9986
|
if (!entry) {
|
|
8216
9987
|
if ((this.files['index.html'] || this.files['public/index.html']) && typeof this.previewApp === 'function') {
|
|
@@ -8221,6 +9992,9 @@ int main() {
|
|
|
8221
9992
|
this._renderDrawerBody();
|
|
8222
9993
|
return;
|
|
8223
9994
|
}
|
|
9995
|
+
if (/\.sql$/i.test(entry)) {
|
|
9996
|
+
return this.runSql('run');
|
|
9997
|
+
}
|
|
8224
9998
|
return this._executeEntryFile(entry);
|
|
8225
9999
|
}
|
|
8226
10000
|
|
|
@@ -8230,6 +10004,25 @@ int main() {
|
|
|
8230
10004
|
const code = this.files[file] || '';
|
|
8231
10005
|
if (!code) return;
|
|
8232
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
|
+
|
|
8233
10026
|
if (file.endsWith('.js') || file.endsWith('.ts') || file.endsWith('.jsx') || file.endsWith('.tsx')) {
|
|
8234
10027
|
if (this.editor && typeof this.editor.getAction === 'function') {
|
|
8235
10028
|
const action = this.editor.getAction('editor.action.formatDocument');
|
|
@@ -8357,7 +10150,7 @@ int main() {
|
|
|
8357
10150
|
const snapshot = await decompressor(token);
|
|
8358
10151
|
if (snapshot && snapshot.files && typeof snapshot.files === 'object') {
|
|
8359
10152
|
this.files = { ...snapshot.files };
|
|
8360
|
-
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')) {
|
|
8361
10154
|
this.lang = snapshot.lang;
|
|
8362
10155
|
}
|
|
8363
10156
|
if (snapshot.stdin) {
|
|
@@ -8381,6 +10174,12 @@ int main() {
|
|
|
8381
10174
|
async runTests(filterTestNames = null) {
|
|
8382
10175
|
if (this.isRunning) return;
|
|
8383
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
|
+
}
|
|
8384
10183
|
if (!entry) {
|
|
8385
10184
|
this.terminalLogs.push({ type: 'stderr', text: 'No test file (test.js, test.ts, test.cpp, test.py) found in this workspace.' });
|
|
8386
10185
|
this.drawerTab = 'terminal';
|
|
@@ -8514,8 +10313,12 @@ int main() {
|
|
|
8514
10313
|
return lastRes;
|
|
8515
10314
|
}
|
|
8516
10315
|
|
|
8517
|
-
async verifyCurrentStep() {
|
|
8518
|
-
|
|
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
|
+
}
|
|
8519
10322
|
const step = this.steps[this.activeStepIndex];
|
|
8520
10323
|
if (step && this.completedSteps.has(step.id) && this.activeStepIndex < this.steps.length - 1) {
|
|
8521
10324
|
// Advance to next step and jump to its target symbol/TODO
|
|
@@ -8523,6 +10326,453 @@ int main() {
|
|
|
8523
10326
|
}
|
|
8524
10327
|
}
|
|
8525
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
|
+
|
|
8526
10776
|
_resolveShellPath(rawPath) {
|
|
8527
10777
|
if (!rawPath || rawPath === '.') return this.cwd || '/workspace';
|
|
8528
10778
|
if (rawPath === '~') return '/workspace';
|
|
@@ -8545,6 +10795,7 @@ int main() {
|
|
|
8545
10795
|
}
|
|
8546
10796
|
|
|
8547
10797
|
async _handleReplCommand(cmd) {
|
|
10798
|
+
if (this.isRunning) return;
|
|
8548
10799
|
const trimmed = (cmd || '').trim();
|
|
8549
10800
|
if (!trimmed) return;
|
|
8550
10801
|
if (this.replHistory[this.replHistory.length - 1] !== trimmed) {
|
|
@@ -8553,7 +10804,19 @@ int main() {
|
|
|
8553
10804
|
this.replHistoryIdx = -1;
|
|
8554
10805
|
const cwdShort = (this.cwd || '/workspace').replace(/^\/workspace\/?/, '') || '~';
|
|
8555
10806
|
const promptPrefix = this.inRepl ? '> ' : `codelab:${cwdShort}$ `;
|
|
8556
|
-
|
|
10807
|
+
const echoLine = `${promptPrefix}${trimmed}`;
|
|
10808
|
+
this.terminalLogs.push({ type: 'system', text: echoLine });
|
|
10809
|
+
if (this.terminalLogs.length > 2000) {
|
|
10810
|
+
this.terminalLogs.splice(0, this.terminalLogs.length - 2000);
|
|
10811
|
+
}
|
|
10812
|
+
const termLogEl = this.container ? this.container.querySelector('#cl-terminal-log') : null;
|
|
10813
|
+
const ptyOwnsDom = Boolean(this.ptyEngine && this.ptyEngine.container);
|
|
10814
|
+
if (termLogEl && typeof document !== 'undefined' && !ptyOwnsDom) {
|
|
10815
|
+
const echoEl = document.createElement('div');
|
|
10816
|
+
echoEl.className = 'codelab-log-line system';
|
|
10817
|
+
echoEl.innerHTML = ansiToHtml ? ansiToHtml(echoLine) : escapeHtml(echoLine);
|
|
10818
|
+
termLogEl.appendChild(echoEl);
|
|
10819
|
+
}
|
|
8557
10820
|
|
|
8558
10821
|
if (this.inRepl) {
|
|
8559
10822
|
if (trimmed === '.exit' || trimmed === 'exit') {
|
|
@@ -8563,7 +10826,7 @@ int main() {
|
|
|
8563
10826
|
return;
|
|
8564
10827
|
}
|
|
8565
10828
|
if (trimmed === '.clear' || trimmed === 'clear') {
|
|
8566
|
-
this.
|
|
10829
|
+
this._clearTerminalLogs();
|
|
8567
10830
|
this._renderDrawerBody();
|
|
8568
10831
|
return;
|
|
8569
10832
|
}
|
|
@@ -8616,7 +10879,7 @@ int main() {
|
|
|
8616
10879
|
}
|
|
8617
10880
|
|
|
8618
10881
|
if (trimmed === 'clear' || trimmed === 'cls') {
|
|
8619
|
-
this.
|
|
10882
|
+
this._clearTerminalLogs();
|
|
8620
10883
|
this._renderDrawerBody();
|
|
8621
10884
|
return;
|
|
8622
10885
|
}
|
|
@@ -8676,7 +10939,7 @@ int main() {
|
|
|
8676
10939
|
this._syncVfsSnapshot(null, true);
|
|
8677
10940
|
|
|
8678
10941
|
if (shellRes && shellRes.clear) {
|
|
8679
|
-
this.
|
|
10942
|
+
this._clearTerminalLogs();
|
|
8680
10943
|
this._renderDrawerBody();
|
|
8681
10944
|
return;
|
|
8682
10945
|
}
|
|
@@ -8842,7 +11105,7 @@ int main() {
|
|
|
8842
11105
|
if (data.mode === 'guided' || data.mode === 'sandbox') {
|
|
8843
11106
|
this.mode = data.mode;
|
|
8844
11107
|
}
|
|
8845
|
-
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') {
|
|
8846
11109
|
this.lang = data.language;
|
|
8847
11110
|
}
|
|
8848
11111
|
if (data.files && typeof data.files === 'object') {
|
|
@@ -8889,18 +11152,66 @@ int main() {
|
|
|
8889
11152
|
return bytes;
|
|
8890
11153
|
}
|
|
8891
11154
|
|
|
8892
|
-
|
|
11155
|
+
exportZip(options = {}) {
|
|
11156
|
+
return this.exportProjectZip(options);
|
|
11157
|
+
}
|
|
11158
|
+
|
|
11159
|
+
importProjectZip(zipBytes, options = {}) {
|
|
8893
11160
|
const zipMod = root.CodeLabZip;
|
|
8894
11161
|
if (!zipMod || typeof zipMod.extractZip !== 'function') {
|
|
8895
11162
|
throw new Error('CodeLabZip engine is not loaded');
|
|
8896
11163
|
}
|
|
8897
11164
|
const extracted = zipMod.extractZip(zipBytes);
|
|
8898
11165
|
if (!extracted || typeof extracted !== 'object') return false;
|
|
8899
|
-
this.setFiles(extracted);
|
|
11166
|
+
this.setFiles(extracted, options);
|
|
8900
11167
|
this._syncFilesToShellVfs();
|
|
8901
11168
|
return true;
|
|
8902
11169
|
}
|
|
8903
11170
|
|
|
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;
|
|
11181
|
+
}
|
|
11182
|
+
|
|
11183
|
+
async saveProjectToStorage(id) {
|
|
11184
|
+
if (!root.CodeLabStorage || typeof root.CodeLabStorage.createWorkspaceStorage !== 'function') {
|
|
11185
|
+
return false;
|
|
11186
|
+
}
|
|
11187
|
+
if (!this._idbStorage) {
|
|
11188
|
+
this._idbStorage = root.CodeLabStorage.createWorkspaceStorage();
|
|
11189
|
+
}
|
|
11190
|
+
const projectId = id || this.labId || 'workspace';
|
|
11191
|
+
return this._idbStorage.saveProject({
|
|
11192
|
+
id: projectId,
|
|
11193
|
+
name: this.title || projectId,
|
|
11194
|
+
files: { ...(this.files || {}) },
|
|
11195
|
+
updatedAt: Date.now()
|
|
11196
|
+
});
|
|
11197
|
+
}
|
|
11198
|
+
|
|
11199
|
+
async loadProjectFromStorage(id) {
|
|
11200
|
+
if (!root.CodeLabStorage || typeof root.CodeLabStorage.createWorkspaceStorage !== 'function') {
|
|
11201
|
+
return null;
|
|
11202
|
+
}
|
|
11203
|
+
if (!this._idbStorage) {
|
|
11204
|
+
this._idbStorage = root.CodeLabStorage.createWorkspaceStorage();
|
|
11205
|
+
}
|
|
11206
|
+
const projectId = id || this.labId || 'workspace';
|
|
11207
|
+
const loaded = await this._idbStorage.loadProject(projectId);
|
|
11208
|
+
if (loaded && loaded.files && typeof loaded.files === 'object') {
|
|
11209
|
+
this.setFiles(loaded.files);
|
|
11210
|
+
this._syncFilesToShellVfs();
|
|
11211
|
+
}
|
|
11212
|
+
return loaded;
|
|
11213
|
+
}
|
|
11214
|
+
|
|
8904
11215
|
searchWorkspace(options) {
|
|
8905
11216
|
const searchMod = root.CodeLabSearch;
|
|
8906
11217
|
if (!searchMod || typeof searchMod.searchInFiles !== 'function') {
|
|
@@ -8914,21 +11225,113 @@ int main() {
|
|
|
8914
11225
|
if (!searchMod || typeof searchMod.replaceInFiles !== 'function') {
|
|
8915
11226
|
throw new Error('CodeLabSearch engine is not loaded');
|
|
8916
11227
|
}
|
|
8917
|
-
const res = searchMod.replaceInFiles(this.files || {}, options);
|
|
8918
|
-
|
|
8919
|
-
|
|
11228
|
+
const res = searchMod.replaceInFiles(this.files || {}, options, options && options.replacement);
|
|
11229
|
+
const nextFiles = res && (res.updatedFiles || res.files);
|
|
11230
|
+
const modifiedCount = res && (typeof res.filesModified === 'number' ? res.filesModified : (Array.isArray(res.filesAffected) ? res.filesAffected.length : 0));
|
|
11231
|
+
if (nextFiles && modifiedCount > 0) {
|
|
11232
|
+
this.setFiles(nextFiles);
|
|
8920
11233
|
this._syncFilesToShellVfs();
|
|
8921
11234
|
}
|
|
8922
11235
|
return res;
|
|
8923
11236
|
}
|
|
8924
11237
|
|
|
11238
|
+
_getGitState() {
|
|
11239
|
+
const scmMod = root.CodeLabScm;
|
|
11240
|
+
if (this.shell && this.shell.gitState) {
|
|
11241
|
+
return this.shell.gitState;
|
|
11242
|
+
}
|
|
11243
|
+
if (!this._gitState && scmMod && typeof scmMod.createGitState === 'function') {
|
|
11244
|
+
this._gitState = scmMod.createGitState(this.files || {});
|
|
11245
|
+
}
|
|
11246
|
+
return this._gitState || null;
|
|
11247
|
+
}
|
|
11248
|
+
|
|
8925
11249
|
getGitStatus() {
|
|
8926
11250
|
const scmMod = root.CodeLabScm;
|
|
8927
11251
|
if (!scmMod || typeof scmMod.computeGitStatus !== 'function') {
|
|
8928
11252
|
return [];
|
|
8929
11253
|
}
|
|
8930
|
-
const gs =
|
|
8931
|
-
|
|
11254
|
+
const gs = this._getGitState() || scmMod.createGitState(this.files || {});
|
|
11255
|
+
const res = scmMod.computeGitStatus(this.files || {}, '/workspace', gs);
|
|
11256
|
+
return res && Array.isArray(res.entries) ? res.entries : (Array.isArray(res) ? res : []);
|
|
11257
|
+
}
|
|
11258
|
+
|
|
11259
|
+
stageGitFile(relPath) {
|
|
11260
|
+
if (!relPath) return false;
|
|
11261
|
+
const gs = this._getGitState();
|
|
11262
|
+
if (!gs) return false;
|
|
11263
|
+
const scmMod = root.CodeLabScm;
|
|
11264
|
+
if (gs.staged instanceof Set) {
|
|
11265
|
+
gs.staged.add(relPath);
|
|
11266
|
+
} else if (scmMod && typeof scmMod.stageFile === 'function') {
|
|
11267
|
+
const currentContent = Object.prototype.hasOwnProperty.call(this.files, relPath) ? this.files[relPath] : null;
|
|
11268
|
+
scmMod.stageFile(gs, relPath, currentContent);
|
|
11269
|
+
}
|
|
11270
|
+
return true;
|
|
11271
|
+
}
|
|
11272
|
+
|
|
11273
|
+
unstageGitFile(relPath) {
|
|
11274
|
+
if (!relPath) return false;
|
|
11275
|
+
const gs = this._getGitState();
|
|
11276
|
+
if (!gs || !gs.staged || typeof gs.staged.delete !== 'function') return false;
|
|
11277
|
+
gs.staged.delete(relPath);
|
|
11278
|
+
return true;
|
|
11279
|
+
}
|
|
11280
|
+
|
|
11281
|
+
stageAllGitFiles() {
|
|
11282
|
+
const entries = this.getGitStatus();
|
|
11283
|
+
for (const entry of entries) {
|
|
11284
|
+
if (!entry.staged) {
|
|
11285
|
+
this.stageGitFile(entry.path);
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
11288
|
+
return true;
|
|
11289
|
+
}
|
|
11290
|
+
|
|
11291
|
+
commitGitChanges(message) {
|
|
11292
|
+
const msg = typeof message === 'string' ? message.trim() : '';
|
|
11293
|
+
if (!msg) return null;
|
|
11294
|
+
const gs = this._getGitState();
|
|
11295
|
+
if (!gs) return null;
|
|
11296
|
+
const scmMod = root.CodeLabScm;
|
|
11297
|
+
if (gs.staged instanceof Set) {
|
|
11298
|
+
if (gs.staged.size === 0) return null;
|
|
11299
|
+
if (!gs.headSnapshot) gs.headSnapshot = {};
|
|
11300
|
+
for (const relPath of gs.staged) {
|
|
11301
|
+
if (Object.prototype.hasOwnProperty.call(this.files, relPath)) {
|
|
11302
|
+
gs.headSnapshot[relPath] = this.files[relPath];
|
|
11303
|
+
} else {
|
|
11304
|
+
delete gs.headSnapshot[relPath];
|
|
11305
|
+
}
|
|
11306
|
+
}
|
|
11307
|
+
gs.headFiles = Object.assign({}, gs.headSnapshot);
|
|
11308
|
+
const hash = scmMod && typeof scmMod.computeShortCommitHash === 'function'
|
|
11309
|
+
? scmMod.computeShortCommitHash(`${gs.branch || 'main'}:${msg}:${Date.now()}`)
|
|
11310
|
+
: Math.random().toString(16).slice(2, 9);
|
|
11311
|
+
if (!Array.isArray(gs.commits)) gs.commits = [];
|
|
11312
|
+
gs.commits.unshift({
|
|
11313
|
+
hash,
|
|
11314
|
+
author: 'CodeLab Developer <dev@codelab.internal>',
|
|
11315
|
+
date: new Date().toUTCString(),
|
|
11316
|
+
timestamp: Date.now(),
|
|
11317
|
+
message: msg
|
|
11318
|
+
});
|
|
11319
|
+
gs.headCommit = hash;
|
|
11320
|
+
gs.staged.clear();
|
|
11321
|
+
this._syncFilesToShellVfs();
|
|
11322
|
+
return hash;
|
|
11323
|
+
}
|
|
11324
|
+
if (scmMod && typeof scmMod.commitChanges === 'function') {
|
|
11325
|
+
try {
|
|
11326
|
+
const hash = scmMod.commitChanges(gs, msg);
|
|
11327
|
+
if (gs.headFiles) gs.headSnapshot = Object.assign({}, gs.headFiles);
|
|
11328
|
+
this._syncFilesToShellVfs();
|
|
11329
|
+
return hash;
|
|
11330
|
+
} catch (_err) {
|
|
11331
|
+
return null;
|
|
11332
|
+
}
|
|
11333
|
+
}
|
|
11334
|
+
return null;
|
|
8932
11335
|
}
|
|
8933
11336
|
|
|
8934
11337
|
getDiagnostics() {
|
|
@@ -8946,12 +11349,20 @@ int main() {
|
|
|
8946
11349
|
const slot = this.container ? this.container.querySelector('#cl-modal-slot') : null;
|
|
8947
11350
|
if (!slot) return;
|
|
8948
11351
|
const q = String(initialQuery || '');
|
|
8949
|
-
const
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
<
|
|
8953
|
-
|
|
8954
|
-
|
|
11352
|
+
const renderRows = (queryText) => {
|
|
11353
|
+
const res = queryText ? this.searchWorkspace({ query: queryText }) : { matches: [], totalMatches: 0, filesMatched: 0 };
|
|
11354
|
+
if (!queryText) {
|
|
11355
|
+
return '<div style="color:var(--cl-fg-muted);font-size:12px;">Enter a query to search across workspace files.</div>';
|
|
11356
|
+
}
|
|
11357
|
+
if (!res.matches || res.matches.length === 0) {
|
|
11358
|
+
return '<div style="color:var(--cl-fg-muted);font-size:12px;">No matches found in workspace.</div>';
|
|
11359
|
+
}
|
|
11360
|
+
return res.matches.map((m) => `
|
|
11361
|
+
<div class="codelab-search-match" data-cl-file="${escapeHtml(m.file)}" data-cl-search-file="${escapeHtml(m.file)}" data-cl-search-line="${m.line || 1}" data-cl-search-col="${m.column || 1}" role="button" tabindex="0" style="padding:6px 8px;border-bottom:1px solid var(--cl-border);cursor:pointer;font-family:var(--cl-font-mono);font-size:12px;">
|
|
11362
|
+
<strong>${escapeHtml(m.file)}:${m.line}:${m.column}</strong> — <span>${escapeHtml(m.lineText)}</span>
|
|
11363
|
+
</div>
|
|
11364
|
+
`).join('');
|
|
11365
|
+
};
|
|
8955
11366
|
slot.innerHTML = `
|
|
8956
11367
|
<div class="codelab-modal-backdrop">
|
|
8957
11368
|
<div class="codelab-modal" role="dialog" aria-modal="true" aria-label="Search Across Workspace">
|
|
@@ -8960,36 +11371,83 @@ int main() {
|
|
|
8960
11371
|
<button type="button" class="codelab-btn" data-cl-action="close-modal">Close (Esc)</button>
|
|
8961
11372
|
</div>
|
|
8962
11373
|
<div class="codelab-modal__body">
|
|
8963
|
-
<div style="display:flex;gap:8px;margin-bottom:8px;">
|
|
8964
|
-
<input id="cl-search-query-input" type="text" value="${escapeHtml(q)}" placeholder="Search text or regex..."
|
|
8965
|
-
<input id="cl-search-replace-input" type="text" placeholder="Replace with..."
|
|
11374
|
+
<div style="display:flex;gap:8px;margin-bottom:8px;align-items:center;">
|
|
11375
|
+
<input id="cl-search-query-input" class="codelab-modal-input" type="text" value="${escapeHtml(q)}" placeholder="Search text or regex..." />
|
|
11376
|
+
<input id="cl-search-replace-input" class="codelab-modal-input" type="text" placeholder="Replace with..." />
|
|
11377
|
+
<button type="button" id="cl-search-replace-all-btn" class="codelab-btn codelab-btn--primary" style="padding:5px 10px;font-size:12px;white-space:nowrap;">Replace All</button>
|
|
8966
11378
|
</div>
|
|
8967
|
-
<div id="cl-search-results-list"
|
|
11379
|
+
<div id="cl-search-results-list" style="max-height:320px;overflow-y:auto;">${renderRows(q)}</div>
|
|
8968
11380
|
</div>
|
|
8969
11381
|
</div>
|
|
8970
11382
|
</div>
|
|
8971
11383
|
`;
|
|
11384
|
+
const queryInput = slot.querySelector('#cl-search-query-input');
|
|
11385
|
+
const replaceInput = slot.querySelector('#cl-search-replace-input');
|
|
11386
|
+
const replaceBtn = slot.querySelector('#cl-search-replace-all-btn');
|
|
11387
|
+
const listEl = slot.querySelector('#cl-search-results-list');
|
|
11388
|
+
if (queryInput && listEl) {
|
|
11389
|
+
queryInput.addEventListener('input', () => {
|
|
11390
|
+
listEl.innerHTML = renderRows(queryInput.value || '');
|
|
11391
|
+
});
|
|
11392
|
+
if (typeof queryInput.focus === 'function') queryInput.focus();
|
|
11393
|
+
}
|
|
11394
|
+
if (replaceBtn && queryInput && replaceInput && listEl) {
|
|
11395
|
+
const triggerReplace = () => {
|
|
11396
|
+
const queryVal = queryInput.value || '';
|
|
11397
|
+
if (!queryVal) return;
|
|
11398
|
+
this.replaceInWorkspace({ query: queryVal, replacement: replaceInput.value || '' });
|
|
11399
|
+
listEl.innerHTML = renderRows(queryVal);
|
|
11400
|
+
};
|
|
11401
|
+
replaceBtn.addEventListener('click', triggerReplace);
|
|
11402
|
+
replaceInput.addEventListener('keydown', (e) => {
|
|
11403
|
+
if (e.key === 'Enter') {
|
|
11404
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
11405
|
+
e.preventDefault();
|
|
11406
|
+
triggerReplace();
|
|
11407
|
+
}
|
|
11408
|
+
});
|
|
11409
|
+
}
|
|
8972
11410
|
}
|
|
8973
11411
|
|
|
8974
11412
|
showScmModal() {
|
|
8975
11413
|
const slot = this.container ? this.container.querySelector('#cl-modal-slot') : null;
|
|
8976
11414
|
if (!slot) return;
|
|
8977
11415
|
const statusList = this.getGitStatus();
|
|
8978
|
-
const
|
|
8979
|
-
|
|
8980
|
-
|
|
8981
|
-
|
|
8982
|
-
|
|
8983
|
-
|
|
11416
|
+
const gs = this._getGitState();
|
|
11417
|
+
const branch = (gs && gs.branch) ? gs.branch : 'main';
|
|
11418
|
+
const hasStaged = statusList.some((e) => e.staged);
|
|
11419
|
+
const hasUnstaged = statusList.some((e) => !e.staged);
|
|
11420
|
+
const rowsHtml = statusList.map((entry) => {
|
|
11421
|
+
const badge = entry.staged ? `Staged (${entry.index})` : (entry.worktree !== ' ' ? entry.worktree : entry.index);
|
|
11422
|
+
const actionBtn = entry.staged
|
|
11423
|
+
? `<button type="button" class="codelab-btn" data-cl-action="scm-unstage-file" data-scm-path="${escapeHtml(entry.path)}" style="padding:2px 8px;font-size:11px;">Unstage</button>`
|
|
11424
|
+
: `<button type="button" class="codelab-btn" data-cl-action="scm-stage-file" data-scm-path="${escapeHtml(entry.path)}" style="padding:2px 8px;font-size:11px;">Stage</button>`;
|
|
11425
|
+
return `
|
|
11426
|
+
<div class="codelab-scm-entry" data-scm-path="${escapeHtml(entry.path)}" style="display:flex;justify-content:space-between;align-items:center;padding:6px 8px;border-bottom:1px solid var(--cl-border);font-family:var(--cl-font-mono);font-size:12px;">
|
|
11427
|
+
<span data-cl-action="scm-open-file" data-scm-path="${escapeHtml(entry.path)}" style="cursor:pointer;text-decoration:underline;">${escapeHtml(entry.path)}</span>
|
|
11428
|
+
<span style="display:inline-flex;align-items:center;gap:8px;">
|
|
11429
|
+
<span>${escapeHtml(badge)}</span>
|
|
11430
|
+
${actionBtn}
|
|
11431
|
+
</span>
|
|
11432
|
+
</div>
|
|
11433
|
+
`;
|
|
11434
|
+
}).join('');
|
|
8984
11435
|
slot.innerHTML = `
|
|
8985
11436
|
<div class="codelab-modal-backdrop">
|
|
8986
11437
|
<div class="codelab-modal" role="dialog" aria-modal="true" aria-label="Source Control">
|
|
8987
11438
|
<div class="codelab-modal__header">
|
|
8988
|
-
<span>Source Control (Git Status)</span>
|
|
8989
|
-
<
|
|
11439
|
+
<span>Source Control (Git Status · ${escapeHtml(branch)})</span>
|
|
11440
|
+
<div style="display:flex;gap:6px;align-items:center;">
|
|
11441
|
+
${hasUnstaged ? `<button type="button" class="codelab-btn" data-cl-action="scm-stage-all" style="padding:3px 8px;font-size:11px;">Stage All</button>` : ''}
|
|
11442
|
+
<button type="button" class="codelab-btn" data-cl-action="close-modal">Close (Esc)</button>
|
|
11443
|
+
</div>
|
|
8990
11444
|
</div>
|
|
8991
11445
|
<div class="codelab-modal__body">
|
|
8992
|
-
<div
|
|
11446
|
+
<div style="display:flex;gap:8px;margin-bottom:8px;align-items:center;">
|
|
11447
|
+
<input id="cl-scm-commit-input" class="codelab-modal-input" type="text" placeholder="Commit message (e.g. feat: update module)..." />
|
|
11448
|
+
<button type="button" id="cl-scm-commit-btn" class="codelab-btn codelab-btn--primary" data-cl-action="scm-commit" ${hasStaged ? '' : 'disabled'} style="padding:5px 10px;font-size:12px;white-space:nowrap;">Commit</button>
|
|
11449
|
+
</div>
|
|
11450
|
+
<div id="cl-scm-status-list" style="max-height:300px;overflow-y:auto;">${rowsHtml || '<div style="color:var(--cl-fg-muted);font-size:12px;">Working tree clean</div>'}</div>
|
|
8993
11451
|
</div>
|
|
8994
11452
|
</div>
|
|
8995
11453
|
</div>
|
|
@@ -9001,11 +11459,14 @@ int main() {
|
|
|
9001
11459
|
const slot = this.container ? this.container.querySelector('#cl-modal-slot') : null;
|
|
9002
11460
|
if (!slot) return;
|
|
9003
11461
|
const items = this.getDiagnostics();
|
|
9004
|
-
const rowsHtml = items.map((d) =>
|
|
9005
|
-
|
|
9006
|
-
|
|
9007
|
-
|
|
9008
|
-
|
|
11462
|
+
const rowsHtml = items.map((d) => {
|
|
11463
|
+
const col = d.col || d.column || 1;
|
|
11464
|
+
return `
|
|
11465
|
+
<div class="codelab-problem-entry" data-problem-file="${escapeHtml(d.file || '')}" data-cl-problem-file="${escapeHtml(d.file || '')}" data-cl-problem-line="${d.line || 1}" data-cl-problem-col="${col}" role="button" tabindex="0" style="padding:6px 8px;border-bottom:1px solid var(--cl-border);cursor:pointer;font-family:var(--cl-font-mono);font-size:12px;">
|
|
11466
|
+
<strong>[${escapeHtml(d.severity)}] ${escapeHtml(d.file || '')}:${d.line || 1}:${col}</strong> — ${escapeHtml(d.message || '')}
|
|
11467
|
+
</div>
|
|
11468
|
+
`;
|
|
11469
|
+
}).join('');
|
|
9009
11470
|
slot.innerHTML = `
|
|
9010
11471
|
<div class="codelab-modal-backdrop">
|
|
9011
11472
|
<div class="codelab-modal" role="dialog" aria-modal="true" aria-label="Problems and Diagnostics">
|
|
@@ -9021,6 +11482,40 @@ int main() {
|
|
|
9021
11482
|
`;
|
|
9022
11483
|
}
|
|
9023
11484
|
|
|
11485
|
+
_clearTerminalLogs() {
|
|
11486
|
+
if (Array.isArray(this.terminalLogs)) {
|
|
11487
|
+
this.terminalLogs.length = 0;
|
|
11488
|
+
} else {
|
|
11489
|
+
this.terminalLogs = [];
|
|
11490
|
+
}
|
|
11491
|
+
if (Array.isArray(this._terminalSessions)) {
|
|
11492
|
+
const active = this._terminalSessions.find((s) => s.id === this._activeTerminalSessionId);
|
|
11493
|
+
if (active) {
|
|
11494
|
+
active.logs = this.terminalLogs;
|
|
11495
|
+
}
|
|
11496
|
+
}
|
|
11497
|
+
}
|
|
11498
|
+
|
|
11499
|
+
_renderTerminalSessionsBar() {
|
|
11500
|
+
if (!this.container || typeof this.container.querySelector !== 'function') return;
|
|
11501
|
+
const bar = this.container.querySelector('#cl-terminal-sessions');
|
|
11502
|
+
if (!bar) return;
|
|
11503
|
+
const sessions = this._ensureTerminalSessions();
|
|
11504
|
+
if (sessions.length <= 1) {
|
|
11505
|
+
bar.innerHTML = '';
|
|
11506
|
+
return;
|
|
11507
|
+
}
|
|
11508
|
+
bar.innerHTML = sessions.map((s) => {
|
|
11509
|
+
const isActive = s.id === this._activeTerminalSessionId;
|
|
11510
|
+
return `
|
|
11511
|
+
<span class="codelab-session-pill ${isActive ? 'active' : ''}" data-cl-action="switch-terminal-session" data-session-id="${escapeHtml(s.id)}" role="button" tabindex="0" title="Switch to ${escapeHtml(s.name)}">
|
|
11512
|
+
<span>${escapeHtml(s.name)}</span>
|
|
11513
|
+
<span data-cl-action="close-terminal-session" data-session-id="${escapeHtml(s.id)}" title="Close session" style="margin-left:2px;opacity:0.75;">×</span>
|
|
11514
|
+
</span>
|
|
11515
|
+
`;
|
|
11516
|
+
}).join('');
|
|
11517
|
+
}
|
|
11518
|
+
|
|
9024
11519
|
_ensureTerminalSessions() {
|
|
9025
11520
|
if (!Array.isArray(this._terminalSessions) || this._terminalSessions.length === 0) {
|
|
9026
11521
|
this._terminalSessions = [
|
|
@@ -9105,6 +11600,10 @@ int main() {
|
|
|
9105
11600
|
this.activeFile = this._pickDefaultFile();
|
|
9106
11601
|
}
|
|
9107
11602
|
this._saveState();
|
|
11603
|
+
if (this.kernel && this.kernel.fs) {
|
|
11604
|
+
this.kernel.fs.loadRecord(this.files, '/workspace');
|
|
11605
|
+
}
|
|
11606
|
+
this._syncDotCodelabConfig({ isInitialMount: false });
|
|
9108
11607
|
this._syncAllModels();
|
|
9109
11608
|
this._syncActiveFileToView();
|
|
9110
11609
|
}
|
|
@@ -9173,9 +11672,13 @@ int main() {
|
|
|
9173
11672
|
if (fallbackEl && this.activeFile === clean) {
|
|
9174
11673
|
fallbackEl.value = updated;
|
|
9175
11674
|
}
|
|
9176
|
-
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')) {
|
|
9177
11676
|
try {
|
|
9178
|
-
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
|
+
}
|
|
9179
11682
|
} catch (err) {
|
|
9180
11683
|
this.logger.warn(`Failed to sync markdown task toggle for "${clean}" to VFS.`, err);
|
|
9181
11684
|
}
|
|
@@ -9215,6 +11718,7 @@ int main() {
|
|
|
9215
11718
|
input.focus();
|
|
9216
11719
|
input.addEventListener('keydown', (e) => {
|
|
9217
11720
|
if (e.key === 'Enter' && input.value.trim()) {
|
|
11721
|
+
if (e.isComposing || e.keyCode === 229) return;
|
|
9218
11722
|
e.preventDefault();
|
|
9219
11723
|
const val = input.value.trim();
|
|
9220
11724
|
this.closeModal();
|
|
@@ -9392,6 +11896,8 @@ int main() {
|
|
|
9392
11896
|
plugin(this, pluginOptions);
|
|
9393
11897
|
} else if (typeof plugin === 'object' && typeof plugin.install === 'function') {
|
|
9394
11898
|
plugin.install(this, pluginOptions);
|
|
11899
|
+
} else if (typeof plugin === 'object' && typeof plugin.id === 'string' && typeof plugin.name === 'string') {
|
|
11900
|
+
this.registerPlugin(plugin);
|
|
9395
11901
|
}
|
|
9396
11902
|
if (this.enabledLanguages instanceof Set && this.enabledLanguages.size > 1) {
|
|
9397
11903
|
this.hasMultipleLanguages = true;
|
|
@@ -9405,11 +11911,65 @@ int main() {
|
|
|
9405
11911
|
}
|
|
9406
11912
|
|
|
9407
11913
|
destroy() {
|
|
11914
|
+
this._destroyed = true;
|
|
11915
|
+
this.flushState();
|
|
9408
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
|
+
}
|
|
9409
11949
|
if (this._previewReloadTimer) {
|
|
9410
11950
|
clearTimeout(this._previewReloadTimer);
|
|
9411
11951
|
this._previewReloadTimer = null;
|
|
9412
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
|
+
}
|
|
9413
11973
|
if (this._escHandler && typeof document !== 'undefined') {
|
|
9414
11974
|
document.removeEventListener('keydown', this._escHandler);
|
|
9415
11975
|
}
|
|
@@ -9433,6 +11993,13 @@ int main() {
|
|
|
9433
11993
|
this._editorResizeObserver.disconnect();
|
|
9434
11994
|
this._editorResizeObserver = null;
|
|
9435
11995
|
}
|
|
11996
|
+
if (this._diffManager && typeof this._diffManager.closeInlineDiff === 'function') {
|
|
11997
|
+
try {
|
|
11998
|
+
this._diffManager.closeInlineDiff();
|
|
11999
|
+
} catch (err) {
|
|
12000
|
+
this.logger.debug('diffManager.closeInlineDiff failed during destroy.', err);
|
|
12001
|
+
}
|
|
12002
|
+
}
|
|
9436
12003
|
if (this.editor) {
|
|
9437
12004
|
this.editor.dispose();
|
|
9438
12005
|
this.editor = null;
|
|
@@ -9458,12 +12025,10 @@ int main() {
|
|
|
9458
12025
|
attributeChangedCallback(name, oldVal, newVal) {
|
|
9459
12026
|
if (!this._instance || oldVal === newVal) return;
|
|
9460
12027
|
if (name === 'theme') {
|
|
9461
|
-
this._instance.
|
|
9462
|
-
const rootEl = this.querySelector('.codelab');
|
|
9463
|
-
if (rootEl) rootEl.setAttribute('data-cl-theme', this._instance._resolvedTheme());
|
|
12028
|
+
this._instance.setTheme(newVal || 'auto');
|
|
9464
12029
|
} else if (name === 'mode' && (newVal === 'guided' || newVal === 'sandbox')) {
|
|
9465
12030
|
this._instance.switchMode(newVal);
|
|
9466
|
-
} 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')) {
|
|
9467
12032
|
this._instance.switchLang(newVal);
|
|
9468
12033
|
} else if (name === 'title' && newVal) {
|
|
9469
12034
|
this._instance.title = newVal;
|
|
@@ -9520,35 +12085,51 @@ int main() {
|
|
|
9520
12085
|
}
|
|
9521
12086
|
|
|
9522
12087
|
getFiles() { return this._instance ? this._instance.getFiles() : {}; }
|
|
9523
|
-
setFiles(filesMap) {
|
|
9524
|
-
getFile(path) { return this._instance ? this._instance.getFile(path) :
|
|
9525
|
-
setFile(path, content, opts) {
|
|
9526
|
-
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; }
|
|
9527
12092
|
deleteFile(path) { return this._instance ? this._instance.deleteFile(path) : false; }
|
|
9528
12093
|
renameFile(oldPath, newPath) { return this._instance ? this._instance.renameFile(oldPath, newPath) : false; }
|
|
9529
12094
|
createFolder(path) { return this._instance ? this._instance.createFolder(path) : false; }
|
|
9530
12095
|
deleteFolder(path) { return this._instance ? this._instance.deleteFolder(path) : false; }
|
|
9531
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); }
|
|
9532
12103
|
openFile(path, sym) { if (this._instance) this._instance.openFile(path, sym); }
|
|
9533
12104
|
closeTab(path) { if (this._instance) this._instance.closeTab(path); }
|
|
9534
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(); }
|
|
9535
12110
|
openCommandPalette(mode) { if (this._instance) this._instance.openCommandPalette(mode); }
|
|
12111
|
+
closeCommandPalette() { if (this._instance) this._instance.closeCommandPalette(); }
|
|
9536
12112
|
showDiffModal(file, target) { if (this._instance) this._instance.showDiffModal(file, target); }
|
|
9537
12113
|
cloneRepo(repoInput, opts) { return this._instance ? this._instance.cloneRepo(repoInput, opts) : Promise.reject(new Error('Workbench not mounted')); }
|
|
9538
12114
|
runCode() { return this._instance ? this._instance.runCode() : Promise.resolve(); }
|
|
12115
|
+
runProject() { return this._instance ? this._instance.runProject() : Promise.resolve(); }
|
|
9539
12116
|
runEntry() { return this._instance ? this._instance.runEntry() : Promise.resolve(); }
|
|
9540
12117
|
runActiveFile() { return this._instance ? this._instance.runActiveFile() : Promise.resolve(); }
|
|
12118
|
+
runSelectedCode() { return this._instance ? this._instance.runSelectedCode() : Promise.resolve(null); }
|
|
9541
12119
|
runDemo() { return this._instance ? this._instance.runDemo() : Promise.resolve(); }
|
|
9542
12120
|
runTests(filter) { return this._instance ? this._instance.runTests(filter) : Promise.resolve(); }
|
|
9543
12121
|
formatActiveDocument() { return this._instance ? this._instance.formatActiveDocument() : Promise.resolve(); }
|
|
9544
12122
|
shareSnapshot() { return this._instance ? this._instance.shareSnapshot() : Promise.resolve(); }
|
|
9545
12123
|
previewApp() { return this._instance ? this._instance.previewApp() : Promise.resolve(null); }
|
|
9546
12124
|
stopExecution() { if (this._instance) this._instance.stopExecution(); }
|
|
9547
|
-
|
|
12125
|
+
cancelExecution() { if (this._instance) this._instance.cancelExecution(); }
|
|
12126
|
+
reset() { return this._instance ? this._instance.reset() : undefined; }
|
|
9548
12127
|
exportWorkspace(opts) { return this._instance ? this._instance.exportWorkspace(opts) : null; }
|
|
9549
12128
|
importWorkspace(snap) { return this._instance ? this._instance.importWorkspace(snap) : false; }
|
|
9550
12129
|
exportProjectZip(opts) { return this._instance ? this._instance.exportProjectZip(opts) : null; }
|
|
9551
|
-
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; }
|
|
9552
12133
|
searchWorkspace(opts) { return this._instance ? this._instance.searchWorkspace(opts) : null; }
|
|
9553
12134
|
replaceInWorkspace(opts) { return this._instance ? this._instance.replaceInWorkspace(opts) : null; }
|
|
9554
12135
|
getGitStatus() { return this._instance ? this._instance.getGitStatus() : []; }
|
|
@@ -9560,6 +12141,14 @@ int main() {
|
|
|
9560
12141
|
createTerminalSession(name) { return this._instance ? this._instance.createTerminalSession(name) : null; }
|
|
9561
12142
|
switchTerminalSession(id) { return this._instance ? this._instance.switchTerminalSession(id) : false; }
|
|
9562
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() {} }; }
|
|
9563
12152
|
on(ev, fn) { return this._instance ? this._instance.on(ev, fn) : () => {}; }
|
|
9564
12153
|
off(ev, fn) { if (this._instance) this._instance.off(ev, fn); }
|
|
9565
12154
|
use(plugin, opts) { if (this._instance) this._instance.use(plugin, opts); return this; }
|
|
@@ -9606,6 +12195,10 @@ int main() {
|
|
|
9606
12195
|
Runtime: root.CodeLabRuntime,
|
|
9607
12196
|
Shell: root.CodeLabShell,
|
|
9608
12197
|
Terminal: root.CodeLabTerminal,
|
|
12198
|
+
Modular: getModular(),
|
|
12199
|
+
sql: getSqlPack(),
|
|
12200
|
+
createSqlEditor: getSqlPack() ? getSqlPack().createSqlEditor : null,
|
|
12201
|
+
formatSql: getSqlPack() ? getSqlPack().formatSql : null,
|
|
9609
12202
|
zip: root.CodeLabZip || null,
|
|
9610
12203
|
createZip: root.CodeLabZip ? root.CodeLabZip.createZip : null,
|
|
9611
12204
|
extractZip: root.CodeLabZip ? root.CodeLabZip.extractZip : null,
|