cobolx-2 1.2.3

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 (284) hide show
  1. package/.github/pull_request_template.md +9 -0
  2. package/.github/workflows/ci.yml +18 -0
  3. package/.vscode/launch.json +19 -0
  4. package/.vscode/tasks.json +14 -0
  5. package/CHANGELOG.md +16 -0
  6. package/CONTRIBUTING.md +23 -0
  7. package/CargoX.lock +2 -0
  8. package/LICENSE +21 -0
  9. package/README.md +164 -0
  10. package/api-demo/CargoX.lock +1 -0
  11. package/api-demo/README.md +3 -0
  12. package/api-demo/benchmarks/arith.cbx +6 -0
  13. package/api-demo/cobolx.toml +6 -0
  14. package/api-demo/docs-output/index.html +1 -0
  15. package/api-demo/generated/LEGACYDEMO.cbx +5 -0
  16. package/api-demo/generated/client-types.ts +2 -0
  17. package/api-demo/generated/deploy.json +12 -0
  18. package/api-demo/generated/flowchart.mmd +4 -0
  19. package/api-demo/migrations/20260411215238_init.sql +1 -0
  20. package/api-demo/src/main.cbx +5 -0
  21. package/api-demo/tests/smoke.cbx +6 -0
  22. package/benchmarks/arithmetic.cbx +6 -0
  23. package/cargox/package.json +11 -0
  24. package/cargox/src/index.d.ts +4 -0
  25. package/cargox/src/index.js +5 -0
  26. package/cargox/src/index.js.map +1 -0
  27. package/cargox/src/index.ts +4 -0
  28. package/cargox/src/lockfile/index.d.ts +1 -0
  29. package/cargox/src/lockfile/index.js +9 -0
  30. package/cargox/src/lockfile/index.js.map +1 -0
  31. package/cargox/src/lockfile/index.ts +9 -0
  32. package/cargox/src/manifest.d.ts +10 -0
  33. package/cargox/src/manifest.js +49 -0
  34. package/cargox/src/manifest.js.map +1 -0
  35. package/cargox/src/manifest.ts +58 -0
  36. package/cargox/src/registry/index.d.ts +4 -0
  37. package/cargox/src/registry/index.js +13 -0
  38. package/cargox/src/registry/index.js.map +1 -0
  39. package/cargox/src/registry/index.ts +13 -0
  40. package/cargox/src/resolver/index.d.ts +5 -0
  41. package/cargox/src/resolver/index.js +4 -0
  42. package/cargox/src/resolver/index.js.map +1 -0
  43. package/cargox/src/resolver/index.ts +8 -0
  44. package/cargox/tsconfig.json +7 -0
  45. package/cli/cobolx-cli/package.json +23 -0
  46. package/cli/cobolx-cli/src/commands/add.ts +18 -0
  47. package/cli/cobolx-cli/src/commands/bench.ts +47 -0
  48. package/cli/cobolx-cli/src/commands/build.ts +74 -0
  49. package/cli/cobolx-cli/src/commands/check.ts +24 -0
  50. package/cli/cobolx-cli/src/commands/debug.ts +15 -0
  51. package/cli/cobolx-cli/src/commands/debug_rewind.ts +16 -0
  52. package/cli/cobolx-cli/src/commands/deploy.ts +18 -0
  53. package/cli/cobolx-cli/src/commands/dev.ts +24 -0
  54. package/cli/cobolx-cli/src/commands/doc.ts +19 -0
  55. package/cli/cobolx-cli/src/commands/fmt.ts +14 -0
  56. package/cli/cobolx-cli/src/commands/fuzz.ts +24 -0
  57. package/cli/cobolx-cli/src/commands/generate.ts +38 -0
  58. package/cli/cobolx-cli/src/commands/install.ts +25 -0
  59. package/cli/cobolx-cli/src/commands/legacy.ts +17 -0
  60. package/cli/cobolx-cli/src/commands/lint.ts +17 -0
  61. package/cli/cobolx-cli/src/commands/migrate.ts +27 -0
  62. package/cli/cobolx-cli/src/commands/new.ts +20 -0
  63. package/cli/cobolx-cli/src/commands/profile.ts +8 -0
  64. package/cli/cobolx-cli/src/commands/publish.ts +16 -0
  65. package/cli/cobolx-cli/src/commands/repl.ts +30 -0
  66. package/cli/cobolx-cli/src/commands/run.ts +22 -0
  67. package/cli/cobolx-cli/src/commands/task.ts +27 -0
  68. package/cli/cobolx-cli/src/commands/test.ts +44 -0
  69. package/cli/cobolx-cli/src/commands/update.ts +30 -0
  70. package/cli/cobolx-cli/src/commands/visualize.ts +25 -0
  71. package/cli/cobolx-cli/src/index.ts +101 -0
  72. package/cli/cobolx-cli/src/project.ts +74 -0
  73. package/cli/cobolx-cli/tsconfig.json +7 -0
  74. package/cobolx.toml +7 -0
  75. package/compiler/package.json +14 -0
  76. package/compiler/src/ast/types.d.ts +87 -0
  77. package/compiler/src/ast/types.js +2 -0
  78. package/compiler/src/ast/types.js.map +1 -0
  79. package/compiler/src/ast/types.ts +329 -0
  80. package/compiler/src/backend/custom.d.ts +8 -0
  81. package/compiler/src/backend/custom.js +12 -0
  82. package/compiler/src/backend/custom.js.map +1 -0
  83. package/compiler/src/backend/custom.ts +21 -0
  84. package/compiler/src/borrow_checker/checker.d.ts +3 -0
  85. package/compiler/src/borrow_checker/checker.js +82 -0
  86. package/compiler/src/borrow_checker/checker.js.map +1 -0
  87. package/compiler/src/borrow_checker/checker.ts +100 -0
  88. package/compiler/src/codegen/javascript.d.ts +2 -0
  89. package/compiler/src/codegen/javascript.js +89 -0
  90. package/compiler/src/codegen/javascript.js.map +1 -0
  91. package/compiler/src/codegen/javascript.ts +175 -0
  92. package/compiler/src/const_eval/evaluator.ts +58 -0
  93. package/compiler/src/diagnostics.d.ts +11 -0
  94. package/compiler/src/diagnostics.js +14 -0
  95. package/compiler/src/diagnostics.js.map +1 -0
  96. package/compiler/src/diagnostics.ts +20 -0
  97. package/compiler/src/hir/lower.d.ts +7 -0
  98. package/compiler/src/hir/lower.js +44 -0
  99. package/compiler/src/hir/lower.js.map +1 -0
  100. package/compiler/src/hir/lower.ts +60 -0
  101. package/compiler/src/hir/types.d.ts +21 -0
  102. package/compiler/src/hir/types.js +2 -0
  103. package/compiler/src/hir/types.js.map +1 -0
  104. package/compiler/src/hir/types.ts +26 -0
  105. package/compiler/src/index.d.ts +22 -0
  106. package/compiler/src/index.js +84 -0
  107. package/compiler/src/index.js.map +1 -0
  108. package/compiler/src/index.ts +122 -0
  109. package/compiler/src/lexer/lexer.d.ts +21 -0
  110. package/compiler/src/lexer/lexer.js +207 -0
  111. package/compiler/src/lexer/lexer.js.map +1 -0
  112. package/compiler/src/lexer/lexer.ts +274 -0
  113. package/compiler/src/lexer/tokens.d.ts +8 -0
  114. package/compiler/src/lexer/tokens.js +18 -0
  115. package/compiler/src/lexer/tokens.js.map +1 -0
  116. package/compiler/src/lexer/tokens.ts +126 -0
  117. package/compiler/src/macros/expand.ts +75 -0
  118. package/compiler/src/main.ts +4 -0
  119. package/compiler/src/mir/lower.d.ts +3 -0
  120. package/compiler/src/mir/lower.js +10 -0
  121. package/compiler/src/mir/lower.js.map +1 -0
  122. package/compiler/src/mir/lower.ts +12 -0
  123. package/compiler/src/mir/types.d.ts +13 -0
  124. package/compiler/src/mir/types.js +2 -0
  125. package/compiler/src/mir/types.js.map +1 -0
  126. package/compiler/src/mir/types.ts +16 -0
  127. package/compiler/src/optimizer/constantFold.d.ts +2 -0
  128. package/compiler/src/optimizer/constantFold.js +61 -0
  129. package/compiler/src/optimizer/constantFold.js.map +1 -0
  130. package/compiler/src/optimizer/constantFold.ts +109 -0
  131. package/compiler/src/parser/parser.d.ts +33 -0
  132. package/compiler/src/parser/parser.js +323 -0
  133. package/compiler/src/parser/parser.js.map +1 -0
  134. package/compiler/src/parser/parser.ts +710 -0
  135. package/compiler/src/plugins/api.ts +8 -0
  136. package/compiler/src/plugins/loader.ts +21 -0
  137. package/compiler/src/semantic/analyzer.d.ts +12 -0
  138. package/compiler/src/semantic/analyzer.js +144 -0
  139. package/compiler/src/semantic/analyzer.js.map +1 -0
  140. package/compiler/src/semantic/analyzer.ts +277 -0
  141. package/compiler/src/type_system/checker.d.ts +7 -0
  142. package/compiler/src/type_system/checker.js +84 -0
  143. package/compiler/src/type_system/checker.js.map +1 -0
  144. package/compiler/src/type_system/checker.ts +108 -0
  145. package/compiler/tsconfig.json +7 -0
  146. package/debugger/package.json +11 -0
  147. package/debugger/src/index.d.ts +1 -0
  148. package/debugger/src/index.js +9 -0
  149. package/debugger/src/index.js.map +1 -0
  150. package/debugger/src/index.ts +9 -0
  151. package/debugger/tsconfig.json +7 -0
  152. package/docs/CHANGELOG.md +11 -0
  153. package/docs/CONTRIBUTING.md +15 -0
  154. package/docs/LICENSE +21 -0
  155. package/docs/architecture.md +29 -0
  156. package/docs/cli.md +58 -0
  157. package/docs/language-spec.md +49 -0
  158. package/docs/packages.md +19 -0
  159. package/docs/platform-systems.md +31 -0
  160. package/docs/release-validation.md +22 -0
  161. package/docs/runtime.md +10 -0
  162. package/docs/tooling.md +17 -0
  163. package/docs/vscode-extension.md +40 -0
  164. package/enterprise-demo/CargoX.lock +2 -0
  165. package/enterprise-demo/README.md +3 -0
  166. package/enterprise-demo/benchmarks/arith.cbx +6 -0
  167. package/enterprise-demo/cobolx.toml +7 -0
  168. package/enterprise-demo/src/main.cbx +5 -0
  169. package/enterprise-demo/tests/smoke.cbx +6 -0
  170. package/examples/README.md +20 -0
  171. package/examples/actors-and-flags.md +8 -0
  172. package/examples/api-server/README.md +9 -0
  173. package/examples/api-server/cobolx.toml +6 -0
  174. package/examples/api-server/src/main.cbx +8 -0
  175. package/examples/debug-replay.md +7 -0
  176. package/examples/debugging-demo/README.md +3 -0
  177. package/examples/debugging-demo/cobolx.toml +6 -0
  178. package/examples/debugging-demo/src/main.cbx +7 -0
  179. package/examples/distributed-service.md +12 -0
  180. package/examples/distributed-system/README.md +3 -0
  181. package/examples/distributed-system/cobolx.toml +6 -0
  182. package/examples/distributed-system/generated/deploy.json +12 -0
  183. package/examples/distributed-system/src/main.cbx +6 -0
  184. package/examples/event-driven.md +5 -0
  185. package/examples/event-system/README.md +3 -0
  186. package/examples/event-system/cobolx.toml +6 -0
  187. package/examples/event-system/src/main.cbx +11 -0
  188. package/examples/functions.cbx +10 -0
  189. package/examples/functions.mjs +12 -0
  190. package/examples/hello.cbx +5 -0
  191. package/examples/hello.mjs +7 -0
  192. package/examples/legacy-sample.cob +5 -0
  193. package/examples/parallel-processing/README.md +3 -0
  194. package/examples/parallel-processing/cobolx.toml +6 -0
  195. package/examples/parallel-processing/src/main.cbx +6 -0
  196. package/examples/parallel-processing.md +8 -0
  197. package/examples/platform-features.cbx +32 -0
  198. package/examples/platform-features.mjs +35 -0
  199. package/examples/service.cbx +10 -0
  200. package/examples/workflow-engine/README.md +3 -0
  201. package/examples/workflow-engine/cobolx.toml +6 -0
  202. package/examples/workflow-engine/generated/flowchart.mmd +8 -0
  203. package/examples/workflow-engine/src/main.cbx +13 -0
  204. package/examples/workflow-engine.md +5 -0
  205. package/formatter/package.json +14 -0
  206. package/formatter/src/index.d.ts +1 -0
  207. package/formatter/src/index.js +59 -0
  208. package/formatter/src/index.js.map +1 -0
  209. package/formatter/src/index.ts +103 -0
  210. package/formatter/tsconfig.json +7 -0
  211. package/generated/LEGACYDEMO.cbx +5 -0
  212. package/install.ps1 +4 -0
  213. package/install.sh +5 -0
  214. package/linter/package.json +14 -0
  215. package/linter/src/index.d.ts +2 -0
  216. package/linter/src/index.js +18 -0
  217. package/linter/src/index.js.map +1 -0
  218. package/linter/src/index.ts +19 -0
  219. package/linter/tsconfig.json +7 -0
  220. package/lsp/server/package.json +16 -0
  221. package/lsp/server/src/index.ts +168 -0
  222. package/lsp/server/tsconfig.json +7 -0
  223. package/package.json +30 -0
  224. package/profiler/package.json +11 -0
  225. package/profiler/src/index.d.ts +5 -0
  226. package/profiler/src/index.js +11 -0
  227. package/profiler/src/index.js.map +1 -0
  228. package/profiler/src/index.ts +11 -0
  229. package/profiler/tsconfig.json +7 -0
  230. package/release.json +10 -0
  231. package/runtime/package.json +14 -0
  232. package/runtime/src/actors/index.ts +27 -0
  233. package/runtime/src/async/futures.ts +11 -0
  234. package/runtime/src/code_as_data/index.ts +5 -0
  235. package/runtime/src/config/index.ts +17 -0
  236. package/runtime/src/distributed/index.ts +13 -0
  237. package/runtime/src/events/index.ts +21 -0
  238. package/runtime/src/feature_flags/index.ts +9 -0
  239. package/runtime/src/gc_or_arc/index.ts +1 -0
  240. package/runtime/src/healing/index.ts +26 -0
  241. package/runtime/src/index.ts +20 -0
  242. package/runtime/src/intents/index.ts +9 -0
  243. package/runtime/src/iterators/index.ts +23 -0
  244. package/runtime/src/memory/arc.ts +22 -0
  245. package/runtime/src/observability/index.ts +23 -0
  246. package/runtime/src/repl/context.ts +7 -0
  247. package/runtime/src/scheduler/taskScheduler.ts +11 -0
  248. package/runtime/src/security/capabilities.ts +15 -0
  249. package/runtime/src/security/secrets.ts +13 -0
  250. package/runtime/src/state/versioned.ts +31 -0
  251. package/runtime/src/std_hooks/audit.ts +23 -0
  252. package/runtime/src/time_travel/index.ts +54 -0
  253. package/runtime/src/workflows/index.ts +35 -0
  254. package/runtime/tsconfig.json +7 -0
  255. package/sample-payroll/README.md +3 -0
  256. package/sample-payroll/cobolx.toml +3 -0
  257. package/sample-payroll/src/main.cbx +5 -0
  258. package/stdlib/business/index.js +15 -0
  259. package/stdlib/core/README.md +8 -0
  260. package/stdlib/core/runtime.js +191 -0
  261. package/stdlib/crypto/index.js +5 -0
  262. package/stdlib/datetime/index.js +3 -0
  263. package/stdlib/fs/index.js +9 -0
  264. package/stdlib/http/index.js +7 -0
  265. package/stdlib/io/index.js +1 -0
  266. package/stdlib/json/index.js +7 -0
  267. package/stdlib/net/index.js +4 -0
  268. package/tests/macros.cbx +10 -0
  269. package/tests/pattern_match.cbx +16 -0
  270. package/tests/smoke.cbx +7 -0
  271. package/tests/validate-release.mjs +54 -0
  272. package/tsconfig.base.json +24 -0
  273. package/vscode-extension/LICENSE +21 -0
  274. package/vscode-extension/README.md +47 -0
  275. package/vscode-extension/cobolx-1.2.0.vsix +0 -0
  276. package/vscode-extension/icon.png +0 -0
  277. package/vscode-extension/icon.svg +15 -0
  278. package/vscode-extension/language-configuration.json +17 -0
  279. package/vscode-extension/package.json +148 -0
  280. package/vscode-extension/snippets/cobolx.code-snippets +49 -0
  281. package/vscode-extension/src/extension.ts +283 -0
  282. package/vscode-extension/syntaxes/cobolx.tmLanguage.json +75 -0
  283. package/vscode-extension/tests/test.cbl +3 -0
  284. package/vscode-extension/tsconfig.json +7 -0
