@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
package/src/extensions/cpp.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CppExtensionOptions, CppExtensionOptionsSchema, CppToolchainProgress } from '../schemas';
|
|
2
|
+
import type { DiagnosticItem } from '../diagnostics';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Built-in competitive programming & DSA headers seeded into `/usr/include`
|
|
@@ -999,6 +1000,647 @@ export function registerCppCompilerOnRuntime(toolchain: CppToolchainManager) {
|
|
|
999
1000
|
return compilerFn;
|
|
1000
1001
|
}
|
|
1001
1002
|
|
|
1003
|
+
// ── VS Code–Style C++20 Language Intelligence & Real-time Linter ─────────────
|
|
1004
|
+
|
|
1005
|
+
/**
|
|
1006
|
+
* Full C++20 standard library header set + built-in CodeLab headers.
|
|
1007
|
+
*/
|
|
1008
|
+
export const STANDARD_CPP20_HEADERS: ReadonlySet<string> = new Set([
|
|
1009
|
+
'concepts', 'coroutine', 'any', 'bitset', 'chrono', 'compare', 'csetjmp', 'csignal',
|
|
1010
|
+
'cstdarg', 'cstddef', 'cstdint', 'cstdio', 'cstdlib', 'cstring', 'ctime', 'expected',
|
|
1011
|
+
'functional', 'initializer_list', 'optional', 'source_location', 'tuple', 'type_traits',
|
|
1012
|
+
'typeindex', 'typeinfo', 'utility', 'variant', 'version', 'memory', 'memory_resource',
|
|
1013
|
+
'new', 'scoped_allocator', 'climits', 'cfloat', 'cerrno', 'exception', 'stdexcept',
|
|
1014
|
+
'system_error', 'stacktrace', 'cassert', 'cctype', 'cwctype', 'cwchar', 'cuchar',
|
|
1015
|
+
'string', 'string_view', 'format', 'span', 'array', 'deque', 'forward_list', 'list',
|
|
1016
|
+
'vector', 'map', 'set', 'unordered_map', 'unordered_set', 'queue', 'stack', 'flat_map',
|
|
1017
|
+
'flat_set', 'mdspan', 'iterator', 'ranges', 'algorithm', 'numeric', 'cmath', 'complex',
|
|
1018
|
+
'valarray', 'random', 'ratio', 'cfenv', 'bit', 'numbers', 'locale', 'clocale', 'codecvt',
|
|
1019
|
+
'ios', 'iosfwd', 'iostream', 'istream', 'ostream', 'sstream', 'fstream', 'syncstream',
|
|
1020
|
+
'iomanip', 'streambuf', 'strstream', 'filesystem', 'regex', 'atomic', 'thread', 'stop_token',
|
|
1021
|
+
'mutex', 'shared_mutex', 'condition_variable', 'future', 'semaphore', 'latch', 'barrier',
|
|
1022
|
+
'bits/stdc++.h', 'codelab/dsa.hpp', 'codelab/test.hpp'
|
|
1023
|
+
]);
|
|
1024
|
+
|
|
1025
|
+
export interface CppSymbolDoc {
|
|
1026
|
+
label: string;
|
|
1027
|
+
kind?: string;
|
|
1028
|
+
detail: string;
|
|
1029
|
+
documentation: string;
|
|
1030
|
+
insertText?: string;
|
|
1031
|
+
header?: string;
|
|
1032
|
+
complexity?: string;
|
|
1033
|
+
}
|
|
1034
|
+
|
|
1035
|
+
export const CPP_COMPLETIONS_AND_HOVERS: Record<string, CppSymbolDoc> = {
|
|
1036
|
+
'std::vector': {
|
|
1037
|
+
label: 'std::vector',
|
|
1038
|
+
detail: 'template <typename T, typename Allocator = std::allocator<T>> class vector;',
|
|
1039
|
+
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)$',
|
|
1040
|
+
insertText: 'std::vector<${1:int}> ${2:vec};',
|
|
1041
|
+
header: '<vector>',
|
|
1042
|
+
complexity: 'O(1) access, Amortized O(1) push_back'
|
|
1043
|
+
},
|
|
1044
|
+
'std::unordered_map': {
|
|
1045
|
+
label: 'std::unordered_map',
|
|
1046
|
+
detail: 'template <typename Key, typename T> class unordered_map;',
|
|
1047
|
+
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)$',
|
|
1048
|
+
insertText: 'std::unordered_map<${1:std::string}, ${2:int}> ${3:map};',
|
|
1049
|
+
header: '<unordered_map>',
|
|
1050
|
+
complexity: 'Average O(1) lookup & insertion'
|
|
1051
|
+
},
|
|
1052
|
+
'std::map': {
|
|
1053
|
+
label: 'std::map',
|
|
1054
|
+
detail: 'template <typename Key, typename T> class map;',
|
|
1055
|
+
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)$',
|
|
1056
|
+
insertText: 'std::map<${1:std::string}, ${2:int}> ${3:map};',
|
|
1057
|
+
header: '<map>',
|
|
1058
|
+
complexity: 'O(log N)'
|
|
1059
|
+
},
|
|
1060
|
+
'std::set': {
|
|
1061
|
+
label: 'std::set',
|
|
1062
|
+
detail: 'template <typename Key> class set;',
|
|
1063
|
+
documentation: 'Sorted associative container containing unique keys (Red-Black Tree).\n\n- Header: `<set>`\n- Search/Insert/Delete: $O(\\log N)$',
|
|
1064
|
+
insertText: 'std::set<${1:int}> ${2:s};',
|
|
1065
|
+
header: '<set>',
|
|
1066
|
+
complexity: 'O(log N)'
|
|
1067
|
+
},
|
|
1068
|
+
'std::priority_queue': {
|
|
1069
|
+
label: 'std::priority_queue',
|
|
1070
|
+
detail: 'template <typename T, typename Container = std::vector<T>> class priority_queue;',
|
|
1071
|
+
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)$',
|
|
1072
|
+
insertText: 'std::priority_queue<${1:int}> ${2:pq};',
|
|
1073
|
+
header: '<queue>',
|
|
1074
|
+
complexity: 'O(1) top, O(log N) push/pop'
|
|
1075
|
+
},
|
|
1076
|
+
'std::deque': {
|
|
1077
|
+
label: 'std::deque',
|
|
1078
|
+
detail: 'template <typename T> class deque;',
|
|
1079
|
+
documentation: 'Double-ended queue sequence container.\n\n- Header: `<deque>`\n- Push/Pop Front & Back: $O(1)$\n- Random Access: $O(1)$',
|
|
1080
|
+
insertText: 'std::deque<${1:int}> ${2:dq};',
|
|
1081
|
+
header: '<deque>',
|
|
1082
|
+
complexity: 'O(1) front & back operations'
|
|
1083
|
+
},
|
|
1084
|
+
'std::stack': {
|
|
1085
|
+
label: 'std::stack',
|
|
1086
|
+
detail: 'template <typename T> class stack;',
|
|
1087
|
+
documentation: 'LIFO stack container adaptor.\n\n- Header: `<stack>`\n- Push / Pop / Top: $O(1)$',
|
|
1088
|
+
insertText: 'std::stack<${1:int}> ${2:st};',
|
|
1089
|
+
header: '<stack>',
|
|
1090
|
+
complexity: 'O(1)'
|
|
1091
|
+
},
|
|
1092
|
+
'std::queue': {
|
|
1093
|
+
label: 'std::queue',
|
|
1094
|
+
detail: 'template <typename T> class queue;',
|
|
1095
|
+
documentation: 'FIFO queue container adaptor.\n\n- Header: `<queue>`\n- Push / Pop / Front: $O(1)$',
|
|
1096
|
+
insertText: 'std::queue<${1:int}> ${2:q};',
|
|
1097
|
+
header: '<queue>',
|
|
1098
|
+
complexity: 'O(1)'
|
|
1099
|
+
},
|
|
1100
|
+
'std::string': {
|
|
1101
|
+
label: 'std::string',
|
|
1102
|
+
detail: 'typedef basic_string<char> string;',
|
|
1103
|
+
documentation: 'Standard char sequence container with SSO (Small String Optimization).\n\n- Header: `<string>`',
|
|
1104
|
+
insertText: 'std::string ${1:str};',
|
|
1105
|
+
header: '<string>',
|
|
1106
|
+
complexity: 'O(1) size, O(1) amortized append'
|
|
1107
|
+
},
|
|
1108
|
+
'std::optional': {
|
|
1109
|
+
label: 'std::optional',
|
|
1110
|
+
detail: 'template <typename T> class optional;',
|
|
1111
|
+
documentation: 'Manages an optional contained value, i.e. a value that may or may not be present.\n\n- Header: `<optional>`',
|
|
1112
|
+
insertText: 'std::optional<${1:int}> ${2:opt};',
|
|
1113
|
+
header: '<optional>',
|
|
1114
|
+
complexity: 'Zero heap allocation overhead'
|
|
1115
|
+
},
|
|
1116
|
+
'std::pair': {
|
|
1117
|
+
label: 'std::pair',
|
|
1118
|
+
detail: 'template <typename T1, typename T2> struct pair;',
|
|
1119
|
+
documentation: 'Heterogeneous pair of values.\n\n- Header: `<utility>`',
|
|
1120
|
+
insertText: 'std::pair<${1:int}, ${2:int}> ${3:p};',
|
|
1121
|
+
header: '<utility>',
|
|
1122
|
+
complexity: 'O(1)'
|
|
1123
|
+
},
|
|
1124
|
+
'std::tuple': {
|
|
1125
|
+
label: 'std::tuple',
|
|
1126
|
+
detail: 'template <typename... Types> class tuple;',
|
|
1127
|
+
documentation: 'Fixed-size collection of heterogeneous values.\n\n- Header: `<tuple>`',
|
|
1128
|
+
insertText: 'std::tuple<${1:int}, ${2:std::string}> ${3:t};',
|
|
1129
|
+
header: '<tuple>',
|
|
1130
|
+
complexity: 'O(1)'
|
|
1131
|
+
},
|
|
1132
|
+
'std::sort': {
|
|
1133
|
+
label: 'std::sort',
|
|
1134
|
+
detail: 'void sort(RandomIt first, RandomIt last, Compare comp = {});',
|
|
1135
|
+
documentation: 'Sorts elements in range [first, last) in non-descending order (IntroSort).\n\n- Header: `<algorithm>`\n- Complexity: $O(N \\log N)$ comparisons',
|
|
1136
|
+
insertText: 'std::sort(${1:vec}.begin(), ${1:vec}.end());',
|
|
1137
|
+
header: '<algorithm>',
|
|
1138
|
+
complexity: 'O(N log N)'
|
|
1139
|
+
},
|
|
1140
|
+
'std::lower_bound': {
|
|
1141
|
+
label: 'std::lower_bound',
|
|
1142
|
+
detail: 'ForwardIt lower_bound(ForwardIt first, ForwardIt last, const T& value);',
|
|
1143
|
+
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',
|
|
1144
|
+
insertText: 'std::lower_bound(${1:vec}.begin(), ${1:vec}.end(), ${2:val});',
|
|
1145
|
+
header: '<algorithm>',
|
|
1146
|
+
complexity: 'O(log N)'
|
|
1147
|
+
},
|
|
1148
|
+
'std::upper_bound': {
|
|
1149
|
+
label: 'std::upper_bound',
|
|
1150
|
+
detail: 'ForwardIt upper_bound(ForwardIt first, ForwardIt last, const T& value);',
|
|
1151
|
+
documentation: 'Returns iterator to the first element that is strictly greater than value.\n\n- Header: `<algorithm>`\n- Complexity: $O(\\log N)$ comparisons',
|
|
1152
|
+
insertText: 'std::upper_bound(${1:vec}.begin(), ${1:vec}.end(), ${2:val});',
|
|
1153
|
+
header: '<algorithm>',
|
|
1154
|
+
complexity: 'O(log N)'
|
|
1155
|
+
},
|
|
1156
|
+
'std::binary_search': {
|
|
1157
|
+
label: 'std::binary_search',
|
|
1158
|
+
detail: 'bool binary_search(ForwardIt first, ForwardIt last, const T& value);',
|
|
1159
|
+
documentation: 'Checks if value exists in sorted range [first, last).\n\n- Header: `<algorithm>`\n- Complexity: $O(\\log N)$',
|
|
1160
|
+
insertText: 'std::binary_search(${1:vec}.begin(), ${1:vec}.end(), ${2:val});',
|
|
1161
|
+
header: '<algorithm>',
|
|
1162
|
+
complexity: 'O(log N)'
|
|
1163
|
+
},
|
|
1164
|
+
'std::next_permutation': {
|
|
1165
|
+
label: 'std::next_permutation',
|
|
1166
|
+
detail: 'bool next_permutation(BidirIt first, BidirIt last);',
|
|
1167
|
+
documentation: 'Rearranges elements into the lexicographically next greater permutation.\n\n- Header: `<algorithm>`\n- Complexity: $O(N)$',
|
|
1168
|
+
insertText: 'std::next_permutation(${1:vec}.begin(), ${1:vec}.end());',
|
|
1169
|
+
header: '<algorithm>',
|
|
1170
|
+
complexity: 'O(N)'
|
|
1171
|
+
},
|
|
1172
|
+
'std::accumulate': {
|
|
1173
|
+
label: 'std::accumulate',
|
|
1174
|
+
detail: 'T accumulate(InputIt first, InputIt last, T init);',
|
|
1175
|
+
documentation: 'Computes sum of the given value init and elements in range [first, last).\n\n- Header: `<numeric>`\n- Complexity: $O(N)$',
|
|
1176
|
+
insertText: 'std::accumulate(${1:vec}.begin(), ${1:vec}.end(), ${2:0});',
|
|
1177
|
+
header: '<numeric>',
|
|
1178
|
+
complexity: 'O(N)'
|
|
1179
|
+
},
|
|
1180
|
+
'std::gcd': {
|
|
1181
|
+
label: 'std::gcd',
|
|
1182
|
+
detail: 'constexpr common_type_t<M, N> gcd(M m, N n);',
|
|
1183
|
+
documentation: 'Computes greatest common divisor of m and n (Euclidean algorithm).\n\n- Header: `<numeric>`\n- Complexity: $O(\\log(\\min(m, n)))$',
|
|
1184
|
+
insertText: 'std::gcd(${1:a}, ${2:b});',
|
|
1185
|
+
header: '<numeric>',
|
|
1186
|
+
complexity: 'O(log(min(a, b)))'
|
|
1187
|
+
},
|
|
1188
|
+
'ListNode': {
|
|
1189
|
+
label: 'ListNode',
|
|
1190
|
+
detail: 'struct ListNode { int val; ListNode* next; ... };',
|
|
1191
|
+
documentation: 'Standard LeetCode / DSA singly linked list node.\n\n- Header: `<codelab/dsa.hpp>`',
|
|
1192
|
+
insertText: 'ListNode* ${1:head} = new ListNode(${2:0});',
|
|
1193
|
+
header: '<codelab/dsa.hpp>',
|
|
1194
|
+
complexity: 'O(1) allocation'
|
|
1195
|
+
},
|
|
1196
|
+
'TreeNode': {
|
|
1197
|
+
label: 'TreeNode',
|
|
1198
|
+
detail: 'struct TreeNode { int val; TreeNode* left; TreeNode* right; ... };',
|
|
1199
|
+
documentation: 'Standard LeetCode / DSA binary tree node.\n\n- Header: `<codelab/dsa.hpp>`',
|
|
1200
|
+
insertText: 'TreeNode* ${1:root} = new TreeNode(${2:0});',
|
|
1201
|
+
header: '<codelab/dsa.hpp>',
|
|
1202
|
+
complexity: 'O(1) allocation'
|
|
1203
|
+
},
|
|
1204
|
+
'buildLinkedList': {
|
|
1205
|
+
label: 'buildLinkedList',
|
|
1206
|
+
detail: 'ListNode* buildLinkedList(const std::vector<int>& values);',
|
|
1207
|
+
documentation: 'Constructs a singly linked list from a std::vector of integers.\n\n- Header: `<codelab/dsa.hpp>`\n- Complexity: $O(N)$',
|
|
1208
|
+
insertText: 'buildLinkedList({${1:1, 2, 3}});',
|
|
1209
|
+
header: '<codelab/dsa.hpp>',
|
|
1210
|
+
complexity: 'O(N)'
|
|
1211
|
+
},
|
|
1212
|
+
'linkedListToVector': {
|
|
1213
|
+
label: 'linkedListToVector',
|
|
1214
|
+
detail: 'std::vector<int> linkedListToVector(const ListNode* head);',
|
|
1215
|
+
documentation: 'Traverses a linked list and collects node values into a std::vector.\n\n- Header: `<codelab/dsa.hpp>`\n- Complexity: $O(N)$',
|
|
1216
|
+
insertText: 'linkedListToVector(${1:head});',
|
|
1217
|
+
header: '<codelab/dsa.hpp>',
|
|
1218
|
+
complexity: 'O(N)'
|
|
1219
|
+
},
|
|
1220
|
+
'buildBinaryTree': {
|
|
1221
|
+
label: 'buildBinaryTree',
|
|
1222
|
+
detail: 'TreeNode* buildBinaryTree(const std::vector<int>& values, int nullSentinel = INT_MIN);',
|
|
1223
|
+
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)$',
|
|
1224
|
+
insertText: 'buildBinaryTree({${1:1, 2, 3}});',
|
|
1225
|
+
header: '<codelab/dsa.hpp>',
|
|
1226
|
+
complexity: 'O(N)'
|
|
1227
|
+
},
|
|
1228
|
+
'DESCRIBE': {
|
|
1229
|
+
label: 'DESCRIBE',
|
|
1230
|
+
detail: 'DESCRIBE(suite_name)',
|
|
1231
|
+
documentation: 'Defines a named test suite in the CodeLab test harness.\n\n- Header: `<codelab/test.hpp>`',
|
|
1232
|
+
insertText: 'DESCRIBE("${1:Suite Name}");\n',
|
|
1233
|
+
header: '<codelab/test.hpp>',
|
|
1234
|
+
complexity: 'CodeLab Test Suite'
|
|
1235
|
+
},
|
|
1236
|
+
'TEST': {
|
|
1237
|
+
label: 'TEST',
|
|
1238
|
+
detail: 'TEST(test_name, block)',
|
|
1239
|
+
documentation: 'Defines and runs a single test case within the active suite.\n\n- Header: `<codelab/test.hpp>`',
|
|
1240
|
+
insertText: 'TEST("${1:should pass}", {\n ASSERT_EQ(${2:actual}, ${3:expected});\n});',
|
|
1241
|
+
header: '<codelab/test.hpp>',
|
|
1242
|
+
complexity: 'CodeLab Test Runner'
|
|
1243
|
+
},
|
|
1244
|
+
'ASSERT_EQ': {
|
|
1245
|
+
label: 'ASSERT_EQ',
|
|
1246
|
+
detail: 'ASSERT_EQ(actual, expected)',
|
|
1247
|
+
documentation: 'Asserts that actual == expected; logs failure message and stack if not.\n\n- Header: `<codelab/test.hpp>`',
|
|
1248
|
+
insertText: 'ASSERT_EQ(${1:actual}, ${2:expected});',
|
|
1249
|
+
header: '<codelab/test.hpp>',
|
|
1250
|
+
complexity: 'Assertion'
|
|
1251
|
+
},
|
|
1252
|
+
'ASSERT_TRUE': {
|
|
1253
|
+
label: 'ASSERT_TRUE',
|
|
1254
|
+
detail: 'ASSERT_TRUE(condition)',
|
|
1255
|
+
documentation: 'Asserts that condition evaluates to true.\n\n- Header: `<codelab/test.hpp>`',
|
|
1256
|
+
insertText: 'ASSERT_TRUE(${1:condition});',
|
|
1257
|
+
header: '<codelab/test.hpp>',
|
|
1258
|
+
complexity: 'Assertion'
|
|
1259
|
+
},
|
|
1260
|
+
'ASSERT_FALSE': {
|
|
1261
|
+
label: 'ASSERT_FALSE',
|
|
1262
|
+
detail: 'ASSERT_FALSE(condition)',
|
|
1263
|
+
documentation: 'Asserts that condition evaluates to false.\n\n- Header: `<codelab/test.hpp>`',
|
|
1264
|
+
insertText: 'ASSERT_FALSE(${1:condition});',
|
|
1265
|
+
header: '<codelab/test.hpp>',
|
|
1266
|
+
complexity: 'Assertion'
|
|
1267
|
+
},
|
|
1268
|
+
'ASSERT_NE': {
|
|
1269
|
+
label: 'ASSERT_NE',
|
|
1270
|
+
detail: 'ASSERT_NE(actual, expected)',
|
|
1271
|
+
documentation: 'Asserts that actual != expected.\n\n- Header: `<codelab/test.hpp>`',
|
|
1272
|
+
insertText: 'ASSERT_NE(${1:actual}, ${2:expected});',
|
|
1273
|
+
header: '<codelab/test.hpp>',
|
|
1274
|
+
complexity: 'Assertion'
|
|
1275
|
+
},
|
|
1276
|
+
'CODELAB_TEST_EXIT_CODE': {
|
|
1277
|
+
label: 'CODELAB_TEST_EXIT_CODE',
|
|
1278
|
+
detail: 'CODELAB_TEST_EXIT_CODE()',
|
|
1279
|
+
documentation: 'Returns 0 if all tests passed, 1 if any failed.\n\n- Header: `<codelab/test.hpp>`',
|
|
1280
|
+
insertText: 'return CODELAB_TEST_EXIT_CODE();',
|
|
1281
|
+
header: '<codelab/test.hpp>',
|
|
1282
|
+
complexity: 'Exit Code'
|
|
1283
|
+
}
|
|
1284
|
+
};
|
|
1285
|
+
|
|
1286
|
+
let _monacoCppRegistered = false;
|
|
1287
|
+
|
|
1288
|
+
/**
|
|
1289
|
+
* Registers Monaco C++20 completion and hover providers.
|
|
1290
|
+
*/
|
|
1291
|
+
export function registerMonacoCppLanguageService(monacoInstance: any): boolean {
|
|
1292
|
+
if (!monacoInstance || !monacoInstance.languages) return false;
|
|
1293
|
+
if (_monacoCppRegistered) return true;
|
|
1294
|
+
_monacoCppRegistered = true;
|
|
1295
|
+
|
|
1296
|
+
try {
|
|
1297
|
+
monacoInstance.languages.registerCompletionItemProvider('cpp', {
|
|
1298
|
+
triggerCharacters: ['.', ':', '>', '<'],
|
|
1299
|
+
provideCompletionItems(model: any, position: any) {
|
|
1300
|
+
const wordInfo = model.getWordUntilPosition(position);
|
|
1301
|
+
const range = {
|
|
1302
|
+
startLineNumber: position.lineNumber,
|
|
1303
|
+
endLineNumber: position.lineNumber,
|
|
1304
|
+
startColumn: wordInfo.startColumn,
|
|
1305
|
+
endColumn: wordInfo.endColumn
|
|
1306
|
+
};
|
|
1307
|
+
|
|
1308
|
+
const suggestions = Object.keys(CPP_COMPLETIONS_AND_HOVERS).map((key) => {
|
|
1309
|
+
const item = CPP_COMPLETIONS_AND_HOVERS[key];
|
|
1310
|
+
return {
|
|
1311
|
+
label: item.label,
|
|
1312
|
+
kind: monacoInstance.languages.CompletionItemKind.Function,
|
|
1313
|
+
detail: item.detail,
|
|
1314
|
+
documentation: { value: item.documentation },
|
|
1315
|
+
insertText: item.insertText || item.label,
|
|
1316
|
+
insertTextRules: monacoInstance.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
1317
|
+
range
|
|
1318
|
+
};
|
|
1319
|
+
});
|
|
1320
|
+
|
|
1321
|
+
return { suggestions };
|
|
1322
|
+
}
|
|
1323
|
+
});
|
|
1324
|
+
|
|
1325
|
+
monacoInstance.languages.registerHoverProvider('cpp', {
|
|
1326
|
+
provideHover(model: any, position: any) {
|
|
1327
|
+
const word = model.getWordAtPosition(position);
|
|
1328
|
+
if (!word) return null;
|
|
1329
|
+
|
|
1330
|
+
// Try exact match or std:: + word
|
|
1331
|
+
const key = CPP_COMPLETIONS_AND_HOVERS[word.word]
|
|
1332
|
+
? word.word
|
|
1333
|
+
: (CPP_COMPLETIONS_AND_HOVERS['std::' + word.word] ? 'std::' + word.word : null);
|
|
1334
|
+
|
|
1335
|
+
if (!key) return null;
|
|
1336
|
+
const item = CPP_COMPLETIONS_AND_HOVERS[key];
|
|
1337
|
+
return {
|
|
1338
|
+
range: {
|
|
1339
|
+
startLineNumber: position.lineNumber,
|
|
1340
|
+
endLineNumber: position.lineNumber,
|
|
1341
|
+
startColumn: word.startColumn,
|
|
1342
|
+
endColumn: word.endColumn
|
|
1343
|
+
},
|
|
1344
|
+
contents: [
|
|
1345
|
+
{ value: `**${item.label}** — \`${item.detail}\`` },
|
|
1346
|
+
{ value: item.documentation }
|
|
1347
|
+
]
|
|
1348
|
+
};
|
|
1349
|
+
}
|
|
1350
|
+
});
|
|
1351
|
+
return true;
|
|
1352
|
+
} catch (err) {
|
|
1353
|
+
if (typeof console !== 'undefined' && console.warn) {
|
|
1354
|
+
console.warn('[C++ Monaco Intelligence Error]:', err);
|
|
1355
|
+
}
|
|
1356
|
+
return false;
|
|
1357
|
+
}
|
|
1358
|
+
}
|
|
1359
|
+
|
|
1360
|
+
/**
|
|
1361
|
+
* Real-time C++20 static AST/syntax linter.
|
|
1362
|
+
* Debounced on keystroke in `.cpp`, `.cc`, `.cxx`, `.hpp`, `.h` files.
|
|
1363
|
+
*/
|
|
1364
|
+
export function analyzeCppSource(source: string, filename = 'main.cpp', vfs?: any): DiagnosticItem[] {
|
|
1365
|
+
const diagnostics: DiagnosticItem[] = [];
|
|
1366
|
+
if (!source || typeof source !== 'string') return diagnostics;
|
|
1367
|
+
|
|
1368
|
+
const lines = source.split('\n');
|
|
1369
|
+
|
|
1370
|
+
// 1. Bracket stack matching: {}, (), []
|
|
1371
|
+
const stack: Array<{ char: string; line: number; col: number }> = [];
|
|
1372
|
+
const matchingPairs: Record<string, string> = { '}': '{', ')': '(', ']': '[' };
|
|
1373
|
+
|
|
1374
|
+
let inBlockComment = false;
|
|
1375
|
+
for (let l = 0; l < lines.length; l++) {
|
|
1376
|
+
const line = lines[l];
|
|
1377
|
+
const lineNum = l + 1;
|
|
1378
|
+
let inString = false;
|
|
1379
|
+
let inChar = false;
|
|
1380
|
+
let stringQuote = '';
|
|
1381
|
+
|
|
1382
|
+
for (let c = 0; c < line.length; c++) {
|
|
1383
|
+
const ch = line[c];
|
|
1384
|
+
const next = line[c + 1] || '';
|
|
1385
|
+
|
|
1386
|
+
if (inBlockComment) {
|
|
1387
|
+
if (ch === '*' && next === '/') {
|
|
1388
|
+
inBlockComment = false;
|
|
1389
|
+
c++;
|
|
1390
|
+
}
|
|
1391
|
+
continue;
|
|
1392
|
+
}
|
|
1393
|
+
|
|
1394
|
+
if (!inString && !inChar) {
|
|
1395
|
+
if (ch === '/' && next === '*') {
|
|
1396
|
+
inBlockComment = true;
|
|
1397
|
+
c++;
|
|
1398
|
+
continue;
|
|
1399
|
+
}
|
|
1400
|
+
if (ch === '/' && next === '/') {
|
|
1401
|
+
break; // Rest of line is comment
|
|
1402
|
+
}
|
|
1403
|
+
}
|
|
1404
|
+
|
|
1405
|
+
// Check string & char literal bounds
|
|
1406
|
+
if (!inChar && (ch === '"' || (ch === 'R' && next === '"'))) {
|
|
1407
|
+
if (ch === 'R') c++; // Raw string literal prefix
|
|
1408
|
+
if (c === 0 || line[c - 1] !== '\\') {
|
|
1409
|
+
inString = !inString;
|
|
1410
|
+
stringQuote = inString ? '"' : '';
|
|
1411
|
+
}
|
|
1412
|
+
continue;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
if (!inString && ch === '\'') {
|
|
1416
|
+
if (c === 0 || line[c - 1] !== '\\') {
|
|
1417
|
+
inChar = !inChar;
|
|
1418
|
+
}
|
|
1419
|
+
continue;
|
|
1420
|
+
}
|
|
1421
|
+
|
|
1422
|
+
if (inString || inChar) continue;
|
|
1423
|
+
|
|
1424
|
+
if (ch === '{' || ch === '(' || ch === '[') {
|
|
1425
|
+
stack.push({ char: ch, line: lineNum, col: c + 1 });
|
|
1426
|
+
} else if (ch === '}' || ch === ')' || ch === ']') {
|
|
1427
|
+
const expectedOpening = matchingPairs[ch];
|
|
1428
|
+
const last = stack.pop();
|
|
1429
|
+
if (!last) {
|
|
1430
|
+
diagnostics.push({
|
|
1431
|
+
id: `cpp-bracket-unmatched-${lineNum}-${c + 1}`,
|
|
1432
|
+
file: filename,
|
|
1433
|
+
line: lineNum,
|
|
1434
|
+
col: c + 1,
|
|
1435
|
+
severity: 'error',
|
|
1436
|
+
message: `Unmatched closing bracket '${ch}' with no opening counterpart.`,
|
|
1437
|
+
source: 'cpp-linter'
|
|
1438
|
+
});
|
|
1439
|
+
} else if (last.char !== expectedOpening) {
|
|
1440
|
+
diagnostics.push({
|
|
1441
|
+
id: `cpp-bracket-mismatch-${lineNum}-${c + 1}`,
|
|
1442
|
+
file: filename,
|
|
1443
|
+
line: lineNum,
|
|
1444
|
+
col: c + 1,
|
|
1445
|
+
severity: 'error',
|
|
1446
|
+
message: `Mismatched bracket: found '${ch}' but expected closing for '${last.char}' from line ${last.line}.`,
|
|
1447
|
+
source: 'cpp-linter'
|
|
1448
|
+
});
|
|
1449
|
+
}
|
|
1450
|
+
}
|
|
1451
|
+
}
|
|
1452
|
+
|
|
1453
|
+
if (inString && !inBlockComment) {
|
|
1454
|
+
diagnostics.push({
|
|
1455
|
+
id: `cpp-string-unterminated-${lineNum}`,
|
|
1456
|
+
file: filename,
|
|
1457
|
+
line: lineNum,
|
|
1458
|
+
col: line.length,
|
|
1459
|
+
severity: 'error',
|
|
1460
|
+
message: 'Unterminated string literal on line.',
|
|
1461
|
+
source: 'cpp-linter'
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
for (const unclosed of stack) {
|
|
1467
|
+
diagnostics.push({
|
|
1468
|
+
id: `cpp-bracket-unclosed-${unclosed.line}-${unclosed.col}`,
|
|
1469
|
+
file: filename,
|
|
1470
|
+
line: unclosed.line,
|
|
1471
|
+
col: unclosed.col,
|
|
1472
|
+
severity: 'error',
|
|
1473
|
+
message: `Unclosed bracket '${unclosed.char}' opened on line ${unclosed.line}.`,
|
|
1474
|
+
source: 'cpp-linter'
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
|
|
1478
|
+
// 2. Validate #include <...> against C++20 standard library + VFS
|
|
1479
|
+
const includeRegex = /#include\s*([<"])([^>"]+)[>"]/g;
|
|
1480
|
+
let incMatch: RegExpExecArray | null;
|
|
1481
|
+
const includedHeaders = new Set<string>();
|
|
1482
|
+
|
|
1483
|
+
while ((incMatch = includeRegex.exec(source)) !== null) {
|
|
1484
|
+
const isAngle = incMatch[1] === '<';
|
|
1485
|
+
const hdr = incMatch[2].trim();
|
|
1486
|
+
includedHeaders.add(hdr);
|
|
1487
|
+
const lineIndex = source.slice(0, incMatch.index).split('\n').length;
|
|
1488
|
+
|
|
1489
|
+
if (isAngle) {
|
|
1490
|
+
const known = STANDARD_CPP20_HEADERS.has(hdr) ||
|
|
1491
|
+
hdr.startsWith('bits/') ||
|
|
1492
|
+
hdr.startsWith('codelab/') ||
|
|
1493
|
+
(vfs && (vfs.existsSync(`/usr/include/${hdr}`) || vfs.existsSync(`/workspace/${hdr}`)));
|
|
1494
|
+
if (!known) {
|
|
1495
|
+
diagnostics.push({
|
|
1496
|
+
id: `cpp-unknown-include-${lineIndex}`,
|
|
1497
|
+
file: filename,
|
|
1498
|
+
line: lineIndex,
|
|
1499
|
+
col: 1,
|
|
1500
|
+
severity: 'warning',
|
|
1501
|
+
message: `Unknown or unresolvable C++ header <${hdr}>.`,
|
|
1502
|
+
source: 'cpp-linter'
|
|
1503
|
+
});
|
|
1504
|
+
}
|
|
1505
|
+
}
|
|
1506
|
+
}
|
|
1507
|
+
|
|
1508
|
+
// 3. Missing #include checks for DSA utilities and Test harness
|
|
1509
|
+
const hasDsaHeader = includedHeaders.has('codelab/dsa.hpp') || includedHeaders.has('bits/stdc++.h');
|
|
1510
|
+
const dsaSymbols = ['ListNode', 'TreeNode', 'buildLinkedList', 'linkedListToVector', 'buildBinaryTree'];
|
|
1511
|
+
for (const sym of dsaSymbols) {
|
|
1512
|
+
const symRegex = new RegExp(`\\b${sym}\\b`);
|
|
1513
|
+
if (symRegex.test(source) && !hasDsaHeader) {
|
|
1514
|
+
diagnostics.push({
|
|
1515
|
+
id: `cpp-missing-dsa-include-${sym}`,
|
|
1516
|
+
file: filename,
|
|
1517
|
+
line: 1,
|
|
1518
|
+
col: 1,
|
|
1519
|
+
severity: 'warning',
|
|
1520
|
+
message: `Symbol '${sym}' used without #include <codelab/dsa.hpp>.`,
|
|
1521
|
+
source: 'cpp-linter'
|
|
1522
|
+
});
|
|
1523
|
+
break;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
const hasTestHeader = includedHeaders.has('codelab/test.hpp');
|
|
1528
|
+
const testSymbols = ['DESCRIBE', 'TEST', 'ASSERT_EQ', 'ASSERT_NE', 'ASSERT_TRUE', 'ASSERT_FALSE', 'CODELAB_TEST_EXIT_CODE'];
|
|
1529
|
+
for (const sym of testSymbols) {
|
|
1530
|
+
const symRegex = new RegExp(`\\b${sym}\\b`);
|
|
1531
|
+
if (symRegex.test(source) && !hasTestHeader) {
|
|
1532
|
+
diagnostics.push({
|
|
1533
|
+
id: `cpp-missing-test-include-${sym}`,
|
|
1534
|
+
file: filename,
|
|
1535
|
+
line: 1,
|
|
1536
|
+
col: 1,
|
|
1537
|
+
severity: 'warning',
|
|
1538
|
+
message: `Test macro '${sym}' used without #include <codelab/test.hpp>.`,
|
|
1539
|
+
source: 'cpp-linter'
|
|
1540
|
+
});
|
|
1541
|
+
break;
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
// 4. Suspicious assignment inside if condition (e.g. if (x = 5))
|
|
1546
|
+
for (let l = 0; l < lines.length; l++) {
|
|
1547
|
+
const line = lines[l];
|
|
1548
|
+
const assignMatch = /\bif\s*\(([^;)]*[^=!<>]=[^=][^;)]*)\)/.exec(line);
|
|
1549
|
+
if (assignMatch) {
|
|
1550
|
+
diagnostics.push({
|
|
1551
|
+
id: `cpp-suspicious-assign-${l + 1}`,
|
|
1552
|
+
file: filename,
|
|
1553
|
+
line: l + 1,
|
|
1554
|
+
col: assignMatch.index + 1,
|
|
1555
|
+
severity: 'warning',
|
|
1556
|
+
message: `Suspicious assignment '=' inside 'if' condition; did you mean '=='?`,
|
|
1557
|
+
source: 'cpp-linter'
|
|
1558
|
+
});
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1561
|
+
|
|
1562
|
+
// 5. Missing semicolon after class or struct definitions
|
|
1563
|
+
const structRegex = /(?:struct|class)\s+([A-Za-z0-9_]+)\s*\{[^}]*\}\s*(?!;)(?=[A-Za-z0-9_#\s\n])/g;
|
|
1564
|
+
let structMatch: RegExpExecArray | null;
|
|
1565
|
+
while ((structMatch = structRegex.exec(source)) !== null) {
|
|
1566
|
+
const lineIndex = source.slice(0, structMatch.index + structMatch[0].length).split('\n').length;
|
|
1567
|
+
diagnostics.push({
|
|
1568
|
+
id: `cpp-missing-semicolon-${lineIndex}`,
|
|
1569
|
+
file: filename,
|
|
1570
|
+
line: lineIndex,
|
|
1571
|
+
col: 1,
|
|
1572
|
+
severity: 'error',
|
|
1573
|
+
message: `Missing semicolon ';' after '${structMatch[1]}' class/struct definition.`,
|
|
1574
|
+
source: 'cpp-linter'
|
|
1575
|
+
});
|
|
1576
|
+
}
|
|
1577
|
+
|
|
1578
|
+
return diagnostics;
|
|
1579
|
+
}
|
|
1580
|
+
|
|
1581
|
+
/**
|
|
1582
|
+
* Parses Clang / LLVM WASI compiler stderr and applies diagnostics to Monaco and DiagnosticsStore.
|
|
1583
|
+
*/
|
|
1584
|
+
export function applyClangStderrDiagnostics(
|
|
1585
|
+
stderrText: string,
|
|
1586
|
+
diagnosticsStore?: any,
|
|
1587
|
+
monacoInstance?: any,
|
|
1588
|
+
activeModel?: any
|
|
1589
|
+
): DiagnosticItem[] {
|
|
1590
|
+
const diagnostics: DiagnosticItem[] = [];
|
|
1591
|
+
if (!stderrText || typeof stderrText !== 'string') return diagnostics;
|
|
1592
|
+
|
|
1593
|
+
if (diagnosticsStore && typeof diagnosticsStore.clear === 'function') {
|
|
1594
|
+
diagnosticsStore.clear('clang');
|
|
1595
|
+
}
|
|
1596
|
+
|
|
1597
|
+
const clangRegex = /(?:(?:^|\n)(?:\/workspace\/)?([^\s:\n]+)):(\d+):(\d+):\s*(fatal error|error|warning|note):\s*([^\n]+)/g;
|
|
1598
|
+
let match: RegExpExecArray | null;
|
|
1599
|
+
let idx = 0;
|
|
1600
|
+
|
|
1601
|
+
while ((match = clangRegex.exec(stderrText)) !== null) {
|
|
1602
|
+
const rawFile = match[1].trim();
|
|
1603
|
+
const line = parseInt(match[2], 10) || 1;
|
|
1604
|
+
const col = parseInt(match[3], 10) || 1;
|
|
1605
|
+
const rawKind = match[4].toLowerCase();
|
|
1606
|
+
const message = match[5].trim();
|
|
1607
|
+
|
|
1608
|
+
let severity: 'error' | 'warning' | 'info' = 'error';
|
|
1609
|
+
if (rawKind === 'warning') severity = 'warning';
|
|
1610
|
+
else if (rawKind === 'note') severity = 'info';
|
|
1611
|
+
|
|
1612
|
+
const item: DiagnosticItem = {
|
|
1613
|
+
id: `clang-${rawFile}-${line}-${col}-${idx++}`,
|
|
1614
|
+
file: rawFile,
|
|
1615
|
+
line,
|
|
1616
|
+
col,
|
|
1617
|
+
severity,
|
|
1618
|
+
message: `[Clang] ${message}`,
|
|
1619
|
+
source: 'clang'
|
|
1620
|
+
};
|
|
1621
|
+
diagnostics.push(item);
|
|
1622
|
+
if (diagnosticsStore && typeof diagnosticsStore.add === 'function') {
|
|
1623
|
+
diagnosticsStore.add(item);
|
|
1624
|
+
}
|
|
1625
|
+
}
|
|
1626
|
+
|
|
1627
|
+
if (monacoInstance && activeModel && typeof monacoInstance.editor?.setModelMarkers === 'function') {
|
|
1628
|
+
const markers = diagnostics.map((d) => ({
|
|
1629
|
+
startLineNumber: d.line,
|
|
1630
|
+
startColumn: d.col || 1,
|
|
1631
|
+
endLineNumber: d.line,
|
|
1632
|
+
endColumn: (d.col || 1) + 20,
|
|
1633
|
+
message: d.message,
|
|
1634
|
+
severity: d.severity === 'error'
|
|
1635
|
+
? monacoInstance.MarkerSeverity.Error
|
|
1636
|
+
: (d.severity === 'warning' ? monacoInstance.MarkerSeverity.Warning : monacoInstance.MarkerSeverity.Info)
|
|
1637
|
+
}));
|
|
1638
|
+
monacoInstance.editor.setModelMarkers(activeModel, 'clang', markers);
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
return diagnostics;
|
|
1642
|
+
}
|
|
1643
|
+
|
|
1002
1644
|
/**
|
|
1003
1645
|
* Real C++20 in WebAssembly Extension for CodeLab (`@innovatorved/code-lab/extensions/cpp`).
|
|
1004
1646
|
*
|
|
@@ -1008,8 +1650,9 @@ export function registerCppCompilerOnRuntime(toolchain: CppToolchainManager) {
|
|
|
1008
1650
|
* - `JS | TS | C++` language switcher in the CodeLab workbench
|
|
1009
1651
|
* - `g++`, `clang++`, `c++`, and `./a.out` binary execution in the POSIX shell
|
|
1010
1652
|
* - Guided Lab `cppStarterFiles`, `cppSolutionFiles`, and `cppFiles` curriculum support
|
|
1653
|
+
* - Monaco IntelliSense, hovers, debounced C++20 static linter, and Clang compiler squiggles
|
|
1011
1654
|
*/
|
|
1012
|
-
export function
|
|
1655
|
+
export function installCppExtension(workbench: any, options: ExtendedCppExtensionOptions = {}) {
|
|
1013
1656
|
const toolchain = new CppToolchainManager(options);
|
|
1014
1657
|
const compilerFn = registerCppCompilerOnRuntime(toolchain);
|
|
1015
1658
|
|
|
@@ -1019,6 +1662,11 @@ export function cppExtension(workbench: any, options: ExtendedCppExtensionOption
|
|
|
1019
1662
|
workbench.cppCompiler = compilerFn;
|
|
1020
1663
|
workbench.cppOptions = toolchain.options;
|
|
1021
1664
|
|
|
1665
|
+
// Register Monaco language service if monaco is available
|
|
1666
|
+
if (typeof window !== 'undefined' && (window as any).monaco) {
|
|
1667
|
+
registerMonacoCppLanguageService((window as any).monaco);
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1022
1670
|
if (!workbench.enabledLanguages || !(workbench.enabledLanguages instanceof Set)) {
|
|
1023
1671
|
workbench.enabledLanguages = new Set(['js', 'cpp']);
|
|
1024
1672
|
} else {
|
|
@@ -1052,6 +1700,39 @@ export function cppExtension(workbench: any, options: ExtendedCppExtensionOption
|
|
|
1052
1700
|
|
|
1053
1701
|
workbench.hasMultipleLanguages = workbench.enabledLanguages.size > 1;
|
|
1054
1702
|
|
|
1703
|
+
// Wire up debounced static linter if workbench has diagnostics store
|
|
1704
|
+
if (workbench._diagnosticsStore) {
|
|
1705
|
+
let lintTimer: any = null;
|
|
1706
|
+
const originalOnCodeChange = workbench.options?.onCodeChange;
|
|
1707
|
+
workbench._cppLintHandler = (file: string, code: string) => {
|
|
1708
|
+
if (!file || !/\.(?:cpp|cc|cxx|hpp|h)$/.test(file)) return;
|
|
1709
|
+
if (lintTimer) clearTimeout(lintTimer);
|
|
1710
|
+
lintTimer = setTimeout(() => {
|
|
1711
|
+
const diags = analyzeCppSource(code, file, workbench.vfs);
|
|
1712
|
+
workbench._diagnosticsStore.clear('cpp-linter');
|
|
1713
|
+
for (const d of diags) {
|
|
1714
|
+
workbench._diagnosticsStore.add(d);
|
|
1715
|
+
}
|
|
1716
|
+
if (typeof window !== 'undefined' && (window as any).monaco && workbench.editor) {
|
|
1717
|
+
const model = workbench.editor.getModel();
|
|
1718
|
+
if (model) {
|
|
1719
|
+
const markers = diags.map((d) => ({
|
|
1720
|
+
startLineNumber: d.line,
|
|
1721
|
+
startColumn: d.col || 1,
|
|
1722
|
+
endLineNumber: d.line,
|
|
1723
|
+
endColumn: (d.col || 1) + 20,
|
|
1724
|
+
message: d.message,
|
|
1725
|
+
severity: d.severity === 'error'
|
|
1726
|
+
? (window as any).monaco.MarkerSeverity.Error
|
|
1727
|
+
: (window as any).monaco.MarkerSeverity.Warning
|
|
1728
|
+
}));
|
|
1729
|
+
(window as any).monaco.editor.setModelMarkers(model, 'cpp-linter', markers);
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
}, 180);
|
|
1733
|
+
};
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1055
1736
|
if (options.preload) {
|
|
1056
1737
|
toolchain.ensureLoaded().catch((err) => {
|
|
1057
1738
|
if (typeof workbench._appendTerminalOutput === 'function') {
|
|
@@ -1062,6 +1743,8 @@ export function cppExtension(workbench: any, options: ExtendedCppExtensionOption
|
|
|
1062
1743
|
|
|
1063
1744
|
if (options.activate && typeof workbench.setLanguage === 'function') {
|
|
1064
1745
|
workbench.setLanguage('cpp');
|
|
1746
|
+
} else if (typeof workbench._refreshToolbarAndTabs === 'function') {
|
|
1747
|
+
workbench._refreshToolbarAndTabs();
|
|
1065
1748
|
} else if (typeof workbench._renderShell === 'function' && workbench.container) {
|
|
1066
1749
|
workbench._renderShell();
|
|
1067
1750
|
if (typeof workbench._bindEvents === 'function') workbench._bindEvents();
|
|
@@ -1071,11 +1754,33 @@ export function cppExtension(workbench: any, options: ExtendedCppExtensionOption
|
|
|
1071
1754
|
return workbench;
|
|
1072
1755
|
}
|
|
1073
1756
|
|
|
1757
|
+
export function cppExtension(workbenchOrOptions?: any, maybeOptions?: ExtendedCppExtensionOptions): any {
|
|
1758
|
+
if (workbenchOrOptions === null) {
|
|
1759
|
+
const toolchain = new CppToolchainManager(maybeOptions || {});
|
|
1760
|
+
registerCppCompilerOnRuntime(toolchain);
|
|
1761
|
+
return toolchain;
|
|
1762
|
+
}
|
|
1763
|
+
if (
|
|
1764
|
+
workbenchOrOptions === undefined ||
|
|
1765
|
+
(typeof workbenchOrOptions === 'object' &&
|
|
1766
|
+
!('enabledLanguages' in workbenchOrOptions) &&
|
|
1767
|
+
!('container' in workbenchOrOptions) &&
|
|
1768
|
+
!('_renderShell' in workbenchOrOptions))
|
|
1769
|
+
) {
|
|
1770
|
+
const opts = (workbenchOrOptions || {}) as ExtendedCppExtensionOptions;
|
|
1771
|
+
const plugin: any = (wb: any, runOpts: any = {}) => {
|
|
1772
|
+
return installCppExtension(wb, { ...opts, ...(runOpts || {}) });
|
|
1773
|
+
};
|
|
1774
|
+
plugin.extensionName = 'cpp';
|
|
1775
|
+
plugin.languageId = 'cpp' as const;
|
|
1776
|
+
plugin.install = plugin;
|
|
1777
|
+
return plugin;
|
|
1778
|
+
}
|
|
1779
|
+
return installCppExtension(workbenchOrOptions, maybeOptions);
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1074
1782
|
export function createCppExtension(options: ExtendedCppExtensionOptions = {}) {
|
|
1075
|
-
|
|
1076
|
-
plugin.extensionName = 'cpp';
|
|
1077
|
-
plugin.languageId = 'cpp' as const;
|
|
1078
|
-
return plugin;
|
|
1783
|
+
return cppExtension(options);
|
|
1079
1784
|
}
|
|
1080
1785
|
|
|
1081
1786
|
export default cppExtension;
|