@innovatorved/code-lab 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/ARCHITECTURE.md +11 -6
  2. package/CHANGELOG.md +27 -0
  3. package/README.md +18 -8
  4. package/dist/code-lab.css +198 -0
  5. package/dist/code-lab.d.ts +27 -9
  6. package/dist/code-lab.esm.js +8248 -83
  7. package/dist/code-lab.js +8246 -81
  8. package/dist/extensions/cpp.d.ts +32 -6
  9. package/dist/extensions/cpp.esm.js +745 -6
  10. package/dist/extensions/cpp.js +745 -6
  11. package/dist/extensions/guided-lab.esm.js +39 -1
  12. package/dist/extensions/guided-lab.js +39 -1
  13. package/dist/extensions/python.d.ts +92 -0
  14. package/dist/extensions/python.esm.js +5476 -0
  15. package/dist/extensions/python.js +5495 -0
  16. package/dist/index.d.ts +7 -4
  17. package/dist/preview-sw.js +1 -1
  18. package/dist/runtime/index.d.ts +4 -0
  19. package/dist/runtime/module-loader.d.ts +11 -0
  20. package/dist/runtime/test-harness.d.ts +24 -0
  21. package/dist/runtime/vfs.d.ts +31 -0
  22. package/dist/runtime/wasi-host.d.ts +33 -0
  23. package/dist/runtime.esm.js +36 -4
  24. package/dist/runtime.js +36 -4
  25. package/dist/schemas.d.ts +134 -21
  26. package/dist/schemas.esm.js +43 -1
  27. package/dist/schemas.js +43 -1
  28. package/dist/shell/coreutils/compilers-cli.d.ts +24 -0
  29. package/dist/shell/index.d.ts +4 -0
  30. package/dist/shell/lexer-parser.d.ts +26 -0
  31. package/dist/shell.esm.js +113 -1
  32. package/dist/shell.js +113 -1
  33. package/dist/terminal.esm.js +1 -1
  34. package/dist/terminal.js +1 -1
  35. package/dist/workbench/command-palette.d.ts +10 -0
  36. package/dist/workbench/diff-editor.d.ts +26 -0
  37. package/dist/workbench/drawer.d.ts +18 -0
  38. package/dist/workbench/editor.d.ts +11 -0
  39. package/dist/workbench/file-tree.d.ts +11 -0
  40. package/dist/workbench/guided-pane.d.ts +11 -0
  41. package/dist/workbench/icons.d.ts +5 -0
  42. package/dist/workbench/index.d.ts +39 -0
  43. package/dist/workbench/share.d.ts +21 -0
  44. package/dist/workbench/styles.d.ts +4 -0
  45. package/dist/workbench/toolbar.d.ts +17 -0
  46. package/dist/workbench.d.ts +6 -1
  47. package/package.json +8 -2
  48. package/src/code-lab.css +198 -0
  49. package/src/extensions/cpp.ts +710 -5
  50. package/src/extensions/python.ts +1293 -0
  51. package/src/index.ts +35 -3
  52. package/src/runtime/index.ts +5 -0
  53. package/src/runtime/test-harness.ts +57 -0
  54. package/src/runtime.ts +35 -3
  55. package/src/schemas.ts +46 -1
  56. package/src/shell/coreutils/compilers-cli.ts +103 -0
  57. package/src/shell/index.ts +5 -0
  58. package/src/shell.ts +112 -0
  59. package/src/workbench/command-palette.ts +140 -0
  60. package/src/workbench/diff-editor.ts +216 -0
  61. package/src/workbench/drawer.ts +148 -0
  62. package/src/workbench/editor.ts +49 -0
  63. package/src/workbench/file-tree.ts +51 -0
  64. package/src/workbench/guided-pane.ts +33 -0
  65. package/src/workbench/icons.ts +48 -0
  66. package/src/workbench/index.ts +38 -0
  67. package/src/workbench/share.ts +99 -0
  68. package/src/workbench/styles.ts +200 -0
  69. package/src/workbench/toolbar.ts +171 -0
  70. package/src/workbench.ts +755 -70
