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