funkscript 0.2.4 → 0.2.7

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 (447) hide show
  1. package/README.md +23 -5
  2. package/dist/ast/types.d.ts.map +1 -1
  3. package/dist/ast/types.js.map +1 -1
  4. package/dist/ast/walk.d.ts.map +1 -1
  5. package/dist/ast/walk.js.map +1 -1
  6. package/dist/cli/build-bun.d.ts.map +1 -1
  7. package/dist/cli/build-bun.js.map +1 -1
  8. package/dist/cli/build-watch.d.ts.map +1 -1
  9. package/dist/cli/build-watch.js +9 -27
  10. package/dist/cli/build-watch.js.map +1 -1
  11. package/dist/cli/build.d.ts +1 -1
  12. package/dist/cli/build.d.ts.map +1 -1
  13. package/dist/cli/build.js +3 -58
  14. package/dist/cli/build.js.map +1 -1
  15. package/dist/cli/check-policy.d.ts +9 -0
  16. package/dist/cli/check-policy.d.ts.map +1 -0
  17. package/dist/cli/check-policy.js +39 -0
  18. package/dist/cli/check-policy.js.map +1 -0
  19. package/dist/cli/check.d.ts.map +1 -1
  20. package/dist/cli/check.js +16 -30
  21. package/dist/cli/check.js.map +1 -1
  22. package/dist/cli/commands.d.ts.map +1 -1
  23. package/dist/cli/commands.js +11 -0
  24. package/dist/cli/commands.js.map +1 -1
  25. package/dist/cli/doc.d.ts.map +1 -1
  26. package/dist/cli/doc.js.map +1 -1
  27. package/dist/cli/doctor.d.ts.map +1 -1
  28. package/dist/cli/doctor.js +5 -7
  29. package/dist/cli/doctor.js.map +1 -1
  30. package/dist/cli/emit.d.ts +1 -1
  31. package/dist/cli/emit.d.ts.map +1 -1
  32. package/dist/cli/emit.js.map +1 -1
  33. package/dist/cli/explain.d.ts.map +1 -1
  34. package/dist/cli/explain.js.map +1 -1
  35. package/dist/cli/fmt.d.ts.map +1 -1
  36. package/dist/cli/fmt.js.map +1 -1
  37. package/dist/cli/index.d.ts.map +1 -1
  38. package/dist/cli/index.js +3 -0
  39. package/dist/cli/index.js.map +1 -1
  40. package/dist/cli/init.d.ts +1 -1
  41. package/dist/cli/init.d.ts.map +1 -1
  42. package/dist/cli/init.js +66 -21
  43. package/dist/cli/init.js.map +1 -1
  44. package/dist/cli/io.d.ts.map +1 -1
  45. package/dist/cli/io.js.map +1 -1
  46. package/dist/cli/pipeline-style.d.ts.map +1 -1
  47. package/dist/cli/pipeline-style.js.map +1 -1
  48. package/dist/cli/query.d.ts +3 -0
  49. package/dist/cli/query.d.ts.map +1 -0
  50. package/dist/cli/query.js +152 -0
  51. package/dist/cli/query.js.map +1 -0
  52. package/dist/cli/repl.d.ts.map +1 -1
  53. package/dist/cli/repl.js.map +1 -1
  54. package/dist/cli/run.d.ts.map +1 -1
  55. package/dist/cli/run.js +2 -29
  56. package/dist/cli/run.js.map +1 -1
  57. package/dist/cli/test.d.ts +1 -1
  58. package/dist/cli/test.d.ts.map +1 -1
  59. package/dist/cli/test.js.map +1 -1
  60. package/dist/cli/tsc.d.ts.map +1 -1
  61. package/dist/cli/tsc.js +6 -8
  62. package/dist/cli/tsc.js.map +1 -1
  63. package/dist/cli/typecheck.d.ts.map +1 -1
  64. package/dist/cli/typecheck.js.map +1 -1
  65. package/dist/compiler/ast-inspection.d.ts.map +1 -1
  66. package/dist/compiler/ast-inspection.js.map +1 -1
  67. package/dist/compiler/boolean-operators.d.ts.map +1 -1
  68. package/dist/compiler/boolean-operators.js +12 -2
  69. package/dist/compiler/boolean-operators.js.map +1 -1
  70. package/dist/compiler/check.d.ts.map +1 -1
  71. package/dist/compiler/check.js +113 -131
  72. package/dist/compiler/check.js.map +1 -1
  73. package/dist/compiler/diagnostics-json.d.ts +73 -0
  74. package/dist/compiler/diagnostics-json.d.ts.map +1 -0
  75. package/dist/compiler/diagnostics-json.js +957 -0
  76. package/dist/compiler/diagnostics-json.js.map +1 -0
  77. package/dist/compiler/diagnostics.d.ts.map +1 -1
  78. package/dist/compiler/diagnostics.js.map +1 -1
  79. package/dist/compiler/effect-mutation-rule.d.ts.map +1 -1
  80. package/dist/compiler/effect-mutation-rule.js.map +1 -1
  81. package/dist/compiler/entry-rules.d.ts.map +1 -1
  82. package/dist/compiler/entry-rules.js.map +1 -1
  83. package/dist/compiler/escape-audit.d.ts +46 -0
  84. package/dist/compiler/escape-audit.d.ts.map +1 -0
  85. package/dist/compiler/escape-audit.js +682 -0
  86. package/dist/compiler/escape-audit.js.map +1 -0
  87. package/dist/compiler/incremental-build.d.ts.map +1 -1
  88. package/dist/compiler/incremental-build.js.map +1 -1
  89. package/dist/compiler/incremental-dependencies.d.ts.map +1 -1
  90. package/dist/compiler/incremental-dependencies.js.map +1 -1
  91. package/dist/compiler/js-interop-nullability.d.ts.map +1 -1
  92. package/dist/compiler/js-interop-nullability.js.map +1 -1
  93. package/dist/compiler/modules/output-collisions.d.ts.map +1 -1
  94. package/dist/compiler/modules/output-collisions.js.map +1 -1
  95. package/dist/compiler/modules/output-plan.d.ts.map +1 -1
  96. package/dist/compiler/modules/output-plan.js +10 -5
  97. package/dist/compiler/modules/output-plan.js.map +1 -1
  98. package/dist/compiler/modules/resolution.d.ts.map +1 -1
  99. package/dist/compiler/modules/resolution.js +2 -1
  100. package/dist/compiler/modules/resolution.js.map +1 -1
  101. package/dist/compiler/modules/source-files.d.ts +5 -0
  102. package/dist/compiler/modules/source-files.d.ts.map +1 -0
  103. package/dist/compiler/modules/source-files.js +13 -0
  104. package/dist/compiler/modules/source-files.js.map +1 -0
  105. package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
  106. package/dist/compiler/numeric-comparisons.js +13 -7
  107. package/dist/compiler/numeric-comparisons.js.map +1 -1
  108. package/dist/compiler/optional-arguments.d.ts.map +1 -1
  109. package/dist/compiler/optional-arguments.js.map +1 -1
  110. package/dist/compiler/package-fingerprint.d.ts.map +1 -1
  111. package/dist/compiler/package-fingerprint.js.map +1 -1
  112. package/dist/compiler/package-record-contracts.d.ts.map +1 -1
  113. package/dist/compiler/package-record-contracts.js.map +1 -1
  114. package/dist/compiler/pipelines/catalog.d.ts.map +1 -1
  115. package/dist/compiler/pipelines/catalog.js.map +1 -1
  116. package/dist/compiler/pipelines/companions.d.ts.map +1 -1
  117. package/dist/compiler/pipelines/companions.js.map +1 -1
  118. package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
  119. package/dist/compiler/pipelines/resolution.js +24 -23
  120. package/dist/compiler/pipelines/resolution.js.map +1 -1
  121. package/dist/compiler/project-config.d.ts.map +1 -1
  122. package/dist/compiler/project-config.js +29 -19
  123. package/dist/compiler/project-config.js.map +1 -1
  124. package/dist/compiler/query.d.ts +53 -0
  125. package/dist/compiler/query.d.ts.map +1 -0
  126. package/dist/compiler/query.js +781 -0
  127. package/dist/compiler/query.js.map +1 -0
  128. package/dist/compiler/record-contracts.d.ts.map +1 -1
  129. package/dist/compiler/record-contracts.js.map +1 -1
  130. package/dist/compiler/rules/control-flow.d.ts.map +1 -1
  131. package/dist/compiler/rules/control-flow.js.map +1 -1
  132. package/dist/compiler/rules/diagnostic.d.ts.map +1 -1
  133. package/dist/compiler/rules/diagnostic.js.map +1 -1
  134. package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -1
  135. package/dist/compiler/rules/module-scope-refs.js.map +1 -1
  136. package/dist/compiler/rules/resource-escape.d.ts +7 -0
  137. package/dist/compiler/rules/resource-escape.d.ts.map +1 -0
  138. package/dist/compiler/rules/resource-escape.js +146 -0
  139. package/dist/compiler/rules/resource-escape.js.map +1 -0
  140. package/dist/compiler/rules/resource-providers.d.ts +19 -0
  141. package/dist/compiler/rules/resource-providers.d.ts.map +1 -0
  142. package/dist/compiler/rules/resource-providers.js +222 -0
  143. package/dist/compiler/rules/resource-providers.js.map +1 -0
  144. package/dist/compiler/schemas/analysis.d.ts.map +1 -1
  145. package/dist/compiler/schemas/analysis.js.map +1 -1
  146. package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -1
  147. package/dist/compiler/schemas/imported-record-functions.js.map +1 -1
  148. package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -1
  149. package/dist/compiler/schemas/imported-schemas.js.map +1 -1
  150. package/dist/compiler/source-map.d.ts.map +1 -1
  151. package/dist/compiler/source-map.js +2 -7
  152. package/dist/compiler/source-map.js.map +1 -1
  153. package/dist/compiler/type-view-paths.d.ts +6 -0
  154. package/dist/compiler/type-view-paths.d.ts.map +1 -0
  155. package/dist/compiler/type-view-paths.js +12 -0
  156. package/dist/compiler/type-view-paths.js.map +1 -0
  157. package/dist/compiler/typescript-context.d.ts.map +1 -1
  158. package/dist/compiler/typescript-context.js +5 -7
  159. package/dist/compiler/typescript-context.js.map +1 -1
  160. package/dist/compiler.d.ts.map +1 -1
  161. package/dist/compiler.js.map +1 -1
  162. package/dist/emitter/assemblyscript.d.ts.map +1 -1
  163. package/dist/emitter/assemblyscript.js +120 -136
  164. package/dist/emitter/assemblyscript.js.map +1 -1
  165. package/dist/emitter/declarations.d.ts.map +1 -1
  166. package/dist/emitter/declarations.js.map +1 -1
  167. package/dist/emitter/emitter.d.ts +3 -1
  168. package/dist/emitter/emitter.d.ts.map +1 -1
  169. package/dist/emitter/emitter.js +10 -1
  170. package/dist/emitter/emitter.js.map +1 -1
  171. package/dist/emitter/imports.d.ts.map +1 -1
  172. package/dist/emitter/imports.js.map +1 -1
  173. package/dist/emitter/indent.d.ts.map +1 -1
  174. package/dist/emitter/indent.js.map +1 -1
  175. package/dist/emitter/jsx.d.ts.map +1 -1
  176. package/dist/emitter/jsx.js.map +1 -1
  177. package/dist/emitter/local-bindings.d.ts.map +1 -1
  178. package/dist/emitter/local-bindings.js.map +1 -1
  179. package/dist/emitter/match.d.ts.map +1 -1
  180. package/dist/emitter/match.js.map +1 -1
  181. package/dist/emitter/runtime-helpers.d.ts.map +1 -1
  182. package/dist/emitter/runtime-helpers.js.map +1 -1
  183. package/dist/emitter/schemas.d.ts.map +1 -1
  184. package/dist/emitter/schemas.js.map +1 -1
  185. package/dist/emitter/statements.d.ts +1 -0
  186. package/dist/emitter/statements.d.ts.map +1 -1
  187. package/dist/emitter/statements.js +1 -0
  188. package/dist/emitter/statements.js.map +1 -1
  189. package/dist/emitter/tagged-match.d.ts.map +1 -1
  190. package/dist/emitter/tagged-match.js.map +1 -1
  191. package/dist/emitter/types.d.ts.map +1 -1
  192. package/dist/emitter/types.js.map +1 -1
  193. package/dist/errors.d.ts.map +1 -1
  194. package/dist/errors.js.map +1 -1
  195. package/dist/formatter/comments.d.ts.map +1 -1
  196. package/dist/formatter/comments.js +13 -0
  197. package/dist/formatter/comments.js.map +1 -1
  198. package/dist/formatter/index.d.ts +9 -0
  199. package/dist/formatter/index.d.ts.map +1 -1
  200. package/dist/formatter/index.js +215 -5
  201. package/dist/formatter/index.js.map +1 -1
  202. package/dist/formatter/operator-precedence.d.ts.map +1 -1
  203. package/dist/formatter/operator-precedence.js.map +1 -1
  204. package/dist/formatter/prettier.d.ts.map +1 -1
  205. package/dist/formatter/prettier.js.map +1 -1
  206. package/dist/index.d.ts +3 -0
  207. package/dist/index.d.ts.map +1 -1
  208. package/dist/index.js +3 -0
  209. package/dist/index.js.map +1 -1
  210. package/dist/interop/callback.d.ts.map +1 -1
  211. package/dist/interop/callback.js.map +1 -1
  212. package/dist/interop/js.d.ts.map +1 -1
  213. package/dist/interop/js.js.map +1 -1
  214. package/dist/interop/record.d.ts.map +1 -1
  215. package/dist/interop/record.js.map +1 -1
  216. package/dist/interop/valibot.d.ts.map +1 -1
  217. package/dist/interop/valibot.js.map +1 -1
  218. package/dist/interop/zod.d.ts.map +1 -1
  219. package/dist/interop/zod.js.map +1 -1
  220. package/dist/lexer/lexer.d.ts +1 -0
  221. package/dist/lexer/lexer.d.ts.map +1 -1
  222. package/dist/lexer/lexer.js +26 -10
  223. package/dist/lexer/lexer.js.map +1 -1
  224. package/dist/lexer/tokens.d.ts.map +1 -1
  225. package/dist/lexer/tokens.js.map +1 -1
  226. package/dist/lsp/code-action-worker.d.ts.map +1 -1
  227. package/dist/lsp/code-action-worker.js.map +1 -1
  228. package/dist/lsp/completion.d.ts +25 -0
  229. package/dist/lsp/completion.d.ts.map +1 -1
  230. package/dist/lsp/completion.js +1114 -51
  231. package/dist/lsp/completion.js.map +1 -1
  232. package/dist/lsp/definition.d.ts +2 -0
  233. package/dist/lsp/definition.d.ts.map +1 -1
  234. package/dist/lsp/definition.js +52 -58
  235. package/dist/lsp/definition.js.map +1 -1
  236. package/dist/lsp/diagnostics-worker.d.ts.map +1 -1
  237. package/dist/lsp/diagnostics-worker.js +1 -1
  238. package/dist/lsp/diagnostics-worker.js.map +1 -1
  239. package/dist/lsp/docs.d.ts +1 -1
  240. package/dist/lsp/docs.d.ts.map +1 -1
  241. package/dist/lsp/docs.js +4 -3
  242. package/dist/lsp/docs.js.map +1 -1
  243. package/dist/lsp/error-channel.d.ts.map +1 -1
  244. package/dist/lsp/error-channel.js.map +1 -1
  245. package/dist/lsp/hover.d.ts +5 -1
  246. package/dist/lsp/hover.d.ts.map +1 -1
  247. package/dist/lsp/hover.js +1016 -46
  248. package/dist/lsp/hover.js.map +1 -1
  249. package/dist/lsp/imports.d.ts +2 -0
  250. package/dist/lsp/imports.d.ts.map +1 -1
  251. package/dist/lsp/imports.js +45 -21
  252. package/dist/lsp/imports.js.map +1 -1
  253. package/dist/lsp/index.d.ts.map +1 -1
  254. package/dist/lsp/index.js.map +1 -1
  255. package/dist/lsp/inlay-hints.d.ts.map +1 -1
  256. package/dist/lsp/inlay-hints.js.map +1 -1
  257. package/dist/lsp/interop-rename.d.ts.map +1 -1
  258. package/dist/lsp/interop-rename.js.map +1 -1
  259. package/dist/lsp/match-arms.d.ts.map +1 -1
  260. package/dist/lsp/match-arms.js.map +1 -1
  261. package/dist/lsp/navigation.d.ts +1 -1
  262. package/dist/lsp/navigation.d.ts.map +1 -1
  263. package/dist/lsp/navigation.js +30 -12
  264. package/dist/lsp/navigation.js.map +1 -1
  265. package/dist/lsp/parsed-documents.d.ts.map +1 -1
  266. package/dist/lsp/parsed-documents.js.map +1 -1
  267. package/dist/lsp/range-format.d.ts +4 -0
  268. package/dist/lsp/range-format.d.ts.map +1 -0
  269. package/dist/lsp/range-format.js +88 -0
  270. package/dist/lsp/range-format.js.map +1 -0
  271. package/dist/lsp/rename-worker.d.ts.map +1 -1
  272. package/dist/lsp/rename-worker.js.map +1 -1
  273. package/dist/lsp/schema-import-hover.d.ts +8 -0
  274. package/dist/lsp/schema-import-hover.d.ts.map +1 -0
  275. package/dist/lsp/schema-import-hover.js +52 -0
  276. package/dist/lsp/schema-import-hover.js.map +1 -0
  277. package/dist/lsp/server.d.ts +3 -1
  278. package/dist/lsp/server.d.ts.map +1 -1
  279. package/dist/lsp/server.js +73 -48
  280. package/dist/lsp/server.js.map +1 -1
  281. package/dist/lsp/signature-help.d.ts +6 -0
  282. package/dist/lsp/signature-help.d.ts.map +1 -0
  283. package/dist/lsp/signature-help.js +183 -0
  284. package/dist/lsp/signature-help.js.map +1 -0
  285. package/dist/lsp/thunk-pipeline.d.ts.map +1 -1
  286. package/dist/lsp/thunk-pipeline.js.map +1 -1
  287. package/dist/lsp/validation.d.ts.map +1 -1
  288. package/dist/lsp/validation.js +3 -2
  289. package/dist/lsp/validation.js.map +1 -1
  290. package/dist/lsp/workspace.d.ts +3 -1
  291. package/dist/lsp/workspace.d.ts.map +1 -1
  292. package/dist/lsp/workspace.js +66 -10
  293. package/dist/lsp/workspace.js.map +1 -1
  294. package/dist/parser/declarations.d.ts.map +1 -1
  295. package/dist/parser/declarations.js +22 -1
  296. package/dist/parser/declarations.js.map +1 -1
  297. package/dist/parser/errors.d.ts.map +1 -1
  298. package/dist/parser/errors.js.map +1 -1
  299. package/dist/parser/jsx.d.ts.map +1 -1
  300. package/dist/parser/jsx.js.map +1 -1
  301. package/dist/parser/operator-expressions.d.ts.map +1 -1
  302. package/dist/parser/operator-expressions.js.map +1 -1
  303. package/dist/parser/parser.d.ts.map +1 -1
  304. package/dist/parser/parser.js.map +1 -1
  305. package/dist/parser/patterns.d.ts.map +1 -1
  306. package/dist/parser/patterns.js.map +1 -1
  307. package/dist/parser/pipeline-expressions.d.ts.map +1 -1
  308. package/dist/parser/pipeline-expressions.js.map +1 -1
  309. package/dist/parser/scope.d.ts.map +1 -1
  310. package/dist/parser/scope.js.map +1 -1
  311. package/dist/parser/statements.d.ts.map +1 -1
  312. package/dist/parser/statements.js.map +1 -1
  313. package/dist/parser/types.d.ts.map +1 -1
  314. package/dist/parser/types.js.map +1 -1
  315. package/dist/plugins/bun-preload.d.ts.map +1 -1
  316. package/dist/plugins/bun-preload.js.map +1 -1
  317. package/dist/plugins/bun.d.ts +2 -18
  318. package/dist/plugins/bun.d.ts.map +1 -1
  319. package/dist/plugins/bun.js +5 -30
  320. package/dist/plugins/bun.js.map +1 -1
  321. package/dist/plugins/esbuild.d.ts +1 -1
  322. package/dist/plugins/esbuild.d.ts.map +1 -1
  323. package/dist/plugins/esbuild.js +10 -36
  324. package/dist/plugins/esbuild.js.map +1 -1
  325. package/dist/plugins/server-boundary.d.ts +14 -0
  326. package/dist/plugins/server-boundary.d.ts.map +1 -0
  327. package/dist/plugins/server-boundary.js +25 -0
  328. package/dist/plugins/server-boundary.js.map +1 -0
  329. package/dist/plugins/type-view.d.ts.map +1 -1
  330. package/dist/plugins/type-view.js +5 -3
  331. package/dist/plugins/type-view.js.map +1 -1
  332. package/dist/plugins/vite.d.ts +2 -18
  333. package/dist/plugins/vite.d.ts.map +1 -1
  334. package/dist/plugins/vite.js +4 -29
  335. package/dist/plugins/vite.js.map +1 -1
  336. package/dist/testing/index.d.ts.map +1 -1
  337. package/dist/testing/index.js.map +1 -1
  338. package/dist/tooling/doc.d.ts.map +1 -1
  339. package/dist/tooling/doc.js.map +1 -1
  340. package/dist/tooling/idiomatic.d.ts.map +1 -1
  341. package/dist/tooling/idiomatic.js.map +1 -1
  342. package/dist/tooling/pipeline-style.d.ts.map +1 -1
  343. package/dist/tooling/pipeline-style.js.map +1 -1
  344. package/dist/version.d.ts.map +1 -1
  345. package/dist/version.js.map +1 -1
  346. package/package.json +13 -6
  347. package/src/cli/build-watch.ts +10 -29
  348. package/src/cli/build.ts +9 -60
  349. package/src/cli/check-policy.ts +54 -0
  350. package/src/cli/check.ts +19 -31
  351. package/src/cli/commands.ts +13 -0
  352. package/src/cli/doctor.ts +10 -7
  353. package/src/cli/index.ts +3 -0
  354. package/src/cli/init.ts +66 -21
  355. package/src/cli/query.ts +191 -0
  356. package/src/cli/run.ts +5 -30
  357. package/src/cli/tsc.ts +10 -8
  358. package/src/compiler/boolean-operators.ts +11 -2
  359. package/src/compiler/check.ts +152 -180
  360. package/src/compiler/diagnostics-json.ts +1205 -0
  361. package/src/compiler/escape-audit.ts +913 -0
  362. package/src/compiler/modules/output-plan.ts +11 -9
  363. package/src/compiler/modules/resolution.ts +2 -1
  364. package/src/compiler/modules/source-files.ts +13 -0
  365. package/src/compiler/numeric-comparisons.ts +14 -8
  366. package/src/compiler/pipelines/resolution.ts +30 -26
  367. package/src/compiler/project-config.ts +30 -19
  368. package/src/compiler/query.ts +1177 -0
  369. package/src/compiler/rules/resource-escape.ts +223 -0
  370. package/src/compiler/rules/resource-providers.ts +293 -0
  371. package/src/compiler/source-map.ts +3 -7
  372. package/src/compiler/type-view-paths.ts +10 -0
  373. package/src/compiler/typescript-context.ts +6 -7
  374. package/src/emitter/assemblyscript.ts +101 -147
  375. package/src/emitter/emitter.ts +13 -1
  376. package/src/emitter/statements.ts +2 -0
  377. package/src/formatter/comments.ts +14 -0
  378. package/src/formatter/index.ts +299 -4
  379. package/src/index.ts +3 -0
  380. package/src/lexer/lexer.ts +39 -20
  381. package/src/lsp/completion.ts +1452 -66
  382. package/src/lsp/definition.ts +50 -58
  383. package/src/lsp/diagnostics-worker.ts +1 -4
  384. package/src/lsp/docs.ts +4 -3
  385. package/src/lsp/hover.ts +1465 -44
  386. package/src/lsp/imports.ts +75 -22
  387. package/src/lsp/navigation.ts +41 -22
  388. package/src/lsp/range-format.ts +102 -0
  389. package/src/lsp/schema-import-hover.ts +76 -0
  390. package/src/lsp/server.ts +99 -69
  391. package/src/lsp/signature-help.ts +226 -0
  392. package/src/lsp/validation.ts +3 -2
  393. package/src/lsp/workspace.ts +63 -9
  394. package/src/parser/declarations.ts +27 -1
  395. package/src/plugins/bun.ts +14 -66
  396. package/src/plugins/esbuild.ts +16 -55
  397. package/src/plugins/server-boundary.ts +41 -0
  398. package/src/plugins/type-view.ts +11 -3
  399. package/src/plugins/vite.ts +12 -62
  400. package/dist/Widget.tsx +0 -9
  401. package/dist/cli/output-collisions.d.ts +0 -2
  402. package/dist/cli/output-collisions.d.ts.map +0 -1
  403. package/dist/cli/output-collisions.js +0 -39
  404. package/dist/cli/output-collisions.js.map +0 -1
  405. package/dist/compiler/imported-record-functions.d.ts +0 -4
  406. package/dist/compiler/imported-record-functions.d.ts.map +0 -1
  407. package/dist/compiler/imported-record-functions.js +0 -706
  408. package/dist/compiler/imported-record-functions.js.map +0 -1
  409. package/dist/compiler/imported-schemas.d.ts +0 -21
  410. package/dist/compiler/imported-schemas.d.ts.map +0 -1
  411. package/dist/compiler/imported-schemas.js +0 -461
  412. package/dist/compiler/imported-schemas.js.map +0 -1
  413. package/dist/compiler/module-resolution.d.ts +0 -6
  414. package/dist/compiler/module-resolution.d.ts.map +0 -1
  415. package/dist/compiler/module-resolution.js +0 -44
  416. package/dist/compiler/module-resolution.js.map +0 -1
  417. package/dist/compiler/pipeline-companions.d.ts +0 -18
  418. package/dist/compiler/pipeline-companions.d.ts.map +0 -1
  419. package/dist/compiler/pipeline-companions.js +0 -1042
  420. package/dist/compiler/pipeline-companions.js.map +0 -1
  421. package/dist/compiler/providers.d.ts +0 -4
  422. package/dist/compiler/providers.d.ts.map +0 -1
  423. package/dist/compiler/providers.js +0 -101
  424. package/dist/compiler/providers.js.map +0 -1
  425. package/dist/emitter/pipeline-catalog.d.ts +0 -15
  426. package/dist/emitter/pipeline-catalog.d.ts.map +0 -1
  427. package/dist/emitter/pipeline-catalog.js +0 -55
  428. package/dist/emitter/pipeline-catalog.js.map +0 -1
  429. package/dist/emitter/pipeline-resolution.d.ts +0 -38
  430. package/dist/emitter/pipeline-resolution.d.ts.map +0 -1
  431. package/dist/emitter/pipeline-resolution.js +0 -571
  432. package/dist/emitter/pipeline-resolution.js.map +0 -1
  433. package/dist/interop/index.d.ts +0 -6
  434. package/dist/interop/index.d.ts.map +0 -1
  435. package/dist/interop/index.js +0 -6
  436. package/dist/interop/index.js.map +0 -1
  437. package/dist/math.ts +0 -1
  438. package/dist/parser/index.d.ts +0 -9
  439. package/dist/parser/index.d.ts.map +0 -1
  440. package/dist/parser/index.js +0 -9
  441. package/dist/parser/index.js.map +0 -1
  442. package/dist/service.ts +0 -3
  443. package/dist/service.ts.map +0 -1
  444. package/dist/tooling/migrate.d.ts +0 -62
  445. package/dist/tooling/migrate.d.ts.map +0 -1
  446. package/dist/tooling/migrate.js +0 -608
  447. package/dist/tooling/migrate.js.map +0 -1