@@ -21,15 +21,21 @@ var CodeLabCpp = (() => {
21
21
  var cpp_exports = {};
22
22
  __export(cpp_exports, {
23
23
  BUILTIN_CPP_HEADERS: () => BUILTIN_CPP_HEADERS,
24
+ CPP_COMPLETIONS_AND_HOVERS: () => CPP_COMPLETIONS_AND_HOVERS,
24
25
  CppToolchainManager: () => CppToolchainManager,
25
26
  DEFAULT_CPP_CDN_BASE_URL: () => DEFAULT_CPP_CDN_BASE_URL,
27
+ STANDARD_CPP20_HEADERS: () => STANDARD_CPP20_HEADERS,
28
+ analyzeCppSource: () => analyzeCppSource,
29
+ applyClangStderrDiagnostics: () => applyClangStderrDiagnostics,
26
30
  cppExtension: () => cppExtension,
27
31
  createCppExtension: () => createCppExtension,
28
32
  createTarArchive: () => createTarArchive,
29
33
  default: () => cpp_default,
30
34
  extractTarToVfs: () => extractTarToVfs,
35
+ installCppExtension: () => installCppExtension,
31
36
  parseCppCompilerFlags: () => parseCppCompilerFlags,
32
37
  registerCppCompilerOnRuntime: () => registerCppCompilerOnRuntime,
38
+ registerMonacoCppLanguageService: () => registerMonacoCppLanguageService,
33
39
  seedCppHeadersIntoVfs: () => seedCppHeadersIntoVfs
34
40
  });
35
41
 
@@ -4087,7 +4093,7 @@ var CodeLabCpp = (() => {
4087
4093
  hint: external_exports.string().optional(),
4088
4094
  testNames: external_exports.array(external_exports.string()).optional()
4089
4095
  });
4090
- var LanguageIdSchema = external_exports.enum(["js", "ts", "cpp"]);
4096
+ var LanguageIdSchema = external_exports.enum(["js", "ts", "cpp", "py"]);
4091
4097
  var LanguageBundleSchema = external_exports.object({
4092
4098
  language: LanguageIdSchema.default("js"),
4093
4099
  files: external_exports.record(external_exports.string()).default({}),
@@ -4110,6 +4116,12 @@ var CodeLabCpp = (() => {
4110
4116
  cppStarterFiles: external_exports.record(external_exports.string()).optional(),
4111
4117
  cppSolutionFiles: external_exports.record(external_exports.string()).optional(),
4112
4118
  cppFiles: external_exports.record(external_exports.string()).optional(),
4119
+ pyStarterFiles: external_exports.record(external_exports.string()).optional(),
4120
+ pySolutionFiles: external_exports.record(external_exports.string()).optional(),
4121
+ pyFiles: external_exports.record(external_exports.string()).optional(),
4122
+ pyEntry: external_exports.string().optional(),
4123
+ pyTestEntry: external_exports.string().optional(),
4124
+ pyTestCode: external_exports.string().optional(),
4113
4125
  summary: external_exports.string().optional(),
4114
4126
  onStepComplete: external_exports.function().args(GuidedStepSchema, external_exports.number()).returns(external_exports.void()).optional(),
4115
4127
  onLabComplete: external_exports.function().args(external_exports.string()).returns(external_exports.void()).optional()
@@ -4141,6 +4153,30 @@ var CodeLabCpp = (() => {
4141
4153
  solutionFiles: external_exports.record(external_exports.string()).optional(),
4142
4154
  onProgress: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional()
4143
4155
  });
4156
+ var PythonToolchainProgressSchema = external_exports.object({
4157
+ stage: external_exports.enum(["downloading", "caching", "extracting", "initializing", "ready"]),
4158
+ loadedBytes: external_exports.number().optional(),
4159
+ totalBytes: external_exports.number().optional(),
4160
+ percent: external_exports.number().optional(),
4161
+ message: external_exports.string().optional()
4162
+ });
4163
+ var PythonExtensionOptionsSchema = external_exports.object({
4164
+ cdnBaseUrl: external_exports.string().optional(),
4165
+ indexUrl: external_exports.string().optional(),
4166
+ pyodideIndexUrl: external_exports.string().optional(),
4167
+ cacheInIndexedDB: external_exports.boolean().default(true),
4168
+ preload: external_exports.boolean().default(false),
4169
+ activate: external_exports.boolean().optional(),
4170
+ entry: external_exports.string().default("main.py"),
4171
+ testEntry: external_exports.string().default("test.py"),
4172
+ packages: external_exports.array(external_exports.string()).optional(),
4173
+ preloadPackages: external_exports.array(external_exports.string()).optional(),
4174
+ compilerMemoryLimitMb: external_exports.number().optional(),
4175
+ files: external_exports.record(external_exports.string()).optional(),
4176
+ starterFiles: external_exports.record(external_exports.string()).optional(),
4177
+ solutionFiles: external_exports.record(external_exports.string()).optional(),
4178
+ onProgress: external_exports.function().args(external_exports.any()).returns(external_exports.void()).optional()
4179
+ });
4144
4180
  var CloneProgressPhaseSchema = external_exports.enum([
4145
4181
  "connecting",
4146
4182
  "metadata",
@@ -4236,6 +4272,14 @@ var CodeLabCpp = (() => {
4236
4272
  cppFiles: external_exports.record(external_exports.string()).optional(),
4237
4273
  cppStarterFiles: external_exports.record(external_exports.string()).optional(),
4238
4274
  cppSolutionFiles: external_exports.record(external_exports.string()).optional(),
4275
+ pyFiles: external_exports.record(external_exports.string()).optional(),
4276
+ pyStarterFiles: external_exports.record(external_exports.string()).optional(),
4277
+ pySolutionFiles: external_exports.record(external_exports.string()).optional(),
4278
+ pyEntry: external_exports.string().optional().default("main.py"),
4279
+ pyTestEntry: external_exports.string().optional().default("test.py"),
4280
+ pyTestCode: external_exports.string().optional(),
4281
+ showWebPreview: external_exports.boolean().optional(),
4282
+ stdin: external_exports.string().optional(),
4239
4283
  guided: external_exports.any().optional(),
4240
4284
  mode: external_exports.enum(["guided", "sandbox"]).optional(),
4241
4285
  language: LanguageIdSchema.optional(),
@@ -5147,13 +5191,662 @@ inline void assertBool(bool cond, bool expected, const char* expr, int line) {
5147
5191
  }
5148
5192
  return compilerFn;
5149
5193
  }
5150
- function cppExtension(workbench, options = {}) {
5194
+ var STANDARD_CPP20_HEADERS = /* @__PURE__ */ new Set([
5195
+ "concepts",
5196
+ "coroutine",
5197
+ "any",
5198
+ "bitset",
5199
+ "chrono",
5200
+ "compare",
5201
+ "csetjmp",
5202
+ "csignal",
5203
+ "cstdarg",
5204
+ "cstddef",
5205
+ "cstdint",
5206
+ "cstdio",
5207
+ "cstdlib",
5208
+ "cstring",
5209
+ "ctime",
5210
+ "expected",
5211
+ "functional",
5212
+ "initializer_list",
5213
+ "optional",
5214
+ "source_location",
5215
+ "tuple",
5216
+ "type_traits",
5217
+ "typeindex",
5218
+ "typeinfo",
5219
+ "utility",
5220
+ "variant",
5221
+ "version",
5222
+ "memory",
5223
+ "memory_resource",
5224
+ "new",
5225
+ "scoped_allocator",
5226
+ "climits",
5227
+ "cfloat",
5228
+ "cerrno",
5229
+ "exception",
5230
+ "stdexcept",
5231
+ "system_error",
5232
+ "stacktrace",
5233
+ "cassert",
5234
+ "cctype",
5235
+ "cwctype",
5236
+ "cwchar",
5237
+ "cuchar",
5238
+ "string",
5239
+ "string_view",
5240
+ "format",
5241
+ "span",
5242
+ "array",
5243
+ "deque",
5244
+ "forward_list",
5245
+ "list",
5246
+ "vector",
5247
+ "map",
5248
+ "set",
5249
+ "unordered_map",
5250
+ "unordered_set",
5251
+ "queue",
5252
+ "stack",
5253
+ "flat_map",
5254
+ "flat_set",
5255
+ "mdspan",
5256
+ "iterator",
5257
+ "ranges",
5258
+ "algorithm",
5259
+ "numeric",
5260
+ "cmath",
5261
+ "complex",
5262
+ "valarray",
5263
+ "random",
5264
+ "ratio",
5265
+ "cfenv",
5266
+ "bit",
5267
+ "numbers",
5268
+ "locale",
5269
+ "clocale",
5270
+ "codecvt",
5271
+ "ios",
5272
+ "iosfwd",
5273
+ "iostream",
5274
+ "istream",
5275
+ "ostream",
5276
+ "sstream",
5277
+ "fstream",
5278
+ "syncstream",
5279
+ "iomanip",
5280
+ "streambuf",
5281
+ "strstream",
5282
+ "filesystem",
5283
+ "regex",
5284
+ "atomic",
5285
+ "thread",
5286
+ "stop_token",
5287
+ "mutex",
5288
+ "shared_mutex",
5289
+ "condition_variable",
5290
+ "future",
5291
+ "semaphore",
5292
+ "latch",
5293
+ "barrier",
5294
+ "bits/stdc++.h",
5295
+ "codelab/dsa.hpp",
5296
+ "codelab/test.hpp"
5297
+ ]);
5298
+ var CPP_COMPLETIONS_AND_HOVERS = {
5299
+ "std::vector": {
5300
+ label: "std::vector",
5301
+ detail: "template <typename T, typename Allocator = std::allocator<T>> class vector;",
5302
+ documentation: "Sequence container that encapsulates dynamic size arrays.\n\n- Header: `<vector>`\n- Indexing: $O(1)$\n- Push back: Amortized $O(1)$\n- Insert / Erase: $O(N)$",
5303
+ insertText: "std::vector<${1:int}> ${2:vec};",
5304
+ header: "<vector>",
5305
+ complexity: "O(1) access, Amortized O(1) push_back"
5306
+ },
5307
+ "std::unordered_map": {
5308
+ label: "std::unordered_map",
5309
+ detail: "template <typename Key, typename T> class unordered_map;",
5310
+ documentation: "Associative container with key-value pairs with unique keys using hash tables.\n\n- Header: `<unordered_map>`\n- Lookup: Average $O(1)$, Worst $O(N)$\n- Insert: Average $O(1)$, Worst $O(N)$",
5311
+ insertText: "std::unordered_map<${1:std::string}, ${2:int}> ${3:map};",
5312
+ header: "<unordered_map>",
5313
+ complexity: "Average O(1) lookup & insertion"
5314
+ },
5315
+ "std::map": {
5316
+ label: "std::map",
5317
+ detail: "template <typename Key, typename T> class map;",
5318
+ documentation: "Sorted associative container containing key-value pairs with unique keys (Red-Black Tree).\n\n- Header: `<map>`\n- Search/Insert/Delete: $O(\\log N)$",
5319
+ insertText: "std::map<${1:std::string}, ${2:int}> ${3:map};",
5320
+ header: "<map>",
5321
+ complexity: "O(log N)"
5322
+ },
5323
+ "std::set": {
5324
+ label: "std::set",
5325
+ detail: "template <typename Key> class set;",
5326
+ documentation: "Sorted associative container containing unique keys (Red-Black Tree).\n\n- Header: `<set>`\n- Search/Insert/Delete: $O(\\log N)$",
5327
+ insertText: "std::set<${1:int}> ${2:s};",
5328
+ header: "<set>",
5329
+ complexity: "O(log N)"
5330
+ },
5331
+ "std::priority_queue": {
5332
+ label: "std::priority_queue",
5333
+ detail: "template <typename T, typename Container = std::vector<T>> class priority_queue;",
5334
+ documentation: "Container adaptor providing max-heap functionality (or min-heap with std::greater).\n\n- Header: `<queue>`\n- Top: $O(1)$\n- Push / Pop: $O(\\log N)$",
5335
+ insertText: "std::priority_queue<${1:int}> ${2:pq};",
5336
+ header: "<queue>",
5337
+ complexity: "O(1) top, O(log N) push/pop"
5338
+ },
5339
+ "std::deque": {
5340
+ label: "std::deque",
5341
+ detail: "template <typename T> class deque;",
5342
+ documentation: "Double-ended queue sequence container.\n\n- Header: `<deque>`\n- Push/Pop Front & Back: $O(1)$\n- Random Access: $O(1)$",
5343
+ insertText: "std::deque<${1:int}> ${2:dq};",
5344
+ header: "<deque>",
5345
+ complexity: "O(1) front & back operations"
5346
+ },
5347
+ "std::stack": {
5348
+ label: "std::stack",
5349
+ detail: "template <typename T> class stack;",
5350
+ documentation: "LIFO stack container adaptor.\n\n- Header: `<stack>`\n- Push / Pop / Top: $O(1)$",
5351
+ insertText: "std::stack<${1:int}> ${2:st};",
5352
+ header: "<stack>",
5353
+ complexity: "O(1)"
5354
+ },
5355
+ "std::queue": {
5356
+ label: "std::queue",
5357
+ detail: "template <typename T> class queue;",
5358
+ documentation: "FIFO queue container adaptor.\n\n- Header: `<queue>`\n- Push / Pop / Front: $O(1)$",
5359
+ insertText: "std::queue<${1:int}> ${2:q};",
5360
+ header: "<queue>",
5361
+ complexity: "O(1)"
5362
+ },
5363
+ "std::string": {
5364
+ label: "std::string",
5365
+ detail: "typedef basic_string<char> string;",
5366
+ documentation: "Standard char sequence container with SSO (Small String Optimization).\n\n- Header: `<string>`",
5367
+ insertText: "std::string ${1:str};",
5368
+ header: "<string>",
5369
+ complexity: "O(1) size, O(1) amortized append"
5370
+ },
5371
+ "std::optional": {
5372
+ label: "std::optional",
5373
+ detail: "template <typename T> class optional;",
5374
+ documentation: "Manages an optional contained value, i.e. a value that may or may not be present.\n\n- Header: `<optional>`",
5375
+ insertText: "std::optional<${1:int}> ${2:opt};",
5376
+ header: "<optional>",
5377
+ complexity: "Zero heap allocation overhead"
5378
+ },
5379
+ "std::pair": {
5380
+ label: "std::pair",
5381
+ detail: "template <typename T1, typename T2> struct pair;",
5382
+ documentation: "Heterogeneous pair of values.\n\n- Header: `<utility>`",
5383
+ insertText: "std::pair<${1:int}, ${2:int}> ${3:p};",
5384
+ header: "<utility>",
5385
+ complexity: "O(1)"
5386
+ },
5387
+ "std::tuple": {
5388
+ label: "std::tuple",
5389
+ detail: "template <typename... Types> class tuple;",
5390
+ documentation: "Fixed-size collection of heterogeneous values.\n\n- Header: `<tuple>`",
5391
+ insertText: "std::tuple<${1:int}, ${2:std::string}> ${3:t};",
5392
+ header: "<tuple>",
5393
+ complexity: "O(1)"
5394
+ },
5395
+ "std::sort": {
5396
+ label: "std::sort",
5397
+ detail: "void sort(RandomIt first, RandomIt last, Compare comp = {});",
5398
+ documentation: "Sorts elements in range [first, last) in non-descending order (IntroSort).\n\n- Header: `<algorithm>`\n- Complexity: $O(N \\log N)$ comparisons",
5399
+ insertText: "std::sort(${1:vec}.begin(), ${1:vec}.end());",
5400
+ header: "<algorithm>",
5401
+ complexity: "O(N log N)"
5402
+ },
5403
+ "std::lower_bound": {
5404
+ label: "std::lower_bound",
5405
+ detail: "ForwardIt lower_bound(ForwardIt first, ForwardIt last, const T& value);",
5406
+ documentation: "Returns iterator to the first element that is not less than (i.e. greater or equal to) value.\n\n- Header: `<algorithm>`\n- Complexity: $O(\\log N)$ comparisons",
5407
+ insertText: "std::lower_bound(${1:vec}.begin(), ${1:vec}.end(), ${2:val});",
5408
+ header: "<algorithm>",
5409
+ complexity: "O(log N)"
5410
+ },
5411
+ "std::upper_bound": {
5412
+ label: "std::upper_bound",
5413
+ detail: "ForwardIt upper_bound(ForwardIt first, ForwardIt last, const T& value);",
5414
+ documentation: "Returns iterator to the first element that is strictly greater than value.\n\n- Header: `<algorithm>`\n- Complexity: $O(\\log N)$ comparisons",
5415
+ insertText: "std::upper_bound(${1:vec}.begin(), ${1:vec}.end(), ${2:val});",
5416
+ header: "<algorithm>",
5417
+ complexity: "O(log N)"
5418
+ },
5419
+ "std::binary_search": {
5420
+ label: "std::binary_search",
5421
+ detail: "bool binary_search(ForwardIt first, ForwardIt last, const T& value);",
5422
+ documentation: "Checks if value exists in sorted range [first, last).\n\n- Header: `<algorithm>`\n- Complexity: $O(\\log N)$",
5423
+ insertText: "std::binary_search(${1:vec}.begin(), ${1:vec}.end(), ${2:val});",
5424
+ header: "<algorithm>",
5425
+ complexity: "O(log N)"
5426
+ },
5427
+ "std::next_permutation": {
5428
+ label: "std::next_permutation",
5429
+ detail: "bool next_permutation(BidirIt first, BidirIt last);",
5430
+ documentation: "Rearranges elements into the lexicographically next greater permutation.\n\n- Header: `<algorithm>`\n- Complexity: $O(N)$",
5431
+ insertText: "std::next_permutation(${1:vec}.begin(), ${1:vec}.end());",
5432
+ header: "<algorithm>",
5433
+ complexity: "O(N)"
5434
+ },
5435
+ "std::accumulate": {
5436
+ label: "std::accumulate",
5437
+ detail: "T accumulate(InputIt first, InputIt last, T init);",
5438
+ documentation: "Computes sum of the given value init and elements in range [first, last).\n\n- Header: `<numeric>`\n- Complexity: $O(N)$",
5439
+ insertText: "std::accumulate(${1:vec}.begin(), ${1:vec}.end(), ${2:0});",
5440
+ header: "<numeric>",
5441
+ complexity: "O(N)"
5442
+ },
5443
+ "std::gcd": {
5444
+ label: "std::gcd",
5445
+ detail: "constexpr common_type_t<M, N> gcd(M m, N n);",
5446
+ documentation: "Computes greatest common divisor of m and n (Euclidean algorithm).\n\n- Header: `<numeric>`\n- Complexity: $O(\\log(\\min(m, n)))$",
5447
+ insertText: "std::gcd(${1:a}, ${2:b});",
5448
+ header: "<numeric>",
5449
+ complexity: "O(log(min(a, b)))"
5450
+ },
5451
+ "ListNode": {
5452
+ label: "ListNode",
5453
+ detail: "struct ListNode { int val; ListNode* next; ... };",
5454
+ documentation: "Standard LeetCode / DSA singly linked list node.\n\n- Header: `<codelab/dsa.hpp>`",
5455
+ insertText: "ListNode* ${1:head} = new ListNode(${2:0});",
5456
+ header: "<codelab/dsa.hpp>",
5457
+ complexity: "O(1) allocation"
5458
+ },
5459
+ "TreeNode": {
5460
+ label: "TreeNode",
5461
+ detail: "struct TreeNode { int val; TreeNode* left; TreeNode* right; ... };",
5462
+ documentation: "Standard LeetCode / DSA binary tree node.\n\n- Header: `<codelab/dsa.hpp>`",
5463
+ insertText: "TreeNode* ${1:root} = new TreeNode(${2:0});",
5464
+ header: "<codelab/dsa.hpp>",
5465
+ complexity: "O(1) allocation"
5466
+ },
5467
+ "buildLinkedList": {
5468
+ label: "buildLinkedList",
5469
+ detail: "ListNode* buildLinkedList(const std::vector<int>& values);",
5470
+ documentation: "Constructs a singly linked list from a std::vector of integers.\n\n- Header: `<codelab/dsa.hpp>`\n- Complexity: $O(N)$",
5471
+ insertText: "buildLinkedList({${1:1, 2, 3}});",
5472
+ header: "<codelab/dsa.hpp>",
5473
+ complexity: "O(N)"
5474
+ },
5475
+ "linkedListToVector": {
5476
+ label: "linkedListToVector",
5477
+ detail: "std::vector<int> linkedListToVector(const ListNode* head);",
5478
+ documentation: "Traverses a linked list and collects node values into a std::vector.\n\n- Header: `<codelab/dsa.hpp>`\n- Complexity: $O(N)$",
5479
+ insertText: "linkedListToVector(${1:head});",
5480
+ header: "<codelab/dsa.hpp>",
5481
+ complexity: "O(N)"
5482
+ },
5483
+ "buildBinaryTree": {
5484
+ label: "buildBinaryTree",
5485
+ detail: "TreeNode* buildBinaryTree(const std::vector<int>& values, int nullSentinel = INT_MIN);",
5486
+ documentation: "Constructs a binary tree in level-order from a vector with INT_MIN sentinels for null nodes.\n\n- Header: `<codelab/dsa.hpp>`\n- Complexity: $O(N)$",
5487
+ insertText: "buildBinaryTree({${1:1, 2, 3}});",
5488
+ header: "<codelab/dsa.hpp>",
5489
+ complexity: "O(N)"
5490
+ },
5491
+ "DESCRIBE": {
5492
+ label: "DESCRIBE",
5493
+ detail: "DESCRIBE(suite_name)",
5494
+ documentation: "Defines a named test suite in the CodeLab test harness.\n\n- Header: `<codelab/test.hpp>`",
5495
+ insertText: 'DESCRIBE("${1:Suite Name}");\n',
5496
+ header: "<codelab/test.hpp>",
5497
+ complexity: "CodeLab Test Suite"
5498
+ },
5499
+ "TEST": {
5500
+ label: "TEST",
5501
+ detail: "TEST(test_name, block)",
5502
+ documentation: "Defines and runs a single test case within the active suite.\n\n- Header: `<codelab/test.hpp>`",
5503
+ insertText: 'TEST("${1:should pass}", {\n ASSERT_EQ(${2:actual}, ${3:expected});\n});',
5504
+ header: "<codelab/test.hpp>",
5505
+ complexity: "CodeLab Test Runner"
5506
+ },
5507
+ "ASSERT_EQ": {
5508
+ label: "ASSERT_EQ",
5509
+ detail: "ASSERT_EQ(actual, expected)",
5510
+ documentation: "Asserts that actual == expected; logs failure message and stack if not.\n\n- Header: `<codelab/test.hpp>`",
5511
+ insertText: "ASSERT_EQ(${1:actual}, ${2:expected});",
5512
+ header: "<codelab/test.hpp>",
5513
+ complexity: "Assertion"
5514
+ },
5515
+ "ASSERT_TRUE": {
5516
+ label: "ASSERT_TRUE",
5517
+ detail: "ASSERT_TRUE(condition)",
5518
+ documentation: "Asserts that condition evaluates to true.\n\n- Header: `<codelab/test.hpp>`",
5519
+ insertText: "ASSERT_TRUE(${1:condition});",
5520
+ header: "<codelab/test.hpp>",
5521
+ complexity: "Assertion"
5522
+ },
5523
+ "ASSERT_FALSE": {
5524
+ label: "ASSERT_FALSE",
5525
+ detail: "ASSERT_FALSE(condition)",
5526
+ documentation: "Asserts that condition evaluates to false.\n\n- Header: `<codelab/test.hpp>`",
5527
+ insertText: "ASSERT_FALSE(${1:condition});",
5528
+ header: "<codelab/test.hpp>",
5529
+ complexity: "Assertion"
5530
+ },
5531
+ "ASSERT_NE": {
5532
+ label: "ASSERT_NE",
5533
+ detail: "ASSERT_NE(actual, expected)",
5534
+ documentation: "Asserts that actual != expected.\n\n- Header: `<codelab/test.hpp>`",
5535
+ insertText: "ASSERT_NE(${1:actual}, ${2:expected});",
5536
+ header: "<codelab/test.hpp>",
5537
+ complexity: "Assertion"
5538
+ },
5539
+ "CODELAB_TEST_EXIT_CODE": {
5540
+ label: "CODELAB_TEST_EXIT_CODE",
5541
+ detail: "CODELAB_TEST_EXIT_CODE()",
5542
+ documentation: "Returns 0 if all tests passed, 1 if any failed.\n\n- Header: `<codelab/test.hpp>`",
5543
+ insertText: "return CODELAB_TEST_EXIT_CODE();",
5544
+ header: "<codelab/test.hpp>",
5545
+ complexity: "Exit Code"
5546
+ }
5547
+ };
5548
+ var _monacoCppRegistered = false;
5549
+ function registerMonacoCppLanguageService(monacoInstance) {
5550
+ if (!monacoInstance || !monacoInstance.languages) return false;
5551
+ if (_monacoCppRegistered) return true;
5552
+ _monacoCppRegistered = true;
5553
+ try {
5554
+ monacoInstance.languages.registerCompletionItemProvider("cpp", {
5555
+ triggerCharacters: [".", ":", ">", "<"],
5556
+ provideCompletionItems(model, position) {
5557
+ const wordInfo = model.getWordUntilPosition(position);
5558
+ const range = {
5559
+ startLineNumber: position.lineNumber,
5560
+ endLineNumber: position.lineNumber,
5561
+ startColumn: wordInfo.startColumn,
5562
+ endColumn: wordInfo.endColumn
5563
+ };
5564
+ const suggestions = Object.keys(CPP_COMPLETIONS_AND_HOVERS).map((key) => {
5565
+ const item = CPP_COMPLETIONS_AND_HOVERS[key];
5566
+ return {
5567
+ label: item.label,
5568
+ kind: monacoInstance.languages.CompletionItemKind.Function,
5569
+ detail: item.detail,
5570
+ documentation: { value: item.documentation },
5571
+ insertText: item.insertText || item.label,
5572
+ insertTextRules: monacoInstance.languages.CompletionItemInsertTextRule.InsertAsSnippet,
5573
+ range
5574
+ };
5575
+ });
5576
+ return { suggestions };
5577
+ }
5578
+ });
5579
+ monacoInstance.languages.registerHoverProvider("cpp", {
5580
+ provideHover(model, position) {
5581
+ const word = model.getWordAtPosition(position);
5582
+ if (!word) return null;
5583
+ const key = CPP_COMPLETIONS_AND_HOVERS[word.word] ? word.word : CPP_COMPLETIONS_AND_HOVERS["std::" + word.word] ? "std::" + word.word : null;
5584
+ if (!key) return null;
5585
+ const item = CPP_COMPLETIONS_AND_HOVERS[key];
5586
+ return {
5587
+ range: {
5588
+ startLineNumber: position.lineNumber,
5589
+ endLineNumber: position.lineNumber,
5590
+ startColumn: word.startColumn,
5591
+ endColumn: word.endColumn
5592
+ },
5593
+ contents: [
5594
+ { value: `**${item.label}** \u2014 \`${item.detail}\`` },
5595
+ { value: item.documentation }
5596
+ ]
5597
+ };
5598
+ }
5599
+ });
5600
+ return true;
5601
+ } catch (err) {
5602
+ if (typeof console !== "undefined" && console.warn) {
5603
+ console.warn("[C++ Monaco Intelligence Error]:", err);
5604
+ }
5605
+ return false;
5606
+ }
5607
+ }
5608
+ function analyzeCppSource(source, filename = "main.cpp", vfs) {
5609
+ const diagnostics = [];
5610
+ if (!source || typeof source !== "string") return diagnostics;
5611
+ const lines = source.split("\n");
5612
+ const stack = [];
5613
+ const matchingPairs = { "}": "{", ")": "(", "]": "[" };
5614
+ let inBlockComment = false;
5615
+ for (let l = 0; l < lines.length; l++) {
5616
+ const line = lines[l];
5617
+ const lineNum = l + 1;
5618
+ let inString = false;
5619
+ let inChar = false;
5620
+ let stringQuote = "";
5621
+ for (let c = 0; c < line.length; c++) {
5622
+ const ch = line[c];
5623
+ const next = line[c + 1] || "";
5624
+ if (inBlockComment) {
5625
+ if (ch === "*" && next === "/") {
5626
+ inBlockComment = false;
5627
+ c++;
5628
+ }
5629
+ continue;
5630
+ }
5631
+ if (!inString && !inChar) {
5632
+ if (ch === "/" && next === "*") {
5633
+ inBlockComment = true;
5634
+ c++;
5635
+ continue;
5636
+ }
5637
+ if (ch === "/" && next === "/") {
5638
+ break;
5639
+ }
5640
+ }
5641
+ if (!inChar && (ch === '"' || ch === "R" && next === '"')) {
5642
+ if (ch === "R") c++;
5643
+ if (c === 0 || line[c - 1] !== "\\") {
5644
+ inString = !inString;
5645
+ stringQuote = inString ? '"' : "";
5646
+ }
5647
+ continue;
5648
+ }
5649
+ if (!inString && ch === "'") {
5650
+ if (c === 0 || line[c - 1] !== "\\") {
5651
+ inChar = !inChar;
5652
+ }
5653
+ continue;
5654
+ }
5655
+ if (inString || inChar) continue;
5656
+ if (ch === "{" || ch === "(" || ch === "[") {
5657
+ stack.push({ char: ch, line: lineNum, col: c + 1 });
5658
+ } else if (ch === "}" || ch === ")" || ch === "]") {
5659
+ const expectedOpening = matchingPairs[ch];
5660
+ const last = stack.pop();
5661
+ if (!last) {
5662
+ diagnostics.push({
5663
+ id: `cpp-bracket-unmatched-${lineNum}-${c + 1}`,
5664
+ file: filename,
5665
+ line: lineNum,
5666
+ col: c + 1,
5667
+ severity: "error",
5668
+ message: `Unmatched closing bracket '${ch}' with no opening counterpart.`,
5669
+ source: "cpp-linter"
5670
+ });
5671
+ } else if (last.char !== expectedOpening) {
5672
+ diagnostics.push({
5673
+ id: `cpp-bracket-mismatch-${lineNum}-${c + 1}`,
5674
+ file: filename,
5675
+ line: lineNum,
5676
+ col: c + 1,
5677
+ severity: "error",
5678
+ message: `Mismatched bracket: found '${ch}' but expected closing for '${last.char}' from line ${last.line}.`,
5679
+ source: "cpp-linter"
5680
+ });
5681
+ }
5682
+ }
5683
+ }
5684
+ if (inString && !inBlockComment) {
5685
+ diagnostics.push({
5686
+ id: `cpp-string-unterminated-${lineNum}`,
5687
+ file: filename,
5688
+ line: lineNum,
5689
+ col: line.length,
5690
+ severity: "error",
5691
+ message: "Unterminated string literal on line.",
5692
+ source: "cpp-linter"
5693
+ });
5694
+ }
5695
+ }
5696
+ for (const unclosed of stack) {
5697
+ diagnostics.push({
5698
+ id: `cpp-bracket-unclosed-${unclosed.line}-${unclosed.col}`,
5699
+ file: filename,
5700
+ line: unclosed.line,
5701
+ col: unclosed.col,
5702
+ severity: "error",
5703
+ message: `Unclosed bracket '${unclosed.char}' opened on line ${unclosed.line}.`,
5704
+ source: "cpp-linter"
5705
+ });
5706
+ }
5707
+ const includeRegex = /#include\s*([<"])([^>"]+)[>"]/g;
5708
+ let incMatch;
5709
+ const includedHeaders = /* @__PURE__ */ new Set();
5710
+ while ((incMatch = includeRegex.exec(source)) !== null) {
5711
+ const isAngle = incMatch[1] === "<";
5712
+ const hdr = incMatch[2].trim();
5713
+ includedHeaders.add(hdr);
5714
+ const lineIndex = source.slice(0, incMatch.index).split("\n").length;
5715
+ if (isAngle) {
5716
+ const known = STANDARD_CPP20_HEADERS.has(hdr) || hdr.startsWith("bits/") || hdr.startsWith("codelab/") || vfs && (vfs.existsSync(`/usr/include/${hdr}`) || vfs.existsSync(`/workspace/${hdr}`));
5717
+ if (!known) {
5718
+ diagnostics.push({
5719
+ id: `cpp-unknown-include-${lineIndex}`,
5720
+ file: filename,
5721
+ line: lineIndex,
5722
+ col: 1,
5723
+ severity: "warning",
5724
+ message: `Unknown or unresolvable C++ header <${hdr}>.`,
5725
+ source: "cpp-linter"
5726
+ });
5727
+ }
5728
+ }
5729
+ }
5730
+ const hasDsaHeader = includedHeaders.has("codelab/dsa.hpp") || includedHeaders.has("bits/stdc++.h");
5731
+ const dsaSymbols = ["ListNode", "TreeNode", "buildLinkedList", "linkedListToVector", "buildBinaryTree"];
5732
+ for (const sym of dsaSymbols) {
5733
+ const symRegex = new RegExp(`\\b${sym}\\b`);
5734
+ if (symRegex.test(source) && !hasDsaHeader) {
5735
+ diagnostics.push({
5736
+ id: `cpp-missing-dsa-include-${sym}`,
5737
+ file: filename,
5738
+ line: 1,
5739
+ col: 1,
5740
+ severity: "warning",
5741
+ message: `Symbol '${sym}' used without #include <codelab/dsa.hpp>.`,
5742
+ source: "cpp-linter"
5743
+ });
5744
+ break;
5745
+ }
5746
+ }
5747
+ const hasTestHeader = includedHeaders.has("codelab/test.hpp");
5748
+ const testSymbols = ["DESCRIBE", "TEST", "ASSERT_EQ", "ASSERT_NE", "ASSERT_TRUE", "ASSERT_FALSE", "CODELAB_TEST_EXIT_CODE"];
5749
+ for (const sym of testSymbols) {
5750
+ const symRegex = new RegExp(`\\b${sym}\\b`);
5751
+ if (symRegex.test(source) && !hasTestHeader) {
5752
+ diagnostics.push({
5753
+ id: `cpp-missing-test-include-${sym}`,
5754
+ file: filename,
5755
+ line: 1,
5756
+ col: 1,
5757
+ severity: "warning",
5758
+ message: `Test macro '${sym}' used without #include <codelab/test.hpp>.`,
5759
+ source: "cpp-linter"
5760
+ });
5761
+ break;
5762
+ }
5763
+ }
5764
+ for (let l = 0; l < lines.length; l++) {
5765
+ const line = lines[l];
5766
+ const assignMatch = /\bif\s*\(([^;)]*[^=!<>]=[^=][^;)]*)\)/.exec(line);
5767
+ if (assignMatch) {
5768
+ diagnostics.push({
5769
+ id: `cpp-suspicious-assign-${l + 1}`,
5770
+ file: filename,
5771
+ line: l + 1,
5772
+ col: assignMatch.index + 1,
5773
+ severity: "warning",
5774
+ message: `Suspicious assignment '=' inside 'if' condition; did you mean '=='?`,
5775
+ source: "cpp-linter"
5776
+ });
5777
+ }
5778
+ }
5779
+ const structRegex = /(?:struct|class)\s+([A-Za-z0-9_]+)\s*\{[^}]*\}\s*(?!;)(?=[A-Za-z0-9_#\s\n])/g;
5780
+ let structMatch;
5781
+ while ((structMatch = structRegex.exec(source)) !== null) {
5782
+ const lineIndex = source.slice(0, structMatch.index + structMatch[0].length).split("\n").length;
5783
+ diagnostics.push({
5784
+ id: `cpp-missing-semicolon-${lineIndex}`,
5785
+ file: filename,
5786
+ line: lineIndex,
5787
+ col: 1,
5788
+ severity: "error",
5789
+ message: `Missing semicolon ';' after '${structMatch[1]}' class/struct definition.`,
5790
+ source: "cpp-linter"
5791
+ });
5792
+ }
5793
+ return diagnostics;
5794
+ }
5795
+ function applyClangStderrDiagnostics(stderrText, diagnosticsStore, monacoInstance, activeModel) {
5796
+ const diagnostics = [];
5797
+ if (!stderrText || typeof stderrText !== "string") return diagnostics;
5798
+ if (diagnosticsStore && typeof diagnosticsStore.clear === "function") {
5799
+ diagnosticsStore.clear("clang");
5800
+ }
5801
+ const clangRegex = /(?:(?:^|\n)(?:\/workspace\/)?([^\s:\n]+)):(\d+):(\d+):\s*(fatal error|error|warning|note):\s*([^\n]+)/g;
5802
+ let match;
5803
+ let idx = 0;
5804
+ while ((match = clangRegex.exec(stderrText)) !== null) {
5805
+ const rawFile = match[1].trim();
5806
+ const line = parseInt(match[2], 10) || 1;
5807
+ const col = parseInt(match[3], 10) || 1;
5808
+ const rawKind = match[4].toLowerCase();
5809
+ const message = match[5].trim();
5810
+ let severity = "error";
5811
+ if (rawKind === "warning") severity = "warning";
5812
+ else if (rawKind === "note") severity = "info";
5813
+ const item = {
5814
+ id: `clang-${rawFile}-${line}-${col}-${idx++}`,
5815
+ file: rawFile,
5816
+ line,
5817
+ col,
5818
+ severity,
5819
+ message: `[Clang] ${message}`,
5820
+ source: "clang"
5821
+ };
5822
+ diagnostics.push(item);
5823
+ if (diagnosticsStore && typeof diagnosticsStore.add === "function") {
5824
+ diagnosticsStore.add(item);
5825
+ }
5826
+ }
5827
+ if (monacoInstance && activeModel && typeof monacoInstance.editor?.setModelMarkers === "function") {
5828
+ const markers = diagnostics.map((d) => ({
5829
+ startLineNumber: d.line,
5830
+ startColumn: d.col || 1,
5831
+ endLineNumber: d.line,
5832
+ endColumn: (d.col || 1) + 20,
5833
+ message: d.message,
5834
+ severity: d.severity === "error" ? monacoInstance.MarkerSeverity.Error : d.severity === "warning" ? monacoInstance.MarkerSeverity.Warning : monacoInstance.MarkerSeverity.Info
5835
+ }));
5836
+ monacoInstance.editor.setModelMarkers(activeModel, "clang", markers);
5837
+ }
5838
+ return diagnostics;
5839
+ }
5840
+ function installCppExtension(workbench, options = {}) {
5151
5841
  const toolchain = new CppToolchainManager(options);
5152
5842
  const compilerFn = registerCppCompilerOnRuntime(toolchain);
5153
5843
  if (!workbench) return toolchain;
5154
5844
  workbench.cppToolchain = toolchain;
5155
5845
  workbench.cppCompiler = compilerFn;
5156
5846
  workbench.cppOptions = toolchain.options;
5847
+ if (typeof window !== "undefined" && window.monaco) {
5848
+ registerMonacoCppLanguageService(window.monaco);
5849
+ }
5157
5850
  if (!workbench.enabledLanguages || !(workbench.enabledLanguages instanceof Set)) {
5158
5851
  workbench.enabledLanguages = /* @__PURE__ */ new Set(["js", "cpp"]);
5159
5852
  } else {
@@ -5183,6 +5876,35 @@ inline void assertBool(bool cond, bool expected, const char* expr, int line) {
5183
5876
  seedCppHeadersIntoVfs(workbench.vfs, toolchain.options.extraHeaders);
5184
5877
  }
5185
5878
  workbench.hasMultipleLanguages = workbench.enabledLanguages.size > 1;
5879
+ if (workbench._diagnosticsStore) {
5880
+ let lintTimer = null;
5881
+ const originalOnCodeChange = workbench.options?.onCodeChange;
5882
+ workbench._cppLintHandler = (file, code) => {
5883
+ if (!file || !/\.(?:cpp|cc|cxx|hpp|h)$/.test(file)) return;
5884
+ if (lintTimer) clearTimeout(lintTimer);
5885
+ lintTimer = setTimeout(() => {
5886
+ const diags = analyzeCppSource(code, file, workbench.vfs);
5887
+ workbench._diagnosticsStore.clear("cpp-linter");
5888
+ for (const d of diags) {
5889
+ workbench._diagnosticsStore.add(d);
5890
+ }
5891
+ if (typeof window !== "undefined" && window.monaco && workbench.editor) {
5892
+ const model = workbench.editor.getModel();
5893
+ if (model) {
5894
+ const markers = diags.map((d) => ({
5895
+ startLineNumber: d.line,
5896
+ startColumn: d.col || 1,
5897
+ endLineNumber: d.line,
5898
+ endColumn: (d.col || 1) + 20,
5899
+ message: d.message,
5900
+ severity: d.severity === "error" ? window.monaco.MarkerSeverity.Error : window.monaco.MarkerSeverity.Warning
5901
+ }));
5902
+ window.monaco.editor.setModelMarkers(model, "cpp-linter", markers);
5903
+ }
5904
+ }
5905
+ }, 180);
5906
+ };
5907
+ }
5186
5908
  if (options.preload) {
5187
5909
  toolchain.ensureLoaded().catch((err) => {
5188
5910
  if (typeof workbench._appendTerminalOutput === "function") {
@@ -5193,6 +5915,8 @@ inline void assertBool(bool cond, bool expected, const char* expr, int line) {
5193
5915
  }
5194
5916
  if (options.activate && typeof workbench.setLanguage === "function") {
5195
5917
  workbench.setLanguage("cpp");
5918
+ } else if (typeof workbench._refreshToolbarAndTabs === "function") {
5919
+ workbench._refreshToolbarAndTabs();
5196
5920
  } else if (typeof workbench._renderShell === "function" && workbench.container) {
5197
5921
  workbench._renderShell();
5198
5922
  if (typeof workbench._bindEvents === "function") workbench._bindEvents();
@@ -5200,11 +5924,26 @@ inline void assertBool(bool cond, bool expected, const char* expr, int line) {
5200
5924
  }
5201
5925
  return workbench;
5202
5926
  }
5927
+ function cppExtension(workbenchOrOptions, maybeOptions) {
5928
+ if (workbenchOrOptions === null) {
5929
+ const toolchain = new CppToolchainManager(maybeOptions || {});
5930
+ registerCppCompilerOnRuntime(toolchain);
5931
+ return toolchain;
5932
+ }
5933
+ if (workbenchOrOptions === void 0 || typeof workbenchOrOptions === "object" && !("enabledLanguages" in workbenchOrOptions) && !("container" in workbenchOrOptions) && !("_renderShell" in workbenchOrOptions)) {
5934
+ const opts = workbenchOrOptions || {};
5935
+ const plugin = (wb, runOpts = {}) => {
5936
+ return installCppExtension(wb, { ...opts, ...runOpts || {} });
5937
+ };
5938
+ plugin.extensionName = "cpp";
5939
+ plugin.languageId = "cpp";
5940
+ plugin.install = plugin;
5941
+ return plugin;
5942
+ }
5943
+ return installCppExtension(workbenchOrOptions, maybeOptions);
5944
+ }
5203
5945
  function createCppExtension(options = {}) {
5204
- const plugin = (workbench) => cppExtension(workbench, options);
5205
- plugin.extensionName = "cpp";
5206
- plugin.languageId = "cpp";
5207
- return plugin;
5946
+ return cppExtension(options);
5208
5947
  }
5209
5948
  var cpp_default = cppExtension;
5210
5949
  return __toCommonJS(cpp_exports);