@@ -0,0 +1,148 @@
1
+ {
2
+ "name": "cobolx",
3
+ "displayName": "COBOL-X",
4
+ "description": "Language support, commands, and LSP integration for the COBOL-X programming language.",
5
+ "version": "1.2.0",
6
+ "publisher": "magnificent-language",
7
+ "engines": {
8
+ "vscode": "^1.90.0"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/Magnexis/cobolx.git"
13
+ },
14
+ "homepage": "https://github.com/Magnexis/cobolx#readme",
15
+ "bugs": {
16
+ "url": "https://github.com/Magnexis/cobolx/issues"
17
+ },
18
+ "license": "MIT",
19
+ "icon": "icon.png",
20
+ "files": [
21
+ "dist",
22
+ "syntaxes",
23
+ "snippets",
24
+ "language-configuration.json",
25
+ "icon.png",
26
+ "icon.svg",
27
+ "README.md",
28
+ "LICENSE"
29
+ ],
30
+ "keywords": [
31
+ "cobolx",
32
+ "cobol",
33
+ "language",
34
+ "lsp",
35
+ "enterprise"
36
+ ],
37
+ "categories": [
38
+ "Programming Languages",
39
+ "Debuggers"
40
+ ],
41
+ "extensionKind": [
42
+ "workspace"
43
+ ],
44
+ "activationEvents": [
45
+ "onLanguage:cobolx",
46
+ "onCommand:cobolx.runFile",
47
+ "onCommand:cobolx.buildProject",
48
+ "onCommand:cobolx.openRepl",
49
+ "onCommand:cobolx.debugFile"
50
+ ],
51
+ "main": "./dist/extension.js",
52
+ "contributes": {
53
+ "languages": [
54
+ {
55
+ "id": "cobolx",
56
+ "aliases": [
57
+ "COBOL-X",
58
+ "COBOLX",
59
+ "cobolx"
60
+ ],
61
+ "extensions": [
62
+ ".cbx",
63
+ ".cob",
64
+ ".col"
65
+ ],
66
+ "configuration": "./language-configuration.json"
67
+ }
68
+ ],
69
+ "grammars": [
70
+ {
71
+ "language": "cobolx",
72
+ "scopeName": "source.cobolx",
73
+ "path": "./syntaxes/cobolx.tmLanguage.json"
74
+ }
75
+ ],
76
+ "commands": [
77
+ {
78
+ "command": "cobolx.runFile",
79
+ "title": "COBOL-X: Run File",
80
+ "category": "COBOL-X"
81
+ },
82
+ {
83
+ "command": "cobolx.buildProject",
84
+ "title": "COBOL-X: Build Project",
85
+ "category": "COBOL-X"
86
+ },
87
+ {
88
+ "command": "cobolx.openRepl",
89
+ "title": "COBOL-X: Open REPL",
90
+ "category": "COBOL-X"
91
+ },
92
+ {
93
+ "command": "cobolx.debugFile",
94
+ "title": "COBOL-X: Debug Current Project",
95
+ "category": "COBOL-X"
96
+ }
97
+ ],
98
+ "menus": {
99
+ "editor/title": [
100
+ {
101
+ "command": "cobolx.runFile",
102
+ "when": "resourceLangId == cobolx",
103
+ "group": "navigation"
104
+ },
105
+ {
106
+ "command": "cobolx.debugFile",
107
+ "when": "resourceLangId == cobolx",
108
+ "group": "navigation"
109
+ }
110
+ ],
111
+ "commandPalette": [
112
+ {
113
+ "command": "cobolx.runFile",
114
+ "when": "editorLangId == cobolx"
115
+ },
116
+ {
117
+ "command": "cobolx.buildProject",
118
+ "when": "workspaceFolderCount > 0"
119
+ },
120
+ {
121
+ "command": "cobolx.openRepl"
122
+ },
123
+ {
124
+ "command": "cobolx.debugFile",
125
+ "when": "editorLangId == cobolx"
126
+ }
127
+ ]
128
+ },
129
+ "snippets": [
130
+ {
131
+ "language": "cobolx",
132
+ "path": "./snippets/cobolx.code-snippets"
133
+ }
134
+ ]
135
+ },
136
+ "scripts": {
137
+ "build": "tsc -p tsconfig.json",
138
+ "check": "tsc -p tsconfig.json --noEmit",
139
+ "clean": "if (Test-Path dist) { Remove-Item -Recurse -Force dist }",
140
+ "package": "npx @vscode/vsce package --no-dependencies",
141
+ "publish:vsix": "npx @vscode/vsce publish --no-dependencies"
142
+ },
143
+ "dependencies": {},
144
+ "devDependencies": {
145
+ "@types/vscode": "^1.90.0",
146
+ "@vscode/vsce": "^3.6.2"
147
+ }
148
+ }
@@ -0,0 +1,49 @@
1
+ {
2
+ "Program": {
3
+ "prefix": "program",
4
+ "body": [
5
+ "PROGRAM ${1:Main}",
6
+ "",
7
+ "BEGIN",
8
+ "\t${2:DISPLAY \"Hello from COBOLX\"}",
9
+ "END"
10
+ ]
11
+ },
12
+ "If": {
13
+ "prefix": "if",
14
+ "body": [
15
+ "IF ${1:condition} THEN",
16
+ "\t${2:DISPLAY \"true\"}",
17
+ "ELSE",
18
+ "\t${3:DISPLAY \"false\"}",
19
+ "END-IF"
20
+ ]
21
+ },
22
+ "Function": {
23
+ "prefix": "function",
24
+ "body": [
25
+ "FUNCTION ${1:name}(${2:param})",
26
+ "BEGIN",
27
+ "\tRETURN ${3:param}",
28
+ "END-FUNCTION"
29
+ ]
30
+ },
31
+ "Match": {
32
+ "prefix": "match",
33
+ "body": [
34
+ "MATCH ${1:value}:",
35
+ "\t${2:OK(result)}:",
36
+ "\t\tDISPLAY ${3:result}",
37
+ "END-MATCH"
38
+ ]
39
+ },
40
+ "Enum": {
41
+ "prefix": "enum",
42
+ "body": [
43
+ "ENUM ${1:Result}:",
44
+ "\tOK(${2:value})",
45
+ "\tERR(${3:error})",
46
+ "END"
47
+ ]
48
+ }
49
+ }
@@ -0,0 +1,283 @@
1
+ import { exec } from "node:child_process";
2
+ import { promisify } from "node:util";
3
+ import path from "node:path";
4
+ import * as vscode from "vscode";
5
+
6
+ const execAsync = promisify(exec);
7
+ const COBOLX_SELECTOR: vscode.DocumentSelector = [{ scheme: "file", language: "cobolx" }];
8
+ const KEYWORDS = [
9
+ "PROGRAM",
10
+ "BEGIN",
11
+ "END",
12
+ "SET",
13
+ "LET",
14
+ "MUT",
15
+ "DISPLAY",
16
+ "INPUT",
17
+ "IF",
18
+ "THEN",
19
+ "ELSE",
20
+ "END-IF",
21
+ "FUNCTION",
22
+ "RETURN",
23
+ "END-FUNCTION",
24
+ "CONST",
25
+ "ENUM",
26
+ "MATCH",
27
+ "END-MATCH",
28
+ "MACRO",
29
+ "END-MACRO",
30
+ "ASYNC",
31
+ "SPAWN",
32
+ "ASSERT",
33
+ "UNSAFE",
34
+ "END-UNSAFE",
35
+ "TRUE",
36
+ "FALSE"
37
+ ];
38
+
39
+ const KEYWORD_DOCS: Record<string, string> = {
40
+ PROGRAM: "Declares the program name.",
41
+ BEGIN: "Starts an executable block.",
42
+ END: "Closes the program or enum block.",
43
+ SET: "Assigns a mutable variable.",
44
+ LET: "Introduces a local binding.",
45
+ MUT: "Marks a `LET` binding as mutable.",
46
+ DISPLAY: "Writes a value to standard output.",
47
+ INPUT: "Reads a value from standard input.",
48
+ IF: "Begins a conditional block.",
49
+ THEN: "Separates an IF condition from its body.",
50
+ ELSE: "Begins the fallback branch of an IF block.",
51
+ "END-IF": "Closes a conditional block.",
52
+ FUNCTION: "Declares a reusable function.",
53
+ RETURN: "Returns from a function.",
54
+ "END-FUNCTION": "Closes a function declaration.",
55
+ CONST: "Declares a compile-time constant.",
56
+ ENUM: "Declares tagged variants.",
57
+ MATCH: "Pattern matches over a value.",
58
+ "END-MATCH": "Closes a match block.",
59
+ MACRO: "Declares a compile-time macro.",
60
+ "END-MACRO": "Closes a macro declaration.",
61
+ ASYNC: "Marks a function as asynchronous.",
62
+ SPAWN: "Schedules a background task.",
63
+ ASSERT: "Checks a condition at runtime.",
64
+ UNSAFE: "Enters an explicitly unsafe block.",
65
+ "END-UNSAFE": "Closes an unsafe block.",
66
+ TRUE: "Boolean true literal.",
67
+ FALSE: "Boolean false literal."
68
+ };
69
+
70
+ let terminal: vscode.Terminal | undefined;
71
+
72
+ export async function activate(context: vscode.ExtensionContext): Promise<void> {
73
+ const diagnostics = vscode.languages.createDiagnosticCollection("cobolx");
74
+ context.subscriptions.push(
75
+ diagnostics,
76
+ registerDiagnostics(diagnostics),
77
+ registerCompletionProvider(),
78
+ registerHoverProvider(),
79
+ registerCommands()
80
+ );
81
+ }
82
+
83
+ export function deactivate(): void {
84
+ terminal?.dispose();
85
+ }
86
+
87
+ function registerDiagnostics(collection: vscode.DiagnosticCollection): vscode.Disposable {
88
+ const refresh = (document: vscode.TextDocument): void => {
89
+ if (document.languageId !== "cobolx") return;
90
+ collection.set(document.uri, computeDiagnostics(document));
91
+ };
92
+
93
+ vscode.workspace.textDocuments.forEach(refresh);
94
+
95
+ return vscode.Disposable.from(
96
+ vscode.workspace.onDidOpenTextDocument(refresh),
97
+ vscode.workspace.onDidChangeTextDocument((event) => refresh(event.document)),
98
+ vscode.workspace.onDidCloseTextDocument((document) => collection.delete(document.uri))
99
+ );
100
+ }
101
+
102
+ function computeDiagnostics(document: vscode.TextDocument): vscode.Diagnostic[] {
103
+ const diagnostics: vscode.Diagnostic[] = [];
104
+ const lines = document.getText().split(/\r?\n/);
105
+ const joined = lines.join("\n");
106
+
107
+ if (!/\bPROGRAM\b/.test(joined)) {
108
+ diagnostics.push(new vscode.Diagnostic(new vscode.Range(0, 0, 0, 1), "A COBOL-X file should start with a PROGRAM declaration.", vscode.DiagnosticSeverity.Error));
109
+ }
110
+
111
+ const beginCount = countToken(lines, "BEGIN");
112
+ const endCount = countToken(lines, "END");
113
+ if (beginCount > endCount) {
114
+ const line = Math.max(lines.length - 1, 0);
115
+ diagnostics.push(new vscode.Diagnostic(new vscode.Range(line, 0, line, Math.max(lines[line]?.length ?? 1, 1)), "Missing END for a BEGIN block.", vscode.DiagnosticSeverity.Error));
116
+ }
117
+
118
+ const ifCount = countToken(lines, "IF");
119
+ const endIfCount = countToken(lines, "END-IF");
120
+ if (ifCount > endIfCount) {
121
+ diagnostics.push(new vscode.Diagnostic(findTokenRange(lines, "IF"), "Missing END-IF for conditional block.", vscode.DiagnosticSeverity.Warning));
122
+ }
123
+
124
+ const matchCount = countToken(lines, "MATCH");
125
+ const endMatchCount = countToken(lines, "END-MATCH");
126
+ if (matchCount > endMatchCount) {
127
+ diagnostics.push(new vscode.Diagnostic(findTokenRange(lines, "MATCH"), "Missing END-MATCH for match block.", vscode.DiagnosticSeverity.Warning));
128
+ }
129
+
130
+ return diagnostics;
131
+ }
132
+
133
+ function countToken(lines: string[], token: string): number {
134
+ const pattern = new RegExp(`\\b${token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`, "g");
135
+ return lines.reduce((total, line) => total + (line.match(pattern)?.length ?? 0), 0);
136
+ }
137
+
138
+ function findTokenRange(lines: string[], token: string): vscode.Range {
139
+ const pattern = new RegExp(`\\b${token.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}\\b`);
140
+ for (let index = 0; index < lines.length; index += 1) {
141
+ const match = pattern.exec(lines[index] ?? "");
142
+ if (match?.index !== undefined) {
143
+ return new vscode.Range(index, match.index, index, match.index + token.length);
144
+ }
145
+ }
146
+ return new vscode.Range(0, 0, 0, 1);
147
+ }
148
+
149
+ function registerCompletionProvider(): vscode.Disposable {
150
+ return vscode.languages.registerCompletionItemProvider(
151
+ COBOLX_SELECTOR,
152
+ {
153
+ provideCompletionItems(): vscode.CompletionItem[] {
154
+ return KEYWORDS.map((keyword) => {
155
+ const item = new vscode.CompletionItem(keyword, vscode.CompletionItemKind.Keyword);
156
+ item.detail = "COBOL-X keyword";
157
+ item.documentation = new vscode.MarkdownString(KEYWORD_DOCS[keyword] ?? "COBOL-X keyword");
158
+ return item;
159
+ });
160
+ }
161
+ }
162
+ );
163
+ }
164
+
165
+ function registerHoverProvider(): vscode.Disposable {
166
+ return vscode.languages.registerHoverProvider(COBOLX_SELECTOR, {
167
+ provideHover(document, position) {
168
+ const range = document.getWordRangeAtPosition(position, /[A-Za-z_-][A-Za-z0-9_-]*/);
169
+ if (!range) return undefined;
170
+ const word = document.getText(range).toUpperCase();
171
+ const docs = KEYWORD_DOCS[word];
172
+ if (!docs) return undefined;
173
+ return new vscode.Hover(new vscode.MarkdownString(`**${word}**\n\n${docs}`), range);
174
+ }
175
+ });
176
+ }
177
+
178
+ function registerCommands(): vscode.Disposable {
179
+ return vscode.Disposable.from(
180
+ vscode.commands.registerCommand("cobolx.runFile", async () => {
181
+ const projectDir = await getProjectRoot();
182
+ if (!projectDir) return;
183
+ runInTerminal(projectDir, `${await resolveCobolxCommand(projectDir)} run`);
184
+ }),
185
+ vscode.commands.registerCommand("cobolx.buildProject", async () => {
186
+ const projectDir = await getProjectRoot();
187
+ if (!projectDir) return;
188
+ runInTerminal(projectDir, `${await resolveCobolxCommand(projectDir)} build`);
189
+ }),
190
+ vscode.commands.registerCommand("cobolx.openRepl", async () => {
191
+ const projectDir = await getProjectRoot();
192
+ if (!projectDir) return;
193
+ runInTerminal(projectDir, `${await resolveCobolxCommand(projectDir)} repl`);
194
+ }),
195
+ vscode.commands.registerCommand("cobolx.debugFile", async () => {
196
+ const projectDir = await getProjectRoot();
197
+ if (!projectDir) return;
198
+ const cobolxCommand = await resolveCobolxCommand(projectDir);
199
+
200
+ try {
201
+ await vscode.window.withProgress(
202
+ { location: vscode.ProgressLocation.Notification, title: "Building COBOL-X project for debugging" },
203
+ async () => {
204
+ await execAsync(`${cobolxCommand} build`, {
205
+ cwd: projectDir,
206
+ shell: process.platform === "win32" ? (process.env.ComSpec ?? "cmd.exe") : "/bin/sh"
207
+ });
208
+ }
209
+ );
210
+ } catch (error) {
211
+ void vscode.window.showErrorMessage(`COBOL-X build failed: ${String(error)}`);
212
+ return;
213
+ }
214
+
215
+ await vscode.debug.startDebugging(vscode.workspace.getWorkspaceFolder(vscode.Uri.file(projectDir)), {
216
+ type: "pwa-node",
217
+ request: "launch",
218
+ name: "Debug COBOL-X Project",
219
+ cwd: projectDir,
220
+ program: path.join(projectDir, "dist", "main.mjs"),
221
+ env: {
222
+ COBOLX_DEBUG_TRACE_FILE: path.join(projectDir, "dist", "debug-timeline.json")
223
+ }
224
+ });
225
+ })
226
+ );
227
+ }
228
+
229
+ async function getProjectRoot(): Promise<string | undefined> {
230
+ const activeUri = vscode.window.activeTextEditor?.document.uri;
231
+ const candidates = [
232
+ activeUri ? vscode.workspace.getWorkspaceFolder(activeUri)?.uri.fsPath : undefined,
233
+ vscode.workspace.workspaceFolders?.[0]?.uri.fsPath
234
+ ].filter((value): value is string => Boolean(value));
235
+
236
+ for (const candidate of candidates) {
237
+ const found = await findUp(candidate, "cobolx.toml");
238
+ if (found) return found;
239
+ }
240
+
241
+ void vscode.window.showErrorMessage("COBOL-X project root not found. Open a folder containing cobolx.toml.");
242
+ return undefined;
243
+ }
244
+
245
+ function runInTerminal(projectDir: string, command: string): void {
246
+ if (!terminal || terminal.exitStatus) {
247
+ terminal = vscode.window.createTerminal({
248
+ name: "COBOL-X",
249
+ cwd: projectDir
250
+ });
251
+ }
252
+ terminal.show(true);
253
+ terminal.sendText(command, true);
254
+ }
255
+
256
+ async function resolveCobolxCommand(projectDir: string): Promise<string> {
257
+ const localRepoRoot = await findUp(projectDir, "package.json");
258
+ if (localRepoRoot) {
259
+ const localCli = path.join(localRepoRoot, "cli", "cobolx-cli", "dist", "index.js");
260
+ try {
261
+ await vscode.workspace.fs.stat(vscode.Uri.file(localCli));
262
+ return `node "${localCli}"`;
263
+ } catch {
264
+ // Fall through to the globally installed CLI.
265
+ }
266
+ }
267
+ return "cobolx";
268
+ }
269
+
270
+ async function findUp(startDir: string, marker: string): Promise<string | undefined> {
271
+ let current = startDir;
272
+ while (true) {
273
+ const candidate = path.join(current, marker);
274
+ try {
275
+ await vscode.workspace.fs.stat(vscode.Uri.file(candidate));
276
+ return current;
277
+ } catch {
278
+ const parent = path.dirname(current);
279
+ if (parent === current) return undefined;
280
+ current = parent;
281
+ }
282
+ }
283
+ }
@@ -0,0 +1,75 @@
1
+ {
2
+ "scopeName": "source.cobolx",
3
+ "name": "COBOLX",
4
+ "patterns": [
5
+ {
6
+ "include": "#keywords"
7
+ },
8
+ {
9
+ "include": "#types"
10
+ },
11
+ {
12
+ "include": "#functions"
13
+ },
14
+ {
15
+ "include": "#strings"
16
+ },
17
+ {
18
+ "include": "#numbers"
19
+ },
20
+ {
21
+ "include": "#comments"
22
+ }
23
+ ],
24
+ "repository": {
25
+ "keywords": {
26
+ "patterns": [
27
+ {
28
+ "name": "keyword.control.cobolx",
29
+ "match": "\\b(PROGRAM|BEGIN|END|SET|LET|MUT|DISPLAY|INPUT|IF|THEN|ELSE|END-IF|FUNCTION|RETURN|END-FUNCTION|CONST|ENUM|TRAIT|IMPL|MODULE|EXPORT|IMPORT|FROM|AS|MATCH|END-MATCH|MACRO|END-MACRO|PLUGIN|TEST|END-TEST|ASYNC|SPAWN|ASSERT|UNSAFE|END-UNSAFE|TRUE|FALSE)\\b"
30
+ }
31
+ ]
32
+ },
33
+ "types": {
34
+ "patterns": [
35
+ {
36
+ "name": "storage.type.cobolx",
37
+ "match": "\\b(STRING|INT|DECIMAL|BOOL|Result|Option)\\b"
38
+ }
39
+ ]
40
+ },
41
+ "functions": {
42
+ "patterns": [
43
+ {
44
+ "name": "entity.name.function.cobolx",
45
+ "match": "\\b([A-Za-z_][A-Za-z0-9_]*)\\s*(?=\\()"
46
+ }
47
+ ]
48
+ },
49
+ "strings": {
50
+ "patterns": [
51
+ {
52
+ "name": "string.quoted.double.cobolx",
53
+ "begin": "\"",
54
+ "end": "\""
55
+ }
56
+ ]
57
+ },
58
+ "numbers": {
59
+ "patterns": [
60
+ {
61
+ "name": "constant.numeric.cobolx",
62
+ "match": "\\b\\d+(?:\\.\\d+)?\\b"
63
+ }
64
+ ]
65
+ },
66
+ "comments": {
67
+ "patterns": [
68
+ {
69
+ "name": "comment.line.cobolx",
70
+ "match": "(\\*>|///).*$"
71
+ }
72
+ ]
73
+ }
74
+ }
75
+ }
@@ -0,0 +1,3 @@
1
+ FUNCTION test():
2
+ RETURN "hello"
3
+ END
@@ -0,0 +1,7 @@
1
+ {
2
+ "extends": "../tsconfig.base.json",
3
+ "compilerOptions": {
4
+ "outDir": "dist"
5
+ },
6
+ "include": ["src/**/*.ts"]
7
+ }