@@ -0,0 +1,1205 @@
1
+ import type {
2
+ MatchExpression,
3
+ Program,
4
+ TaggedUnionSchema,
5
+ } from "../ast/types.js";
6
+ import { walkAst } from "../ast/walk.js";
7
+ import { Lexer } from "../lexer/lexer.js";
8
+ import { BANNED_KEYWORDS, BANNED_SYMBOLS } from "../lexer/tokens.js";
9
+ import { Parser } from "../parser/parser.js";
10
+ import type {
11
+ DiagnosticCategory,
12
+ TypeCheckDiagnostic,
13
+ TypeCheckResult,
14
+ } from "./check.js";
15
+
16
+ export type FunDiagnosticCode =
17
+ | "FUN_NON_FINAL_EFFECT"
18
+ | "FUN_EFFECT_MISSING_RETURN"
19
+ | "FUN_FUNCTION_MISSING_RETURN"
20
+ | "FUN_BANNED_SYNTAX"
21
+ | "FUN_PARSE_ERROR"
22
+ | "FUN_NON_EXHAUSTIVE_MATCH"
23
+ | "FUN_MISSING_SERVICE"
24
+ | "FUN_TYPE_ERROR"
25
+ | "FUN_WARNING";
26
+
27
+ export interface SuggestedEdit {
28
+ file: string;
29
+ startLine: number;
30
+ startColumn: number;
31
+ endLine: number;
32
+ endColumn: number;
33
+ replacement: string;
34
+ description: string;
35
+ }
36
+
37
+ export interface DiagnosticRepairHint {
38
+ kind: string;
39
+ description: string;
40
+ edits: SuggestedEdit[];
41
+ }
42
+
43
+ export interface DiagnosticInput {
44
+ file: string;
45
+ line: number;
46
+ column: number;
47
+ endLine?: number;
48
+ endColumn?: number;
49
+ message: string;
50
+ code?: number | string;
51
+ diagnosticCode?: string;
52
+ category?: DiagnosticCategory;
53
+ severity?: string;
54
+ }
55
+
56
+ export interface JsonCheckDiagnostic {
57
+ file: string;
58
+ line: number;
59
+ column: number;
60
+ endLine?: number;
61
+ endColumn?: number;
62
+ category: DiagnosticCategory;
63
+ code?: number | string;
64
+ message: string;
65
+ funCode: FunDiagnosticCode;
66
+ repairHints: DiagnosticRepairHint[];
67
+ }
68
+
69
+ export interface JsonCheckReport {
70
+ schemaVersion: 1;
71
+ success: boolean;
72
+ errorCount: number;
73
+ warningCount: number;
74
+ diagnostics: JsonCheckDiagnostic[];
75
+ }
76
+
77
+ const ANSI_ESCAPE_RE = new RegExp(
78
+ `${String.fromCharCode(0x1b)}\\[[0-9;]*m`,
79
+ "g",
80
+ );
81
+ const LOCATION_SUFFIX_RE = /\s+at line \d+, col \d+$/;
82
+
83
+ const BANNED_KEYWORD_MESSAGES = new Set(Object.values(BANNED_KEYWORDS));
84
+ const BANNED_SYMBOL_MESSAGES = new Set(Object.values(BANNED_SYMBOLS));
85
+
86
+ function stripAnsi(text: string): string {
87
+ return text.replace(ANSI_ESCAPE_RE, "");
88
+ }
89
+
90
+ function stripLocationSuffix(message: string): string {
91
+ return message.replace(LOCATION_SUFFIX_RE, "");
92
+ }
93
+
94
+ function splitLines(source?: string): string[] | undefined {
95
+ if (source === undefined) return undefined;
96
+ return source.replace(/\r\n/g, "\n").split("\n");
97
+ }
98
+
99
+ function getLine(
100
+ lines: string[] | undefined,
101
+ lineNumber: number,
102
+ ): string | undefined {
103
+ if (!lines || lineNumber < 1 || lineNumber > lines.length) return undefined;
104
+ return lines[lineNumber - 1];
105
+ }
106
+
107
+ function resolveCategory(diagnostic: DiagnosticInput): DiagnosticCategory {
108
+ if (diagnostic.category) return diagnostic.category;
109
+ switch (diagnostic.severity) {
110
+ case "warning":
111
+ return "warning";
112
+ case "suggestion":
113
+ return "suggestion";
114
+ case "message":
115
+ return "message";
116
+ default:
117
+ return "error";
118
+ }
119
+ }
120
+
121
+ function findBalancedEnd(
122
+ text: string,
123
+ openIndex: number,
124
+ openChar: string,
125
+ closeChar: string,
126
+ ): number {
127
+ let depth = 0;
128
+ let quote: string | null = null;
129
+ for (let i = openIndex; i < text.length; i++) {
130
+ const ch = text[i];
131
+ if (quote) {
132
+ if (ch === "\\" && i + 1 < text.length) {
133
+ i++;
134
+ continue;
135
+ }
136
+ if (ch === quote) quote = null;
137
+ continue;
138
+ }
139
+ if (ch === '"' || ch === "'" || ch === "`") {
140
+ quote = ch;
141
+ continue;
142
+ }
143
+ if (ch === openChar) depth++;
144
+ else if (ch === closeChar) {
145
+ depth--;
146
+ if (depth === 0) return i;
147
+ }
148
+ }
149
+ return -1;
150
+ }
151
+
152
+ function splitTopLevel(text: string, delimiter: string): string[] {
153
+ const parts: string[] = [];
154
+ let angle = 0;
155
+ let brace = 0;
156
+ let paren = 0;
157
+ let bracket = 0;
158
+ let quote: string | null = null;
159
+ let start = 0;
160
+
161
+ for (let i = 0; i < text.length; i++) {
162
+ const ch = text[i];
163
+ if (quote) {
164
+ if (ch === "\\" && i + 1 < text.length) {
165
+ i++;
166
+ continue;
167
+ }
168
+ if (ch === quote) quote = null;
169
+ continue;
170
+ }
171
+ if (ch === '"' || ch === "'" || ch === "`") {
172
+ quote = ch;
173
+ continue;
174
+ }
175
+ if (ch === "<") angle++;
176
+ else if (ch === ">" && text[i - 1] !== "=") angle = Math.max(0, angle - 1);
177
+ else if (ch === "{") brace++;
178
+ else if (ch === "}") brace = Math.max(0, brace - 1);
179
+ else if (ch === "(") paren++;
180
+ else if (ch === ")") paren = Math.max(0, paren - 1);
181
+ else if (ch === "[") bracket++;
182
+ else if (ch === "]") bracket = Math.max(0, bracket - 1);
183
+ else if (
184
+ ch === delimiter &&
185
+ angle === 0 &&
186
+ brace === 0 &&
187
+ paren === 0 &&
188
+ bracket === 0
189
+ ) {
190
+ parts.push(text.slice(start, i).trim());
191
+ start = i + 1;
192
+ }
193
+ }
194
+
195
+ const tail = text.slice(start).trim();
196
+ if (tail.length > 0) parts.push(tail);
197
+ return parts;
198
+ }
199
+
200
+ function extractTopLevelObjectFields(objectType: string): string[] {
201
+ const trimmed = objectType.trim();
202
+ if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) return [];
203
+ const inner = trimmed.slice(1, -1);
204
+ const props = splitTopLevel(inner, ";");
205
+ const fields: string[] = [];
206
+ for (const prop of props) {
207
+ const m = /^(?:readonly\s+)?([A-Za-z_$][A-Za-z0-9_$]*)\s*\??\s*:/.exec(
208
+ prop.trim(),
209
+ );
210
+ if (m && m[1] !== "_tag") {
211
+ fields.push(m[1]);
212
+ }
213
+ }
214
+ return fields;
215
+ }
216
+
217
+ function formatMissingMatchArm(unionMember: string): string {
218
+ const member = unionMember.trim();
219
+ if (member.startsWith("{") && member.endsWith("}")) {
220
+ const tagMatch = /\b_tag\s*:\s*"([^"]+)"/.exec(member);
221
+ if (tagMatch) {
222
+ const tag = tagMatch[1];
223
+ const fields = extractTopLevelObjectFields(member);
224
+ if (fields.length > 0) {
225
+ return `| ${tag}(${fields.join(", ")}) => ???`;
226
+ }
227
+ return `| ${tag} => ???`;
228
+ }
229
+ }
230
+ if (/^(true|false|-?\d+(?:\.\d+)?|"[^"]*"|'[^']*')$/.test(member)) {
231
+ return `| ${member} => ???`;
232
+ }
233
+ return `| _ => ???`;
234
+ }
235
+
236
+ function extractNonExhaustiveArms(message: string): string[] {
237
+ const marker = "NonExhaustiveError<";
238
+ const idx = message.indexOf(marker);
239
+ if (idx === -1) return [];
240
+ const angleStart = idx + marker.length - 1;
241
+ const angleEnd = findBalancedEnd(message, angleStart, "<", ">");
242
+ if (angleEnd === -1) return ["| _ => ???"];
243
+ const inner = message.slice(angleStart + 1, angleEnd).trim();
244
+ if (!inner) return ["| _ => ???"];
245
+
246
+ const members = splitTopLevel(inner, "|");
247
+ const arms: string[] = [];
248
+ const seen = new Set<string>();
249
+ for (const member of members) {
250
+ const arm = formatMissingMatchArm(member);
251
+ if (!seen.has(arm)) {
252
+ seen.add(arm);
253
+ arms.push(arm);
254
+ }
255
+ }
256
+ return arms.length > 0 ? arms : ["| _ => ???"];
257
+ }
258
+
259
+ function collectTaggedUnions(ast: Program): TaggedUnionSchema[] {
260
+ const schemas: TaggedUnionSchema[] = [];
261
+ for (const decl of ast.body) {
262
+ const inner = decl.kind === "ExportDeclaration" ? decl.declaration : decl;
263
+ if (
264
+ inner.kind === "SchemaDeclaration" &&
265
+ inner.body.kind === "TaggedUnionSchema"
266
+ ) {
267
+ schemas.push(inner.body);
268
+ }
269
+ }
270
+ return schemas;
271
+ }
272
+
273
+ function findMatchNearLine(
274
+ ast: Program,
275
+ line: number,
276
+ ): MatchExpression | undefined {
277
+ let best: MatchExpression | undefined;
278
+ let bestScore = Number.POSITIVE_INFINITY;
279
+ walkAst(ast, (node) => {
280
+ if (node.kind === "MatchExpression") {
281
+ const matchNode = node as unknown as MatchExpression;
282
+ const start = matchNode.span.start.line;
283
+ const end = matchNode.span.end.line;
284
+ if (line >= start && line <= end) {
285
+ const spanSize = end - start;
286
+ if (!best || spanSize < bestScore) {
287
+ best = matchNode;
288
+ bestScore = spanSize;
289
+ }
290
+ } else {
291
+ const dist = Math.min(Math.abs(line - start), Math.abs(line - end));
292
+ if (!best && dist <= 3) {
293
+ best = matchNode;
294
+ bestScore = dist + 1000;
295
+ }
296
+ }
297
+ }
298
+ });
299
+ return best;
300
+ }
301
+
302
+ function inferMissingArmsFromSource(
303
+ source: string | undefined,
304
+ line: number,
305
+ message: string,
306
+ ): string[] {
307
+ if (source !== undefined) {
308
+ try {
309
+ const ast = new Parser(
310
+ new Lexer(source, "<diagnostic>").tokenize(),
311
+ "<diagnostic>",
312
+ source,
313
+ ).parse();
314
+ const matchNode = findMatchNearLine(ast, line);
315
+ if (matchNode) {
316
+ const handledBools = new Set<boolean>();
317
+ const handledConstructors = new Set<string>();
318
+
319
+ for (const arm of matchNode.arms) {
320
+ if (
321
+ arm.pattern.kind === "LiteralPattern" &&
322
+ arm.pattern.literal.kind === "BooleanLiteral" &&
323
+ !arm.guard
324
+ ) {
325
+ handledBools.add(arm.pattern.literal.value);
326
+ } else if (arm.pattern.kind === "ConstructorPattern" && !arm.guard) {
327
+ handledConstructors.add(arm.pattern.constructorName.name);
328
+ } else if (
329
+ arm.pattern.kind === "VariablePattern" &&
330
+ !arm.guard &&
331
+ arm.pattern.name.kind === "UpperIdentifier"
332
+ ) {
333
+ handledConstructors.add(arm.pattern.name.name);
334
+ }
335
+ }
336
+
337
+ if (handledBools.size === 1) {
338
+ return handledBools.has(true)
339
+ ? ["| false => ???"]
340
+ : ["| true => ???"];
341
+ }
342
+
343
+ if (handledConstructors.size > 0) {
344
+ const unions = collectTaggedUnions(ast);
345
+ for (const union of unions) {
346
+ const variantNames = new Set(
347
+ union.variants.map((v) => v.name.name),
348
+ );
349
+ const allMatch = Array.from(handledConstructors).every((c) =>
350
+ variantNames.has(c),
351
+ );
352
+ if (allMatch) {
353
+ const missingArms = union.variants
354
+ .filter((v) => !handledConstructors.has(v.name.name))
355
+ .map((v) =>
356
+ v.fields.length > 0
357
+ ? `| ${v.name.name}(${v.fields.map((f) => f.name.name).join(", ")}) => ???`
358
+ : `| ${v.name.name} => ???`,
359
+ );
360
+ if (missingArms.length > 0) {
361
+ return missingArms;
362
+ }
363
+ }
364
+ }
365
+ }
366
+ }
367
+ } catch {
368
+ // Fall back to diagnostic message parsing when source cannot be parsed.
369
+ }
370
+ }
371
+
372
+ const tagMatch = /Missing variant:\s*'([^']+)'/.exec(message);
373
+ if (tagMatch) {
374
+ return [`| ${tagMatch[1]} => ???`];
375
+ }
376
+ return ["| _ => ???"];
377
+ }
378
+
379
+ function findMatchInsertPoint(
380
+ lines: string[],
381
+ startLine: number,
382
+ ): { line: number; column: number; indent: string } | null {
383
+ const startIdx = Math.max(0, startLine - 1);
384
+ let firstArmIdx = -1;
385
+
386
+ for (let i = startIdx; i < lines.length; i++) {
387
+ const trimmed = lines[i].trimStart();
388
+ if (trimmed.startsWith("| ")) {
389
+ firstArmIdx = i;
390
+ break;
391
+ }
392
+ if (i > startIdx && trimmed === "}") {
393
+ break;
394
+ }
395
+ }
396
+
397
+ if (firstArmIdx === -1) return null;
398
+
399
+ const armIndentMatch = /^(\s*)/.exec(lines[firstArmIdx]);
400
+ const armIndent = armIndentMatch ? armIndentMatch[1] : "";
401
+ let lastArmIdx = firstArmIdx;
402
+
403
+ for (let i = firstArmIdx + 1; i < lines.length; i++) {
404
+ const line = lines[i];
405
+ const trimmed = line.trim();
406
+ if (trimmed === "") {
407
+ let nextNonEmpty = i + 1;
408
+ while (nextNonEmpty < lines.length && lines[nextNonEmpty].trim() === "") {
409
+ nextNonEmpty++;
410
+ }
411
+ if (
412
+ nextNonEmpty < lines.length &&
413
+ lines[nextNonEmpty].startsWith(`${armIndent}| `)
414
+ ) {
415
+ i = nextNonEmpty - 1;
416
+ continue;
417
+ }
418
+ break;
419
+ }
420
+
421
+ const indentLen = (/^(\s*)/.exec(line)?.[1] ?? "").length;
422
+ if (line.startsWith(`${armIndent}| `) || indentLen > armIndent.length) {
423
+ lastArmIdx = i;
424
+ continue;
425
+ }
426
+ break;
427
+ }
428
+
429
+ return {
430
+ line: lastArmIdx + 1,
431
+ column: lines[lastArmIdx].length + 1,
432
+ indent: armIndent,
433
+ };
434
+ }
435
+
436
+ function extractEffectTypeAt(
437
+ text: string,
438
+ startIndex: number,
439
+ ): { a: string; e: string; r: string; endIndex: number } | null {
440
+ const angleStart = text.indexOf("<", startIndex);
441
+ if (angleStart === -1) return null;
442
+ const angleEnd = findBalancedEnd(text, angleStart, "<", ">");
443
+ if (angleEnd === -1) return null;
444
+ const args = splitTopLevel(text.slice(angleStart + 1, angleEnd), ",");
445
+ if (args.length < 3) return null;
446
+ return {
447
+ a: args[0],
448
+ e: args[1],
449
+ r: args[2],
450
+ endIndex: angleEnd,
451
+ };
452
+ }
453
+
454
+ function collectDeclaredServices(ast: Program): string[] {
455
+ const services: string[] = [];
456
+ for (const decl of ast.body) {
457
+ const inner = decl.kind === "ExportDeclaration" ? decl.declaration : decl;
458
+ if (inner.kind === "ServiceDeclaration") {
459
+ services.push(inner.id.name);
460
+ }
461
+ }
462
+ return services;
463
+ }
464
+
465
+ function collectUsedServicesInAst(
466
+ root: unknown,
467
+ declaredServices: ReadonlySet<string>,
468
+ bindingInits: ReadonlyMap<string, unknown>,
469
+ visitedBindings: Set<string>,
470
+ foundServices: Set<string>,
471
+ ): void {
472
+ walkAst(root, (node) => {
473
+ if (
474
+ node.kind === "CallExpression" &&
475
+ typeof node.callee === "object" &&
476
+ node.callee !== null
477
+ ) {
478
+ const callee = node.callee as Record<string, unknown>;
479
+ if (
480
+ callee.kind === "MemberExpression" &&
481
+ typeof callee.object === "object" &&
482
+ callee.object !== null
483
+ ) {
484
+ const obj = callee.object as Record<string, unknown>;
485
+ if (
486
+ obj.kind === "UpperIdentifier" &&
487
+ typeof obj.name === "string" &&
488
+ declaredServices.has(obj.name)
489
+ ) {
490
+ foundServices.add(obj.name);
491
+ }
492
+ }
493
+ } else if (
494
+ node.kind === "Identifier" &&
495
+ typeof node.name === "string" &&
496
+ bindingInits.has(node.name) &&
497
+ !visitedBindings.has(node.name)
498
+ ) {
499
+ visitedBindings.add(node.name);
500
+ collectUsedServicesInAst(
501
+ bindingInits.get(node.name),
502
+ declaredServices,
503
+ bindingInits,
504
+ visitedBindings,
505
+ foundServices,
506
+ );
507
+ }
508
+ });
509
+ }
510
+
511
+ function inferMissingServicesFromSource(
512
+ source: string | undefined,
513
+ line: number,
514
+ message: string,
515
+ ): { matched: boolean; services: string[] } {
516
+ const mismatch =
517
+ /^Effect error channel mismatch: expected (.+), got (.+)\.$/.exec(message);
518
+ if (!mismatch || mismatch[1].trim() !== mismatch[2].trim()) {
519
+ return { matched: false, services: [] };
520
+ }
521
+ if (source === undefined) {
522
+ return { matched: true, services: [] };
523
+ }
524
+
525
+ try {
526
+ const ast = new Parser(
527
+ new Lexer(source, "<diagnostic>").tokenize(),
528
+ "<diagnostic>",
529
+ source,
530
+ ).parse();
531
+ const declared = collectDeclaredServices(ast);
532
+ if (declared.length === 0) {
533
+ return { matched: true, services: [] };
534
+ }
535
+ const declaredSet = new Set(declared);
536
+ const bindingInits = new Map<string, unknown>();
537
+ let targetNode: unknown;
538
+
539
+ for (const decl of ast.body) {
540
+ const inner = decl.kind === "ExportDeclaration" ? decl.declaration : decl;
541
+ if (inner.kind === "BindingDeclaration") {
542
+ if (
543
+ inner.id.kind === "Identifier" ||
544
+ inner.id.kind === "UpperIdentifier"
545
+ ) {
546
+ bindingInits.set(inner.id.name, inner.init);
547
+ }
548
+ if (line >= decl.span.start.line && line <= decl.span.end.line) {
549
+ targetNode = inner.init;
550
+ }
551
+ }
552
+ }
553
+
554
+ const found = new Set<string>();
555
+ collectUsedServicesInAst(
556
+ targetNode ?? ast,
557
+ declaredSet,
558
+ bindingInits,
559
+ new Set<string>(),
560
+ found,
561
+ );
562
+ const ordered = declared.filter((name) => found.has(name));
563
+ return { matched: true, services: ordered };
564
+ } catch {
565
+ return { matched: true, services: [] };
566
+ }
567
+ }
568
+
569
+ function extractMissingServices(message: string): string[] {
570
+ const sourceEffectMatch =
571
+ /(?:Argument of type|Type)\s+'(?:Effect\.)?Effect</.exec(message);
572
+ if (!sourceEffectMatch) return [];
573
+
574
+ const sourceEffect = extractEffectTypeAt(message, sourceEffectMatch.index);
575
+ if (!sourceEffect) return [];
576
+
577
+ const afterSource = message.slice(sourceEffect.endIndex + 1);
578
+ const targetEffectMatch =
579
+ /is not assignable to (?:parameter of )?type\s+'(?:Effect\.)?Effect</.exec(
580
+ afterSource,
581
+ );
582
+ if (!targetEffectMatch) return [];
583
+
584
+ const targetEffect = extractEffectTypeAt(
585
+ afterSource,
586
+ targetEffectMatch.index,
587
+ );
588
+ if (!targetEffect) return [];
589
+
590
+ const actualServices = splitTopLevel(sourceEffect.r, "|").filter(
591
+ (s) => s.length > 0 && s !== "never" && s !== "unknown" && s !== "any",
592
+ );
593
+ const expectedServices = new Set(
594
+ splitTopLevel(targetEffect.r, "|").filter(
595
+ (s) => s.length > 0 && s !== "never",
596
+ ),
597
+ );
598
+
599
+ return actualServices.filter((s) => !expectedServices.has(s));
600
+ }
601
+
602
+ function toLiveLayerName(serviceType: string): string {
603
+ const base = serviceType.replace(/<.*>$/, "").trim();
604
+ return `${base}Live`;
605
+ }
606
+
607
+ function hasBalancedDelimiters(text: string): boolean {
608
+ let paren = 0;
609
+ let brace = 0;
610
+ let bracket = 0;
611
+ let quote: string | null = null;
612
+ for (let i = 0; i < text.length; i++) {
613
+ const ch = text[i];
614
+ if (quote) {
615
+ if (ch === "\\" && i + 1 < text.length) {
616
+ i++;
617
+ continue;
618
+ }
619
+ if (ch === quote) quote = null;
620
+ continue;
621
+ }
622
+ if (ch === '"' || ch === "'" || ch === "`") {
623
+ quote = ch;
624
+ continue;
625
+ }
626
+ if (ch === "(") paren++;
627
+ else if (ch === ")") paren--;
628
+ else if (ch === "{") brace++;
629
+ else if (ch === "}") brace--;
630
+ else if (ch === "[") bracket++;
631
+ else if (ch === "]") bracket--;
632
+ if (paren < 0 || brace < 0 || bracket < 0) return false;
633
+ }
634
+ return paren === 0 && brace === 0 && bracket === 0 && quote === null;
635
+ }
636
+
637
+ function buildProvideServiceEdits(
638
+ diagnostic: DiagnosticInput,
639
+ lines: string[] | undefined,
640
+ provideChain: string,
641
+ ): SuggestedEdit[] {
642
+ const lineText = getLine(lines, diagnostic.line);
643
+ if (!lineText) return [];
644
+
645
+ if (
646
+ diagnostic.endLine === diagnostic.line &&
647
+ diagnostic.endColumn !== undefined
648
+ ) {
649
+ const startIdx = Math.max(0, diagnostic.column - 1);
650
+ const endIdx = Math.min(lineText.length, diagnostic.endColumn - 1);
651
+ const spanText = lineText.slice(startIdx, endIdx);
652
+ const before = lineText.slice(0, startIdx);
653
+ const after = lineText.slice(endIdx);
654
+
655
+ const isBindingLhs =
656
+ /^\s*(?:export\s+)?(?:mut\s+)?$/.test(before) &&
657
+ (/^\s*=/.test(after) || /^\s*:[^=]*=/.test(after));
658
+
659
+ if (isBindingLhs) {
660
+ const eqIdx = lineText.indexOf("=", endIdx);
661
+ if (eqIdx !== -1) {
662
+ const rhsRaw = lineText.slice(eqIdx + 1);
663
+ const leadingSpaces = rhsRaw.length - rhsRaw.trimStart().length;
664
+ const rhsStartIdx = eqIdx + 1 + leadingSpaces;
665
+ const rhsTrimmed = lineText.slice(rhsStartIdx).trimEnd();
666
+ if (
667
+ rhsTrimmed.length > 0 &&
668
+ !rhsTrimmed.endsWith("{") &&
669
+ hasBalancedDelimiters(rhsTrimmed)
670
+ ) {
671
+ return [
672
+ {
673
+ file: diagnostic.file,
674
+ startLine: diagnostic.line,
675
+ startColumn: rhsStartIdx + 1,
676
+ endLine: diagnostic.line,
677
+ endColumn: rhsStartIdx + rhsTrimmed.length + 1,
678
+ replacement: `${rhsTrimmed} ${provideChain}`,
679
+ description: `Provide required service(s) with '${provideChain}'`,
680
+ },
681
+ ];
682
+ }
683
+ }
684
+ return [];
685
+ }
686
+
687
+ if (
688
+ spanText.length > 0 &&
689
+ !spanText.endsWith("{") &&
690
+ hasBalancedDelimiters(spanText)
691
+ ) {
692
+ return [
693
+ {
694
+ file: diagnostic.file,
695
+ startLine: diagnostic.line,
696
+ startColumn: diagnostic.column,
697
+ endLine: diagnostic.line,
698
+ endColumn: diagnostic.endColumn,
699
+ replacement: `${spanText} ${provideChain}`,
700
+ description: `Provide required service(s) with '${provideChain}'`,
701
+ },
702
+ ];
703
+ }
704
+ }
705
+
706
+ return [];
707
+ }
708
+
709
+ function buildBannedSyntaxHints(
710
+ diagnostic: DiagnosticInput,
711
+ coreMsg: string,
712
+ lines: string[] | undefined,
713
+ ): DiagnosticRepairHint[] {
714
+ const lineText = getLine(lines, diagnostic.line);
715
+ const startIdx = Math.max(0, diagnostic.column - 1);
716
+ const rest = lineText ? lineText.slice(startIdx) : "";
717
+ const edits: SuggestedEdit[] = [];
718
+
719
+ if (lineText) {
720
+ if (coreMsg === BANNED_KEYWORDS.let || coreMsg === BANNED_KEYWORDS.const) {
721
+ const m = /^(let|const)\s+/.exec(rest);
722
+ if (m) {
723
+ edits.push({
724
+ file: diagnostic.file,
725
+ startLine: diagnostic.line,
726
+ startColumn: diagnostic.column,
727
+ endLine: diagnostic.line,
728
+ endColumn: diagnostic.column + m[0].length,
729
+ replacement: "",
730
+ description: `Remove '${m[1]}' (FunkScript bindings are immutable by default)`,
731
+ });
732
+ }
733
+ } else if (coreMsg === BANNED_KEYWORDS.var) {
734
+ const m = /^var\b/.exec(rest);
735
+ if (m) {
736
+ edits.push({
737
+ file: diagnostic.file,
738
+ startLine: diagnostic.line,
739
+ startColumn: diagnostic.column,
740
+ endLine: diagnostic.line,
741
+ endColumn: diagnostic.column + 3,
742
+ replacement: "mut",
743
+ description: "Replace 'var' with 'mut'",
744
+ });
745
+ }
746
+ } else if (coreMsg === BANNED_KEYWORDS.return) {
747
+ const m = /^return\b/.exec(rest);
748
+ if (m) {
749
+ edits.push({
750
+ file: diagnostic.file,
751
+ startLine: diagnostic.line,
752
+ startColumn: diagnostic.column,
753
+ endLine: diagnostic.line,
754
+ endColumn: diagnostic.column + 6,
755
+ replacement: "=>",
756
+ description: "Replace 'return' with '=>'",
757
+ });
758
+ }
759
+ } else if (coreMsg === BANNED_KEYWORDS.type) {
760
+ const m = /^type\b/.exec(rest);
761
+ if (m) {
762
+ edits.push({
763
+ file: diagnostic.file,
764
+ startLine: diagnostic.line,
765
+ startColumn: diagnostic.column,
766
+ endLine: diagnostic.line,
767
+ endColumn: diagnostic.column + 4,
768
+ replacement: "schema",
769
+ description: "Replace 'type' with 'schema'",
770
+ });
771
+ }
772
+ } else if (coreMsg === BANNED_SYMBOLS["&&"] && rest.startsWith("&&")) {
773
+ edits.push({
774
+ file: diagnostic.file,
775
+ startLine: diagnostic.line,
776
+ startColumn: diagnostic.column,
777
+ endLine: diagnostic.line,
778
+ endColumn: diagnostic.column + 2,
779
+ replacement: "and",
780
+ description: "Replace '&&' with 'and'",
781
+ });
782
+ } else if (coreMsg === BANNED_SYMBOLS["||"] && rest.startsWith("||")) {
783
+ edits.push({
784
+ file: diagnostic.file,
785
+ startLine: diagnostic.line,
786
+ startColumn: diagnostic.column,
787
+ endLine: diagnostic.line,
788
+ endColumn: diagnostic.column + 2,
789
+ replacement: "or",
790
+ description: "Replace '||' with 'or'",
791
+ });
792
+ } else if (
793
+ coreMsg === BANNED_SYMBOLS["!"] &&
794
+ rest.startsWith("!") &&
795
+ !rest.startsWith("!=")
796
+ ) {
797
+ edits.push({
798
+ file: diagnostic.file,
799
+ startLine: diagnostic.line,
800
+ startColumn: diagnostic.column,
801
+ endLine: diagnostic.line,
802
+ endColumn: diagnostic.column + 1,
803
+ replacement: rest.startsWith("! ") ? "not" : "not ",
804
+ description: "Replace '!' with 'not'",
805
+ });
806
+ } else if (coreMsg === BANNED_SYMBOLS["==="] && rest.startsWith("===")) {
807
+ edits.push({
808
+ file: diagnostic.file,
809
+ startLine: diagnostic.line,
810
+ startColumn: diagnostic.column,
811
+ endLine: diagnostic.line,
812
+ endColumn: diagnostic.column + 3,
813
+ replacement: "@=",
814
+ description: "Replace '===' with '@='",
815
+ });
816
+ } else if (coreMsg === BANNED_SYMBOLS["!=="] && rest.startsWith("!==")) {
817
+ edits.push({
818
+ file: diagnostic.file,
819
+ startLine: diagnostic.line,
820
+ startColumn: diagnostic.column,
821
+ endLine: diagnostic.line,
822
+ endColumn: diagnostic.column + 3,
823
+ replacement: "@!",
824
+ description: "Replace '!==' with '@!'",
825
+ });
826
+ } else if (coreMsg === BANNED_SYMBOLS["=="] && rest.startsWith("==")) {
827
+ edits.push({
828
+ file: diagnostic.file,
829
+ startLine: diagnostic.line,
830
+ startColumn: diagnostic.column,
831
+ endLine: diagnostic.line,
832
+ endColumn: diagnostic.column + 2,
833
+ replacement: "#=",
834
+ description: "Replace '==' with '#=' (value equality)",
835
+ });
836
+ } else if (coreMsg === BANNED_SYMBOLS["!="] && rest.startsWith("!=")) {
837
+ edits.push({
838
+ file: diagnostic.file,
839
+ startLine: diagnostic.line,
840
+ startColumn: diagnostic.column,
841
+ endLine: diagnostic.line,
842
+ endColumn: diagnostic.column + 2,
843
+ replacement: "#!",
844
+ description: "Replace '!=' with '#!' (value inequality)",
845
+ });
846
+ } else if (
847
+ coreMsg.startsWith("Tabs are not allowed") &&
848
+ rest.startsWith("\t")
849
+ ) {
850
+ edits.push({
851
+ file: diagnostic.file,
852
+ startLine: diagnostic.line,
853
+ startColumn: diagnostic.column,
854
+ endLine: diagnostic.line,
855
+ endColumn: diagnostic.column + 1,
856
+ replacement: " ",
857
+ description: "Replace tab with 2 spaces",
858
+ });
859
+ } else if (coreMsg.startsWith("Reference identity operator '@='")) {
860
+ const opIdx =
861
+ lineText.indexOf("@=", startIdx) !== -1
862
+ ? lineText.indexOf("@=", startIdx)
863
+ : lineText.indexOf("@=");
864
+ if (opIdx !== -1) {
865
+ edits.push({
866
+ file: diagnostic.file,
867
+ startLine: diagnostic.line,
868
+ startColumn: opIdx + 1,
869
+ endLine: diagnostic.line,
870
+ endColumn: opIdx + 3,
871
+ replacement: "#=",
872
+ description: "Replace '@=' with '#=' for value equality",
873
+ });
874
+ }
875
+ } else if (coreMsg.startsWith("Reference identity operator '@!'")) {
876
+ const opIdx =
877
+ lineText.indexOf("@!", startIdx) !== -1
878
+ ? lineText.indexOf("@!", startIdx)
879
+ : lineText.indexOf("@!");
880
+ if (opIdx !== -1) {
881
+ edits.push({
882
+ file: diagnostic.file,
883
+ startLine: diagnostic.line,
884
+ startColumn: opIdx + 1,
885
+ endLine: diagnostic.line,
886
+ endColumn: opIdx + 3,
887
+ replacement: "#!",
888
+ description: "Replace '@!' with '#!' for value inequality",
889
+ });
890
+ }
891
+ }
892
+ }
893
+
894
+ return [
895
+ {
896
+ kind: "replace-banned-syntax",
897
+ description: coreMsg,
898
+ edits,
899
+ },
900
+ ];
901
+ }
902
+
903
+ function isBannedSyntaxMessage(coreMsg: string): boolean {
904
+ return (
905
+ BANNED_KEYWORD_MESSAGES.has(coreMsg) ||
906
+ BANNED_SYMBOL_MESSAGES.has(coreMsg) ||
907
+ coreMsg.startsWith("Tabs are not allowed for indentation") ||
908
+ coreMsg.startsWith("Reference identity operator '") ||
909
+ coreMsg.includes("is only available for numbers; this operand has type") ||
910
+ coreMsg.startsWith("Early return 'when (...) =>' is rejected") ||
911
+ coreMsg.startsWith(
912
+ "Early returns ('when (...) =>') are disabled by default",
913
+ )
914
+ );
915
+ }
916
+
917
+ /**
918
+ * Deterministically classifies a FunkScript or TypeScript check diagnostic
919
+ * and generates structured repair hints and suggested source edits.
920
+ */
921
+ export function classifyDiagnostic(
922
+ diagnostic: DiagnosticInput,
923
+ source?: string,
924
+ ): { funCode: FunDiagnosticCode; repairHints: DiagnosticRepairHint[] } {
925
+ const message = stripAnsi(diagnostic.message);
926
+ const coreMsg = stripLocationSuffix(message);
927
+ const lines = splitLines(source);
928
+ const category = resolveCategory(diagnostic);
929
+
930
+ if (
931
+ coreMsg.startsWith(
932
+ "Non-final bare expression in effect block is not executed",
933
+ )
934
+ ) {
935
+ const edits: SuggestedEdit[] = [];
936
+ const lineText = getLine(lines, diagnostic.line);
937
+ if (lineText) {
938
+ const startIdx = Math.max(0, diagnostic.column - 1);
939
+ const endIdx =
940
+ diagnostic.endLine === diagnostic.line &&
941
+ diagnostic.endColumn !== undefined &&
942
+ diagnostic.endColumn - 1 > startIdx &&
943
+ diagnostic.endColumn - 1 <= lineText.length
944
+ ? diagnostic.endColumn - 1
945
+ : lineText.trimEnd().length;
946
+ const exprText = lineText.slice(startIdx, endIdx);
947
+ if (exprText.trim().length > 0) {
948
+ edits.push({
949
+ file: diagnostic.file,
950
+ startLine: diagnostic.line,
951
+ startColumn: diagnostic.column,
952
+ endLine: diagnostic.line,
953
+ endColumn: endIdx + 1,
954
+ replacement: `_ <- ${exprText}`,
955
+ description: `Execute and discard effect with '_ <- ${exprText}'`,
956
+ });
957
+ }
958
+ }
959
+ return {
960
+ funCode: "FUN_NON_FINAL_EFFECT",
961
+ repairHints: [
962
+ {
963
+ kind: "discard-effect-bind",
964
+ description:
965
+ "Use '_ <- <expr>' to execute and discard an effect, or 'name <- <expr>' to bind its result.",
966
+ edits,
967
+ },
968
+ ],
969
+ };
970
+ }
971
+
972
+ if (
973
+ coreMsg.startsWith(
974
+ "Effect block must end with an explicit '=> returnValue'",
975
+ ) ||
976
+ coreMsg.startsWith("Effect block return must be the final statement")
977
+ ) {
978
+ return {
979
+ funCode: "FUN_EFFECT_MISSING_RETURN",
980
+ repairHints: [
981
+ {
982
+ kind: "explicit-return",
983
+ description:
984
+ "End the effect block with an explicit '=> <value>' return statement (for example '=> ()').",
985
+ edits: [],
986
+ },
987
+ ],
988
+ };
989
+ }
990
+
991
+ if (
992
+ coreMsg.startsWith(
993
+ "Function block must end with an explicit '=> returnValue'",
994
+ )
995
+ ) {
996
+ return {
997
+ funCode: "FUN_FUNCTION_MISSING_RETURN",
998
+ repairHints: [
999
+ {
1000
+ kind: "explicit-return",
1001
+ description:
1002
+ "End the function block with an explicit '=> <value>' return statement.",
1003
+ edits: [],
1004
+ },
1005
+ ],
1006
+ };
1007
+ }
1008
+
1009
+ if (isBannedSyntaxMessage(coreMsg)) {
1010
+ return {
1011
+ funCode: "FUN_BANNED_SYNTAX",
1012
+ repairHints: buildBannedSyntaxHints(diagnostic, coreMsg, lines),
1013
+ };
1014
+ }
1015
+
1016
+ if (
1017
+ diagnostic.code === "SYNTAX" ||
1018
+ diagnostic.diagnosticCode === "FS_SYNTAX"
1019
+ ) {
1020
+ return {
1021
+ funCode: "FUN_PARSE_ERROR",
1022
+ repairHints: [],
1023
+ };
1024
+ }
1025
+
1026
+ if (
1027
+ message.includes("NonExhaustiveError<") ||
1028
+ diagnostic.code === "NON_EXHAUSTIVE_MATCH" ||
1029
+ diagnostic.diagnosticCode === "FS_NON_EXHAUSTIVE_MATCH" ||
1030
+ message.startsWith("Pattern match is not exhaustive.")
1031
+ ) {
1032
+ const arms = message.includes("NonExhaustiveError<")
1033
+ ? extractNonExhaustiveArms(message)
1034
+ : inferMissingArmsFromSource(source, diagnostic.line, message);
1035
+ const edits: SuggestedEdit[] = [];
1036
+ if (lines) {
1037
+ const insertPoint = findMatchInsertPoint(lines, diagnostic.line);
1038
+ if (insertPoint) {
1039
+ const formattedArms = arms
1040
+ .map((arm) => `${insertPoint.indent}${arm}`)
1041
+ .join("\n");
1042
+ edits.push({
1043
+ file: diagnostic.file,
1044
+ startLine: insertPoint.line,
1045
+ startColumn: insertPoint.column,
1046
+ endLine: insertPoint.line,
1047
+ endColumn: insertPoint.column,
1048
+ replacement: `\n${formattedArms}`,
1049
+ description: `Append missing match arm${arms.length === 1 ? "" : "s"}`,
1050
+ });
1051
+ }
1052
+ }
1053
+ return {
1054
+ funCode: "FUN_NON_EXHAUSTIVE_MATCH",
1055
+ repairHints: [
1056
+ {
1057
+ kind: "add-match-arms",
1058
+ description: `Add missing match arm${arms.length === 1 ? "" : "s"}: ${arms.join(", ")}`,
1059
+ edits,
1060
+ },
1061
+ ],
1062
+ };
1063
+ }
1064
+
1065
+ const missingServices = extractMissingServices(message);
1066
+ if (missingServices.length > 0) {
1067
+ const provideChain = missingServices
1068
+ .map((svc) => `|> Effect.provide(${toLiveLayerName(svc)})`)
1069
+ .join(" ");
1070
+ const edits = buildProvideServiceEdits(diagnostic, lines, provideChain);
1071
+ return {
1072
+ funCode: "FUN_MISSING_SERVICE",
1073
+ repairHints: [
1074
+ {
1075
+ kind: "provide-service",
1076
+ description: `Provide missing service(s) (${missingServices.join(", ")}) using '${provideChain}'.`,
1077
+ edits,
1078
+ },
1079
+ ],
1080
+ };
1081
+ }
1082
+
1083
+ const inferredServices = inferMissingServicesFromSource(
1084
+ source,
1085
+ diagnostic.line,
1086
+ coreMsg,
1087
+ );
1088
+ if (inferredServices.matched) {
1089
+ if (inferredServices.services.length > 0) {
1090
+ const provideChain = inferredServices.services
1091
+ .map((svc) => `|> Effect.provide(${toLiveLayerName(svc)})`)
1092
+ .join(" ");
1093
+ const edits = buildProvideServiceEdits(diagnostic, lines, provideChain);
1094
+ return {
1095
+ funCode: "FUN_MISSING_SERVICE",
1096
+ repairHints: [
1097
+ {
1098
+ kind: "provide-service",
1099
+ description: `Provide missing service(s) (${inferredServices.services.join(", ")}) using '${provideChain}'.`,
1100
+ edits,
1101
+ },
1102
+ ],
1103
+ };
1104
+ }
1105
+ return {
1106
+ funCode: "FUN_MISSING_SERVICE",
1107
+ repairHints: [
1108
+ {
1109
+ kind: "provide-service",
1110
+ description:
1111
+ "Provide required Effect service(s) using '|> Effect.provide(<Service>Live)'.",
1112
+ edits: [],
1113
+ },
1114
+ ],
1115
+ };
1116
+ }
1117
+
1118
+ if (category === "warning") {
1119
+ return {
1120
+ funCode: "FUN_WARNING",
1121
+ repairHints: [],
1122
+ };
1123
+ }
1124
+
1125
+ const repairHints: DiagnosticRepairHint[] = [];
1126
+ if (/Property '[^']+' does not exist on type 'Option<[^>]+>'/.test(message)) {
1127
+ repairHints.push({
1128
+ kind: "unwrap-option",
1129
+ description:
1130
+ "Untrusted 'js' calls return Option<unknown>; validate or match with Option.match / Schema.decodeUnknown before accessing properties.",
1131
+ edits: [],
1132
+ });
1133
+ }
1134
+
1135
+ return {
1136
+ funCode: "FUN_TYPE_ERROR",
1137
+ repairHints,
1138
+ };
1139
+ }
1140
+
1141
+ /**
1142
+ * Attaches classification and repair hints to a 0.2.6 TypeCheckDiagnostic or CLI JSON
1143
+ * diagnostic entry while preserving all existing fields.
1144
+ */
1145
+ export function attachRepairHints<T extends DiagnosticInput>(
1146
+ diagnostic: T,
1147
+ source?: string,
1148
+ ): T & {
1149
+ funCode: FunDiagnosticCode;
1150
+ repairHints: DiagnosticRepairHint[];
1151
+ } {
1152
+ const { funCode, repairHints } = classifyDiagnostic(diagnostic, source);
1153
+ return {
1154
+ ...diagnostic,
1155
+ funCode,
1156
+ repairHints,
1157
+ };
1158
+ }
1159
+
1160
+ /**
1161
+ * Enriches a TypeCheckResult with FunkScript diagnostic codes and repair metadata,
1162
+ * omitting ANSI-formatted text fields for clean machine-readable JSON output.
1163
+ */
1164
+ export function enrichCheckResult(
1165
+ result: TypeCheckResult,
1166
+ sourcesByFile?: Record<string, string>,
1167
+ ): JsonCheckReport {
1168
+ const diagnostics: JsonCheckDiagnostic[] = result.diagnostics.map(
1169
+ (d: TypeCheckDiagnostic) => {
1170
+ const source = sourcesByFile?.[d.file];
1171
+ const { funCode, repairHints } = classifyDiagnostic(d, source);
1172
+ const entry: JsonCheckDiagnostic = {
1173
+ file: d.file,
1174
+ line: d.line,
1175
+ column: d.column,
1176
+ ...(d.endLine !== undefined ? { endLine: d.endLine } : {}),
1177
+ ...(d.endColumn !== undefined ? { endColumn: d.endColumn } : {}),
1178
+ category: d.category,
1179
+ ...(d.code !== undefined ? { code: d.code } : {}),
1180
+ message: stripAnsi(d.message),
1181
+ funCode,
1182
+ repairHints,
1183
+ };
1184
+ return entry;
1185
+ },
1186
+ );
1187
+
1188
+ return {
1189
+ schemaVersion: 1,
1190
+ success: result.success,
1191
+ errorCount: result.errorCount,
1192
+ warningCount: result.warningCount,
1193
+ diagnostics,
1194
+ };
1195
+ }
1196
+
1197
+ /**
1198
+ * Formats a TypeCheckResult as deterministic, pretty-printed JSON.
1199
+ */
1200
+ export function formatCheckJson(
1201
+ result: TypeCheckResult,
1202
+ sourcesByFile?: Record<string, string>,
1203
+ ): string {
1204
+ return JSON.stringify(enrichCheckResult(result, sourcesByFile), null, 2);
1205
+ }