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
package/dist/lsp/hover.js CHANGED
@@ -1,23 +1,906 @@
1
+ import { existsSync, readFileSync } from "node:fs";
2
+ import { dirname, resolve } from "node:path";
3
+ import { fileURLToPath, pathToFileURL } from "node:url";
1
4
  import * as Effect from "effect/Effect";
2
- import { fileURLToPath } from "node:url";
3
5
  import ts from "typescript";
4
6
  import { MarkupKind, } from "vscode-languageserver/node";
5
7
  import { compileString } from "../compiler.js";
6
- import { resolveImportedSchemas } from "../compiler/schemas/imported-schemas.js";
8
+ import { pipelineCompanionCandidates } from "../compiler/pipelines/catalog.js";
7
9
  import { inferPipelineCompanions } from "../compiler/pipelines/companions.js";
10
+ import { resolveImportedSchemas } from "../compiler/schemas/imported-schemas.js";
8
11
  import { TypeScriptCompilationContext } from "../compiler/typescript-context.js";
9
12
  import { Emitter } from "../emitter/emitter.js";
10
- import { pipelineCompanionCandidates } from "../compiler/pipelines/catalog.js";
13
+ import { FunScriptError, isExpectedSyntaxError, isExpectedUriError, isFileNotFoundError, } from "../errors.js";
11
14
  import { Lexer } from "../lexer/lexer.js";
12
15
  import { BANNED_KEYWORDS, BANNED_SYMBOLS, TokenType, } from "../lexer/tokens.js";
13
16
  import { Parser } from "../parser/parser.js";
14
- import { spanToRange } from "./definition.js";
17
+ import { detectJsxContext } from "./completion.js";
18
+ import { DefinitionFinder, findDefinition, isPositionInSpan, spanToRange, } from "./definition.js";
15
19
  import { getHoverDocumentation } from "./docs.js";
16
- import { FunScriptError } from "../errors.js";
17
20
  function isExpectedHoverError(error) {
18
21
  return error instanceof FunScriptError || error instanceof URIError;
19
22
  }
20
- function symbolHover(source, uri, token) {
23
+ function isWordChar(ch) {
24
+ return /[A-Za-z0-9_]/.test(ch);
25
+ }
26
+ function tryParseProgram(source, uri, existingTokens) {
27
+ try {
28
+ const tokens = existingTokens ?? new Lexer(source, uri).tokenize();
29
+ return new Parser(tokens, uri, source).parse();
30
+ }
31
+ catch (error) {
32
+ if (!isExpectedSyntaxError(error))
33
+ throw error;
34
+ return null;
35
+ }
36
+ }
37
+ function formatBindingTarget(target) {
38
+ if (target.kind === "Identifier" || target.kind === "UpperIdentifier") {
39
+ return target.name;
40
+ }
41
+ if (target.kind === "RecordPattern") {
42
+ return `{ ${target.fields
43
+ .map((f) => f.pattern
44
+ ? `${f.key.name}: ${formatBindingTarget(f.pattern)}`
45
+ : f.key.name)
46
+ .join(", ")} }`;
47
+ }
48
+ return `[${target.elements.map((e) => ("name" in e && typeof e.name === "object" && e.name && "name" in e.name ? String(e.name.name) : "_")).join(", ")}]`;
49
+ }
50
+ function formatTypeNode(typeNode) {
51
+ switch (typeNode.kind) {
52
+ case "TypeReferenceNode": {
53
+ const args = typeNode.typeArgs && typeNode.typeArgs.length > 0
54
+ ? `<${typeNode.typeArgs.map(formatTypeNode).join(", ")}>`
55
+ : "";
56
+ return `${typeNode.name.name}${args}`;
57
+ }
58
+ case "QualifiedTypeReferenceNode": {
59
+ const args = typeNode.typeArgs && typeNode.typeArgs.length > 0
60
+ ? `<${typeNode.typeArgs.map(formatTypeNode).join(", ")}>`
61
+ : "";
62
+ return `${typeNode.parts.map((p) => p.name).join(".")}${args}`;
63
+ }
64
+ case "FunctionTypeNode": {
65
+ const tp = typeNode.typeParams && typeNode.typeParams.length > 0
66
+ ? `<${typeNode.typeParams.map((p) => p.name.name).join(", ")}>`
67
+ : "";
68
+ const params = typeNode.params
69
+ .map((p) => p.typeAnnotation
70
+ ? `${formatBindingTarget(p.name)}: ${formatTypeNode(p.typeAnnotation)}`
71
+ : formatBindingTarget(p.name))
72
+ .join(", ");
73
+ return `${tp}(${params}) => ${formatTypeNode(typeNode.returnType)}`;
74
+ }
75
+ case "EffectTypeNode": {
76
+ const parts = [formatTypeNode(typeNode.success)];
77
+ if (typeNode.error)
78
+ parts.push(formatTypeNode(typeNode.error));
79
+ if (typeNode.requirements) {
80
+ if (!typeNode.error)
81
+ parts.push("never");
82
+ parts.push(formatTypeNode(typeNode.requirements));
83
+ }
84
+ return `Effect<${parts.join(", ")}>`;
85
+ }
86
+ case "RecordTypeNode": {
87
+ if (typeNode.fields.length === 0)
88
+ return "{}";
89
+ const fields = typeNode.fields
90
+ .map((f) => `${f.name.name}${f.optional ? "?" : ""}: ${formatTypeNode(f.typeAnnotation)}`)
91
+ .join(", ");
92
+ return `{ ${fields} }`;
93
+ }
94
+ case "ArrayTypeNode":
95
+ return `Array<${formatTypeNode(typeNode.elementType)}>`;
96
+ case "UnionTypeNode":
97
+ return typeNode.types.map(formatTypeNode).join(" | ");
98
+ case "IntersectionTypeNode":
99
+ return typeNode.types.map(formatTypeNode).join(" & ");
100
+ case "LiteralTypeNode":
101
+ return typeof typeNode.value === "string"
102
+ ? JSON.stringify(typeNode.value)
103
+ : String(typeNode.value);
104
+ case "ParenthesizedTypeNode":
105
+ return `(${formatTypeNode(typeNode.typeNode)})`;
106
+ case "TypeQueryNode":
107
+ return "typeof ...";
108
+ case "IndexedAccessTypeNode":
109
+ return `${formatTypeNode(typeNode.objectType)}[${formatTypeNode(typeNode.indexType)}]`;
110
+ case "TsEscapeTypeNode":
111
+ return `ts { ${typeNode.code.trim()} }`;
112
+ }
113
+ }
114
+ function inferQuickExprType(expr) {
115
+ switch (expr.kind) {
116
+ case "NumberLiteral":
117
+ return "number";
118
+ case "StringLiteral":
119
+ return "string";
120
+ case "BooleanLiteral":
121
+ return "boolean";
122
+ case "ArrayExpression":
123
+ return "Array<unknown>";
124
+ case "RecordExpression":
125
+ return "{ ... }";
126
+ case "EffectBlockExpression":
127
+ return "Effect<...>";
128
+ case "JSXElement":
129
+ case "JSXSelfClosingElement":
130
+ return "JSX.Element";
131
+ case "FunctionExpression":
132
+ return formatFunctionSignature("fn", expr).replace(/^fn = /, "");
133
+ default:
134
+ return "unknown";
135
+ }
136
+ }
137
+ function formatFunctionSignature(name, fn, explicitType) {
138
+ if (explicitType) {
139
+ return `${name}: ${formatTypeNode(explicitType)}`;
140
+ }
141
+ const tp = fn.typeParams && fn.typeParams.length > 0
142
+ ? `<${fn.typeParams.map((p) => p.name.name).join(", ")}>`
143
+ : "";
144
+ const params = fn.params
145
+ .map((p) => p.typeAnnotation
146
+ ? `${formatBindingTarget(p.name)}: ${formatTypeNode(p.typeAnnotation)}`
147
+ : formatBindingTarget(p.name))
148
+ .join(", ");
149
+ const ret = fn.returnType
150
+ ? formatTypeNode(fn.returnType)
151
+ : fn.body.kind === "BlockStatement"
152
+ ? "unknown"
153
+ : inferQuickExprType(fn.body);
154
+ return `${name} = ${tp}(${params}) => ${ret}`;
155
+ }
156
+ function extractLeadingDocComment(source, oneBasedLine) {
157
+ const lines = source.split(/\r?\n/);
158
+ const commentLines = [];
159
+ let idx = oneBasedLine - 2;
160
+ while (idx >= 0) {
161
+ const trimmed = lines[idx].trim();
162
+ if (trimmed.startsWith("//")) {
163
+ commentLines.push(trimmed.replace(/^\/\/\/?\s?/, ""));
164
+ idx--;
165
+ continue;
166
+ }
167
+ break;
168
+ }
169
+ if (commentLines.length === 0)
170
+ return null;
171
+ return commentLines.reverse().join("\n").trim() || null;
172
+ }
173
+ function formatMarkdownHover(signature, kindLabel, name, docComment, originInfo) {
174
+ const parts = [`\`\`\`funscript\n${signature}\n\`\`\``, "***"];
175
+ const header = originInfo
176
+ ? `**${kindLabel}** \`${name}\` — ${originInfo}`
177
+ : `**${kindLabel}** \`${name}\``;
178
+ parts.push(header);
179
+ if (docComment) {
180
+ parts.push(docComment);
181
+ }
182
+ return parts.join("\n\n");
183
+ }
184
+ function resolveRelativeModule(fromUri, modulePath, documents) {
185
+ if (!modulePath.startsWith("."))
186
+ return null;
187
+ let base;
188
+ try {
189
+ base = resolve(dirname(fileURLToPath(fromUri)), modulePath);
190
+ }
191
+ catch (error) {
192
+ if (!isExpectedUriError(error))
193
+ throw error;
194
+ return null;
195
+ }
196
+ const candidates = [
197
+ base,
198
+ `${base}.fun`,
199
+ `${base}.funs`,
200
+ `${base}.funx`,
201
+ `${base}.ts`,
202
+ `${base}.tsx`,
203
+ resolve(base, "index.fun"),
204
+ resolve(base, "index.funs"),
205
+ resolve(base, "index.funx"),
206
+ ];
207
+ if (documents) {
208
+ for (const doc of documents) {
209
+ try {
210
+ if (candidates.includes(fileURLToPath(doc.uri))) {
211
+ return doc;
212
+ }
213
+ }
214
+ catch (error) {
215
+ if (!isExpectedUriError(error))
216
+ throw error;
217
+ }
218
+ }
219
+ }
220
+ for (const candidate of candidates) {
221
+ try {
222
+ if (existsSync(candidate)) {
223
+ return {
224
+ uri: pathToFileURL(candidate).href,
225
+ text: readFileSync(candidate, "utf8"),
226
+ };
227
+ }
228
+ }
229
+ catch (error) {
230
+ if (!isFileNotFoundError(error) && !isExpectedUriError(error))
231
+ throw error;
232
+ }
233
+ }
234
+ return null;
235
+ }
236
+ function findExportedDeclaration(program, name) {
237
+ for (const entry of program.body) {
238
+ if (entry.kind !== "ExportDeclaration")
239
+ continue;
240
+ if ("id" in entry.declaration &&
241
+ "name" in entry.declaration.id &&
242
+ entry.declaration.id.name === name) {
243
+ return { outer: entry, decl: entry.declaration };
244
+ }
245
+ }
246
+ return null;
247
+ }
248
+ function findImportedDeclaration(program, uri, localName, documents) {
249
+ for (const item of program.body) {
250
+ if (item.kind !== "ImportDeclaration")
251
+ continue;
252
+ const spec = item.specifiers.find((s) => (s.local ?? s.imported).name === localName);
253
+ if (!spec)
254
+ continue;
255
+ const modulePath = item.source.parts
256
+ .map((part) => (part.kind === "StringRawPart" ? part.value : ""))
257
+ .join("");
258
+ const targetDoc = resolveRelativeModule(uri, modulePath, documents);
259
+ if (!targetDoc)
260
+ continue;
261
+ const targetAst = tryParseProgram(targetDoc.text, targetDoc.uri);
262
+ if (!targetAst)
263
+ continue;
264
+ const found = findExportedDeclaration(targetAst, spec.imported.name);
265
+ if (found) {
266
+ return {
267
+ doc: targetDoc,
268
+ modulePath,
269
+ outer: found.outer,
270
+ decl: found.decl,
271
+ };
272
+ }
273
+ }
274
+ return null;
275
+ }
276
+ function formatSchemaSignature(decl, isExported) {
277
+ const prefix = isExported ? "export " : "";
278
+ const tp = decl.typeParams && decl.typeParams.length > 0
279
+ ? `<${decl.typeParams.map((p) => p.name.name).join(", ")}>`
280
+ : "";
281
+ const header = `${prefix}schema ${decl.id.name}${tp}`;
282
+ switch (decl.body.kind) {
283
+ case "RecordSchema": {
284
+ if (decl.body.fields.length === 0)
285
+ return `${header} = {}`;
286
+ const fields = decl.body.fields
287
+ .map((f) => ` ${f.name.name}: ${formatTypeNode(f.typeAnnotation)}`)
288
+ .join("\n");
289
+ return `${header} = {\n${fields}\n}`;
290
+ }
291
+ case "TaggedUnionSchema": {
292
+ const variants = decl.body.variants
293
+ .map((v) => {
294
+ if (v.fields.length === 0)
295
+ return ` | ${v.name.name}`;
296
+ const fields = v.fields
297
+ .map((f) => `${f.name.name}: ${formatTypeNode(f.typeAnnotation)}`)
298
+ .join(", ");
299
+ return ` | ${v.name.name}(${fields})`;
300
+ })
301
+ .join("\n");
302
+ return `${header} =\n${variants}`;
303
+ }
304
+ case "StructuralUnionSchema":
305
+ return `${header} = ${decl.body.members.map(formatTypeNode).join(" | ")}`;
306
+ case "RefinementSchema":
307
+ return `${header} = ${formatTypeNode(decl.body.baseType)} |> ...`;
308
+ case "TypeSignatureSchema":
309
+ return `${header} = ${formatTypeNode(decl.body.signature)}`;
310
+ case "TsDerivedSchema":
311
+ return `${header} = ts ${formatTypeNode(decl.body.targetType)}`;
312
+ case "ImportedTsSchema":
313
+ return `${header} = from ts<${formatTypeNode(decl.body.typeNode)}>`;
314
+ }
315
+ }
316
+ function formatErrorSignature(decl, isExported) {
317
+ const prefix = isExported ? "export " : "";
318
+ if (decl.fields.length === 0) {
319
+ return `${prefix}error ${decl.id.name}`;
320
+ }
321
+ const fields = decl.fields
322
+ .map((f) => `${f.name.name}: ${formatTypeNode(f.typeAnnotation)}`)
323
+ .join(", ");
324
+ return `${prefix}error ${decl.id.name}(${fields})`;
325
+ }
326
+ function formatServiceSignature(decl, isExported) {
327
+ const prefix = isExported ? "export " : "";
328
+ if (decl.members.length === 0) {
329
+ return `${prefix}service ${decl.id.name}`;
330
+ }
331
+ const members = decl.members
332
+ .map((m) => ` ${m.name.name}: ${formatTypeNode(m.signature)}`)
333
+ .join("\n");
334
+ return `${prefix}service ${decl.id.name}\n${members}`;
335
+ }
336
+ function formatTopLevelDeclarationHover(decl, outer, source, originInfo) {
337
+ const isExported = outer.kind === "ExportDeclaration";
338
+ const docComment = extractLeadingDocComment(source, outer.span.start.line);
339
+ switch (decl.kind) {
340
+ case "SchemaDeclaration":
341
+ return formatMarkdownHover(formatSchemaSignature(decl, isExported), "schema", decl.id.name, docComment, originInfo);
342
+ case "ErrorDeclaration":
343
+ return formatMarkdownHover(formatErrorSignature(decl, isExported), "error", decl.id.name, docComment, originInfo);
344
+ case "ServiceDeclaration":
345
+ return formatMarkdownHover(formatServiceSignature(decl, isExported), "service", decl.id.name, docComment, originInfo);
346
+ case "BindingDeclaration": {
347
+ const bindingName = formatBindingTarget(decl.id);
348
+ const prefix = `${isExported ? "export " : ""}${decl.isMut ? "mut " : ""}`;
349
+ if (decl.init.kind === "FunctionExpression") {
350
+ const sig = `${prefix}${formatFunctionSignature(bindingName, decl.init, decl.typeAnnotation)}`;
351
+ return formatMarkdownHover(sig, "function", bindingName, docComment, originInfo);
352
+ }
353
+ const typeStr = decl.typeAnnotation
354
+ ? `: ${formatTypeNode(decl.typeAnnotation)}`
355
+ : ` = ${inferQuickExprType(decl.init)}`;
356
+ return formatMarkdownHover(`${prefix}${bindingName}${typeStr}`, "binding", bindingName, docComment, originInfo);
357
+ }
358
+ }
359
+ }
360
+ function findHoverInAst(source, uri, posLine, posCol, tokens, documents) {
361
+ const program = tryParseProgram(source, uri, tokens);
362
+ if (!program)
363
+ return null;
364
+ const finder = new DefinitionFinder(posLine, posCol);
365
+ const match = finder.find(program);
366
+ if (!match)
367
+ return null;
368
+ const range = spanToRange(match.originNode.span);
369
+ const declNode = match.declarationNode;
370
+ if (declNode.kind === "ExportDeclaration") {
371
+ return {
372
+ contents: {
373
+ kind: MarkupKind.Markdown,
374
+ value: formatTopLevelDeclarationHover(declNode.declaration, declNode, source),
375
+ },
376
+ range,
377
+ };
378
+ }
379
+ if (declNode.kind === "SchemaDeclaration" ||
380
+ declNode.kind === "ErrorDeclaration" ||
381
+ declNode.kind === "ServiceDeclaration" ||
382
+ declNode.kind === "BindingDeclaration") {
383
+ return {
384
+ contents: {
385
+ kind: MarkupKind.Markdown,
386
+ value: formatTopLevelDeclarationHover(declNode, declNode, source),
387
+ },
388
+ range,
389
+ };
390
+ }
391
+ if (declNode.kind === "ImportSpecifier") {
392
+ const spec = declNode;
393
+ const importDecl = program.body.find((entry) => entry.kind === "ImportDeclaration" && entry.specifiers.includes(spec));
394
+ if (!importDecl)
395
+ return null;
396
+ const localName = (spec.local ?? spec.imported).name;
397
+ const imported = findImportedDeclaration(program, uri, localName, documents);
398
+ if (!imported)
399
+ return null;
400
+ return {
401
+ contents: {
402
+ kind: MarkupKind.Markdown,
403
+ value: formatTopLevelDeclarationHover(imported.decl, imported.outer, imported.doc.text, `imported from \`${imported.modulePath}\``),
404
+ },
405
+ range,
406
+ };
407
+ }
408
+ return null;
409
+ }
410
+ function findTokenAtPosition(tokens, posLine, posCol) {
411
+ const lineTokens = [];
412
+ for (let i = 0; i < tokens.length; i++) {
413
+ const t = tokens[i];
414
+ if (t.span.start.line === posLine) {
415
+ lineTokens.push({ token: t, index: i });
416
+ }
417
+ }
418
+ if (lineTokens.length === 0)
419
+ return null;
420
+ for (const entry of lineTokens) {
421
+ if (posCol >= entry.token.span.start.column &&
422
+ posCol < entry.token.span.end.column) {
423
+ return entry;
424
+ }
425
+ }
426
+ for (const entry of lineTokens) {
427
+ if (posCol === entry.token.span.end.column) {
428
+ return entry;
429
+ }
430
+ }
431
+ return null;
432
+ }
433
+ function isJsxPunctuationOrTextToken(type) {
434
+ return (type === TokenType.JSX_TEXT ||
435
+ type === TokenType.JSX_TAG_OPEN ||
436
+ type === TokenType.JSX_TAG_CLOSE ||
437
+ type === TokenType.JSX_SLASH_CLOSE ||
438
+ type === TokenType.JSX_CLOSING_TAG_OPEN ||
439
+ type === TokenType.JSX_ATTRIBUTE_NAME);
440
+ }
441
+ function isJsxTagNameToken(tokens, index) {
442
+ const tok = tokens[index];
443
+ if (tok.type !== TokenType.IDENTIFIER &&
444
+ tok.type !== TokenType.UPPER_IDENTIFIER) {
445
+ return false;
446
+ }
447
+ let i = index - 1;
448
+ while (i >= 1 && tokens[i].type === TokenType.DOT) {
449
+ const prev = tokens[i - 1];
450
+ if (prev.type !== TokenType.IDENTIFIER &&
451
+ prev.type !== TokenType.UPPER_IDENTIFIER) {
452
+ return false;
453
+ }
454
+ i -= 2;
455
+ }
456
+ if (i < 0)
457
+ return false;
458
+ return (tokens[i].type === TokenType.JSX_TAG_OPEN ||
459
+ tokens[i].type === TokenType.JSX_CLOSING_TAG_OPEN);
460
+ }
461
+ function formatTagName(tagName) {
462
+ if (tagName.kind === "Identifier" || tagName.kind === "UpperIdentifier") {
463
+ return tagName.name;
464
+ }
465
+ return `${formatTagName(tagName.object)}.${tagName.property.name}`;
466
+ }
467
+ function findJsxAttributeInList(tagName, attributes, posLine, posCol) {
468
+ for (const attr of attributes) {
469
+ if (attr.kind === "JSXSpreadAttribute") {
470
+ const nested = findJsxAttributeInExpr(attr.argument, posLine, posCol);
471
+ if (nested)
472
+ return nested;
473
+ continue;
474
+ }
475
+ if (isPositionInSpan(posLine, posCol, attr.name.span)) {
476
+ return { tagName, attr };
477
+ }
478
+ if (attr.value?.kind === "JSXExpressionContainer") {
479
+ const nested = findJsxAttributeInExpr(attr.value.expression, posLine, posCol);
480
+ if (nested)
481
+ return nested;
482
+ }
483
+ }
484
+ return null;
485
+ }
486
+ function findJsxAttributeInExpr(expr, posLine, posCol) {
487
+ switch (expr.kind) {
488
+ case "JSXElement": {
489
+ const inAttrs = findJsxAttributeInList(expr.openingElement.name, expr.openingElement.attributes, posLine, posCol);
490
+ if (inAttrs)
491
+ return inAttrs;
492
+ for (const child of expr.children) {
493
+ if (child.kind === "JSXElement" ||
494
+ child.kind === "JSXSelfClosingElement") {
495
+ const nested = findJsxAttributeInExpr(child, posLine, posCol);
496
+ if (nested)
497
+ return nested;
498
+ }
499
+ else if (child.kind === "JSXExpressionContainer") {
500
+ const nested = findJsxAttributeInExpr(child.expression, posLine, posCol);
501
+ if (nested)
502
+ return nested;
503
+ }
504
+ }
505
+ return null;
506
+ }
507
+ case "JSXSelfClosingElement":
508
+ return findJsxAttributeInList(expr.name, expr.attributes, posLine, posCol);
509
+ case "FunctionExpression":
510
+ case "MutBlockExpression":
511
+ return expr.body.kind === "BlockStatement"
512
+ ? findJsxAttributeInBlock(expr.body, posLine, posCol)
513
+ : findJsxAttributeInExpr(expr.body, posLine, posCol);
514
+ case "PipelineExpression":
515
+ case "BinaryExpression":
516
+ return (findJsxAttributeInExpr(expr.left, posLine, posCol) ??
517
+ findJsxAttributeInExpr(expr.right, posLine, posCol));
518
+ case "UnaryExpression":
519
+ return findJsxAttributeInExpr(expr.argument, posLine, posCol);
520
+ case "CallExpression": {
521
+ const inCallee = findJsxAttributeInExpr(expr.callee, posLine, posCol);
522
+ if (inCallee)
523
+ return inCallee;
524
+ for (const arg of expr.args) {
525
+ const inArg = findJsxAttributeInExpr(arg, posLine, posCol);
526
+ if (inArg)
527
+ return inArg;
528
+ }
529
+ return null;
530
+ }
531
+ case "MemberExpression":
532
+ return findJsxAttributeInExpr(expr.object, posLine, posCol);
533
+ case "IndexExpression":
534
+ return (findJsxAttributeInExpr(expr.object, posLine, posCol) ??
535
+ findJsxAttributeInExpr(expr.index, posLine, posCol));
536
+ case "RecordExpression": {
537
+ for (const entry of expr.entries) {
538
+ if (entry.kind === "ShorthandEntry")
539
+ continue;
540
+ const inner = entry.kind === "SpreadEntry" ? entry.argument : entry.value;
541
+ const found = findJsxAttributeInExpr(inner, posLine, posCol);
542
+ if (found)
543
+ return found;
544
+ }
545
+ return null;
546
+ }
547
+ case "ArrayExpression": {
548
+ for (const el of expr.elements) {
549
+ const found = findJsxAttributeInExpr(el, posLine, posCol);
550
+ if (found)
551
+ return found;
552
+ }
553
+ return null;
554
+ }
555
+ case "MatchExpression": {
556
+ const inSubj = expr.scrutinee
557
+ ? findJsxAttributeInExpr(expr.scrutinee, posLine, posCol)
558
+ : null;
559
+ if (inSubj)
560
+ return inSubj;
561
+ for (const arm of expr.arms) {
562
+ if (arm.guard) {
563
+ const inGuard = findJsxAttributeInExpr(arm.guard, posLine, posCol);
564
+ if (inGuard)
565
+ return inGuard;
566
+ }
567
+ const inBody = arm.body.kind === "BlockStatement"
568
+ ? findJsxAttributeInBlock(arm.body, posLine, posCol)
569
+ : findJsxAttributeInExpr(arm.body, posLine, posCol);
570
+ if (inBody)
571
+ return inBody;
572
+ }
573
+ return null;
574
+ }
575
+ case "EffectBlockExpression": {
576
+ for (const stmt of expr.body) {
577
+ if (stmt.kind === "EffectBindStatement" ||
578
+ stmt.kind === "EffectDiscardStatement") {
579
+ const found = findJsxAttributeInExpr(stmt.effect, posLine, posCol);
580
+ if (found)
581
+ return found;
582
+ }
583
+ else if (stmt.kind === "EffectControlFlowStatement") {
584
+ const found = findJsxAttributeInExpr(stmt.statement, posLine, posCol);
585
+ if (found)
586
+ return found;
587
+ }
588
+ else if (stmt.kind === "BindingDeclaration") {
589
+ const found = findJsxAttributeInExpr(stmt.init, posLine, posCol);
590
+ if (found)
591
+ return found;
592
+ }
593
+ else if (stmt.kind === "AssignmentStatement") {
594
+ const found = findJsxAttributeInExpr(stmt.value, posLine, posCol);
595
+ if (found)
596
+ return found;
597
+ }
598
+ else if (stmt.kind === "WhenStatement") {
599
+ const inCond = findJsxAttributeInExpr(stmt.condition, posLine, posCol);
600
+ if (inCond)
601
+ return inCond;
602
+ const inCons = stmt.isEarlyReturn
603
+ ? findJsxAttributeInExpr(stmt.consequent, posLine, posCol)
604
+ : findJsxAttributeInBlock(stmt.consequent, posLine, posCol);
605
+ if (inCons)
606
+ return inCons;
607
+ }
608
+ }
609
+ return findJsxAttributeInExpr(expr.finalExpression, posLine, posCol);
610
+ }
611
+ case "StringLiteral":
612
+ case "TemplateLiteral": {
613
+ for (const part of expr.parts) {
614
+ if (part.kind === "StringInterpolationPart") {
615
+ const found = findJsxAttributeInExpr(part.expression, posLine, posCol);
616
+ if (found)
617
+ return found;
618
+ }
619
+ }
620
+ return null;
621
+ }
622
+ default:
623
+ return null;
624
+ }
625
+ }
626
+ function findJsxAttributeInBlock(block, posLine, posCol) {
627
+ for (const stmt of block.statements) {
628
+ if (stmt.kind === "BindingDeclaration") {
629
+ const found = findJsxAttributeInExpr(stmt.init, posLine, posCol);
630
+ if (found)
631
+ return found;
632
+ }
633
+ else if (stmt.kind === "AssignmentStatement") {
634
+ const found = findJsxAttributeInExpr(stmt.value, posLine, posCol);
635
+ if (found)
636
+ return found;
637
+ }
638
+ else if (stmt.kind === "ExpressionStatement") {
639
+ const found = findJsxAttributeInExpr(stmt.expression, posLine, posCol);
640
+ if (found)
641
+ return found;
642
+ }
643
+ else if (stmt.kind === "ReturnStatement") {
644
+ const found = findJsxAttributeInExpr(stmt.argument, posLine, posCol);
645
+ if (found)
646
+ return found;
647
+ }
648
+ else if (stmt.kind === "WhenStatement") {
649
+ const inCond = findJsxAttributeInExpr(stmt.condition, posLine, posCol);
650
+ if (inCond)
651
+ return inCond;
652
+ const inCons = stmt.isEarlyReturn
653
+ ? findJsxAttributeInExpr(stmt.consequent, posLine, posCol)
654
+ : findJsxAttributeInBlock(stmt.consequent, posLine, posCol);
655
+ if (inCons)
656
+ return inCons;
657
+ }
658
+ }
659
+ return block.finalExpression
660
+ ? findJsxAttributeInExpr(block.finalExpression, posLine, posCol)
661
+ : null;
662
+ }
663
+ function findJsxAttributeInProgram(program, posLine, posCol) {
664
+ for (const top of program.body) {
665
+ const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
666
+ if (inner.kind === "BindingDeclaration") {
667
+ const found = findJsxAttributeInExpr(inner.init, posLine, posCol);
668
+ if (found)
669
+ return found;
670
+ }
671
+ else if (inner.kind === "ExportDefaultDeclaration") {
672
+ const found = findJsxAttributeInExpr(inner.expression, posLine, posCol);
673
+ if (found)
674
+ return found;
675
+ }
676
+ }
677
+ return null;
678
+ }
679
+ function resolveBindingDeclaration(program, source, uri, name, usageLine, usageCol, documents) {
680
+ const def = new DefinitionFinder(usageLine, usageCol).find(program);
681
+ if (def) {
682
+ const declNode = def.declarationNode;
683
+ const raw = declNode.kind === "ExportDeclaration" ? declNode.declaration : declNode;
684
+ if (raw.kind === "BindingDeclaration") {
685
+ return {
686
+ decl: raw,
687
+ ownerProgram: program,
688
+ ownerSource: source,
689
+ ownerUri: uri,
690
+ };
691
+ }
692
+ if (raw.kind === "ImportSpecifier") {
693
+ const localName = (raw.local ?? raw.imported).name;
694
+ const imported = findImportedDeclaration(program, uri, localName, documents);
695
+ if (imported && imported.decl.kind === "BindingDeclaration") {
696
+ const ownerProgram = tryParseProgram(imported.doc.text, imported.doc.uri);
697
+ if (ownerProgram) {
698
+ return {
699
+ decl: imported.decl,
700
+ ownerProgram,
701
+ ownerSource: imported.doc.text,
702
+ ownerUri: imported.doc.uri,
703
+ originInfo: `imported from \`${imported.modulePath}\``,
704
+ };
705
+ }
706
+ }
707
+ }
708
+ }
709
+ for (const top of program.body) {
710
+ const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
711
+ if (inner.kind === "BindingDeclaration" &&
712
+ "name" in inner.id &&
713
+ inner.id.name === name) {
714
+ return {
715
+ decl: inner,
716
+ ownerProgram: program,
717
+ ownerSource: source,
718
+ ownerUri: uri,
719
+ };
720
+ }
721
+ }
722
+ const imported = findImportedDeclaration(program, uri, name, documents);
723
+ if (imported && imported.decl.kind === "BindingDeclaration") {
724
+ const ownerProgram = tryParseProgram(imported.doc.text, imported.doc.uri);
725
+ if (ownerProgram) {
726
+ return {
727
+ decl: imported.decl,
728
+ ownerProgram,
729
+ ownerSource: imported.doc.text,
730
+ ownerUri: imported.doc.uri,
731
+ originInfo: `imported from \`${imported.modulePath}\``,
732
+ };
733
+ }
734
+ }
735
+ return null;
736
+ }
737
+ function resolveRecordMemberEntry(program, source, uri, objectName, memberName, usageLine, usageCol, documents) {
738
+ const resolved = resolveBindingDeclaration(program, source, uri, objectName, usageLine, usageCol, documents);
739
+ if (!resolved || resolved.decl.init.kind !== "RecordExpression") {
740
+ return null;
741
+ }
742
+ const rec = resolved.decl.init;
743
+ const field = rec.entries.find((e) => e.kind === "FieldEntry" && e.key.name === memberName);
744
+ if (!field || field.kind !== "FieldEntry") {
745
+ return null;
746
+ }
747
+ return {
748
+ expr: field.value,
749
+ ownerProgram: resolved.ownerProgram,
750
+ ownerSource: resolved.ownerSource,
751
+ ownerUri: resolved.ownerUri,
752
+ originInfo: resolved.originInfo,
753
+ };
754
+ }
755
+ function findPropInTypeNode(typeNode, propName, ownerProgram, ownerSource, ownerUri, documents) {
756
+ if (typeNode.kind === "RecordTypeNode") {
757
+ const field = typeNode.fields.find((f) => f.name.name === propName);
758
+ if (!field)
759
+ return null;
760
+ return {
761
+ typeText: formatTypeNode(field.typeAnnotation),
762
+ docComment: extractLeadingDocComment(ownerSource, field.span.start.line),
763
+ };
764
+ }
765
+ if (typeNode.kind === "TypeReferenceNode") {
766
+ const schemaName = typeNode.name.name;
767
+ let targetSchema = null;
768
+ let schemaSource = ownerSource;
769
+ for (const top of ownerProgram.body) {
770
+ const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
771
+ if (inner.kind === "SchemaDeclaration" && inner.id.name === schemaName) {
772
+ targetSchema = inner;
773
+ break;
774
+ }
775
+ }
776
+ if (!targetSchema) {
777
+ const imported = findImportedDeclaration(ownerProgram, ownerUri, schemaName, documents);
778
+ if (imported && imported.decl.kind === "SchemaDeclaration") {
779
+ targetSchema = imported.decl;
780
+ schemaSource = imported.doc.text;
781
+ }
782
+ }
783
+ if (!targetSchema)
784
+ return null;
785
+ if (targetSchema.body.kind === "RecordSchema") {
786
+ const field = targetSchema.body.fields.find((f) => f.name.name === propName);
787
+ if (!field)
788
+ return null;
789
+ return {
790
+ typeText: formatTypeNode(field.typeAnnotation),
791
+ docComment: extractLeadingDocComment(schemaSource, field.span.start.line),
792
+ };
793
+ }
794
+ }
795
+ return null;
796
+ }
797
+ function findJsxAttributeHover(source, uri, posLine, posCol, tokens, documents) {
798
+ const program = tryParseProgram(source, uri, tokens);
799
+ if (!program)
800
+ return null;
801
+ const hit = findJsxAttributeInProgram(program, posLine, posCol);
802
+ if (!hit || hit.attr.kind !== "JSXAttribute")
803
+ return null;
804
+ const { tagName, attr } = hit;
805
+ let paramType;
806
+ let ownerProgram = null;
807
+ let ownerSource = source;
808
+ let ownerUri = uri;
809
+ let originInfo;
810
+ if (tagName.kind === "MemberExpression" &&
811
+ (tagName.object.kind === "Identifier" ||
812
+ tagName.object.kind === "UpperIdentifier")) {
813
+ const member = resolveRecordMemberEntry(program, source, uri, tagName.object.name, tagName.property.name, tagName.object.span.start.line, tagName.object.span.start.column, documents);
814
+ if (member && member.expr.kind === "FunctionExpression") {
815
+ paramType = member.expr.params[0]?.typeAnnotation;
816
+ ownerProgram = member.ownerProgram;
817
+ ownerSource = member.ownerSource;
818
+ ownerUri = member.ownerUri;
819
+ originInfo = member.originInfo;
820
+ }
821
+ }
822
+ else if (tagName.kind === "Identifier" ||
823
+ tagName.kind === "UpperIdentifier") {
824
+ const resolved = resolveBindingDeclaration(program, source, uri, tagName.name, tagName.span.start.line, tagName.span.start.column, documents);
825
+ if (resolved) {
826
+ ownerProgram = resolved.ownerProgram;
827
+ ownerSource = resolved.ownerSource;
828
+ ownerUri = resolved.ownerUri;
829
+ originInfo = resolved.originInfo;
830
+ if (resolved.decl.init.kind === "FunctionExpression") {
831
+ paramType = resolved.decl.init.params[0]?.typeAnnotation;
832
+ }
833
+ else if (resolved.decl.typeAnnotation?.kind === "FunctionTypeNode") {
834
+ paramType = resolved.decl.typeAnnotation.params[0]?.typeAnnotation;
835
+ }
836
+ }
837
+ }
838
+ if (!paramType || !ownerProgram)
839
+ return null;
840
+ const prop = findPropInTypeNode(paramType, attr.name.name, ownerProgram, ownerSource, ownerUri, documents);
841
+ if (!prop)
842
+ return null;
843
+ const fullTag = formatTagName(tagName);
844
+ return {
845
+ contents: {
846
+ kind: MarkupKind.Markdown,
847
+ value: formatMarkdownHover(`${fullTag}.${attr.name.name}: ${prop.typeText}`, "prop", attr.name.name, prop.docComment, originInfo),
848
+ },
849
+ range: spanToRange(attr.name.span),
850
+ };
851
+ }
852
+ function formatRecordMemberHover(tokens, matchedIndex, source, uri, documents) {
853
+ if (matchedIndex < 2 ||
854
+ tokens[matchedIndex - 1].type !== TokenType.DOT ||
855
+ (tokens[matchedIndex - 2].type !== TokenType.UPPER_IDENTIFIER &&
856
+ tokens[matchedIndex - 2].type !== TokenType.IDENTIFIER)) {
857
+ return null;
858
+ }
859
+ const program = tryParseProgram(source, uri, tokens);
860
+ if (!program)
861
+ return null;
862
+ const objTok = tokens[matchedIndex - 2];
863
+ const token = tokens[matchedIndex];
864
+ const recMember = resolveRecordMemberEntry(program, source, uri, objTok.value, token.value, objTok.span.start.line, objTok.span.start.column, documents);
865
+ if (!recMember)
866
+ return null;
867
+ const sig = recMember.expr.kind === "FunctionExpression"
868
+ ? formatFunctionSignature(`${objTok.value}.${token.value}`, recMember.expr)
869
+ : `${objTok.value}.${token.value}: ${inferQuickExprType(recMember.expr)}`;
870
+ const docComment = extractLeadingDocComment(recMember.ownerSource, recMember.expr.span.start.line);
871
+ return {
872
+ contents: {
873
+ kind: MarkupKind.Markdown,
874
+ value: formatMarkdownHover(sig, recMember.expr.kind === "FunctionExpression" ? "function" : "property", `${objTok.value}.${token.value}`, docComment, recMember.originInfo),
875
+ },
876
+ range: spanToRange(token.span),
877
+ };
878
+ }
879
+ function findJsxTagHover(tokens, matchedIndex, posLine, posCol, source, uri, skipSymbol, documents) {
880
+ const token = tokens[matchedIndex];
881
+ const isMemberSegment = matchedIndex >= 2 && tokens[matchedIndex - 1].type === TokenType.DOT;
882
+ const hasMemberSuffix = matchedIndex + 2 < tokens.length &&
883
+ tokens[matchedIndex + 1].type === TokenType.DOT;
884
+ if (isMemberSegment) {
885
+ const memberHover = formatRecordMemberHover(tokens, matchedIndex, source, uri, documents);
886
+ if (memberHover)
887
+ return memberHover;
888
+ }
889
+ else if (token.type === TokenType.UPPER_IDENTIFIER || hasMemberSuffix) {
890
+ const astHover = findHoverInAst(source, uri, posLine, posCol, tokens, documents);
891
+ if (astHover)
892
+ return astHover;
893
+ }
894
+ else {
895
+ // Lowercase intrinsic JSX tag (e.g. `<div>`, `<span>`)
896
+ return null;
897
+ }
898
+ if (!skipSymbol && posCol < token.span.end.column) {
899
+ return symbolHover(source, uri, token);
900
+ }
901
+ return null;
902
+ }
903
+ function symbolHover(source, uri, token, companion) {
21
904
  if (token.type !== TokenType.IDENTIFIER &&
22
905
  token.type !== TokenType.UPPER_IDENTIFIER)
23
906
  return null;
@@ -25,7 +908,7 @@ function symbolHover(source, uri, token) {
25
908
  const filename = uri.startsWith("file:") ? fileURLToPath(uri) : uri;
26
909
  const context = new TypeScriptCompilationContext(filename);
27
910
  const result = Effect.runSync(compileString(source, filename, { context, sourcemap: false }));
28
- return symbolHoverFromResult(source, token, context, result);
911
+ return symbolHoverFromResult(source, token, context, result, companion);
29
912
  }
30
913
  catch (error) {
31
914
  if (!isExpectedHoverError(error))
@@ -33,8 +916,28 @@ function symbolHover(source, uri, token) {
33
916
  return null;
34
917
  }
35
918
  }
36
- function symbolHoverFromResult(source, token, context, result) {
919
+ function symbolHoverFromResult(source, token, context, result, companion) {
37
920
  try {
921
+ const schemaDeclaration = result.ast.body.flatMap((entry) => {
922
+ const decl = entry.kind === "ExportDeclaration" ? entry.declaration : entry;
923
+ return decl.kind === "SchemaDeclaration" &&
924
+ decl.body.kind !== "RecordSchema" &&
925
+ decl.body.kind !== "ImportedTsSchema" &&
926
+ decl.id.span.start.offset === token.span.start.offset
927
+ ? [decl]
928
+ : [];
929
+ });
930
+ if (schemaDeclaration.length === 1) {
931
+ const decl = schemaDeclaration[0];
932
+ const signature = source.slice(decl.id.span.start.offset, decl.body.span.end.offset);
933
+ return {
934
+ contents: {
935
+ kind: MarkupKind.Markdown,
936
+ value: `\`\`\`fun\nschema ${signature}\n\`\`\``,
937
+ },
938
+ range: spanToRange(token.span),
939
+ };
940
+ }
38
941
  const schema = result.ast.body.flatMap((entry) => {
39
942
  const decl = entry.kind === "ExportDeclaration" ? entry.declaration : entry;
40
943
  return decl.kind === "SchemaDeclaration" &&
@@ -71,7 +974,13 @@ function symbolHoverFromResult(source, token, context, result) {
71
974
  const found = new Map();
72
975
  const candidates = [];
73
976
  const visit = (node) => {
74
- if (ts.isIdentifier(node) && node.text === token.value) {
977
+ if (ts.isIdentifier(node) &&
978
+ node.text === token.value &&
979
+ (!companion ||
980
+ (ts.isPropertyAccessExpression(node.parent) &&
981
+ node.parent.name === node &&
982
+ ts.isIdentifier(node.parent.expression) &&
983
+ node.parent.expression.text === companion))) {
75
984
  const symbol = checked.checker.getSymbolAtLocation(node);
76
985
  if (symbol) {
77
986
  found.set(symbol, node);
@@ -107,7 +1016,45 @@ function symbolHoverFromResult(source, token, context, result) {
107
1016
  symbol = candidates[0].symbol;
108
1017
  node = candidates[0].node;
109
1018
  }
110
- const type = checked.checker.typeToString(checked.checker.getTypeOfSymbolAtLocation(symbol, node), node, ts.TypeFormatFlags.NoTruncation);
1019
+ const valueType = checked.checker.getTypeOfSymbolAtLocation(symbol, node);
1020
+ const resolvedType = valueType.flags & ts.TypeFlags.Any &&
1021
+ symbol.flags & ts.SymbolFlags.TypeAlias
1022
+ ? checked.checker.getDeclaredTypeOfSymbol(symbol)
1023
+ : valueType;
1024
+ if (resolvedType.flags & ts.TypeFlags.Any ||
1025
+ checked.checker.typeToString(resolvedType, node) === token.value ||
1026
+ checked.checker
1027
+ .typeToString(resolvedType, node)
1028
+ .startsWith(`${token.value}<`)) {
1029
+ const location = findDefinition(source, "file:///hover.fun", {
1030
+ line: token.span.start.line - 1,
1031
+ character: token.span.start.column - 1,
1032
+ }, true);
1033
+ const target = Array.isArray(location)
1034
+ ? location[0]?.targetSelectionRange.start
1035
+ : undefined;
1036
+ const declaration = result.ast.body.flatMap((entry) => {
1037
+ const decl = entry.kind === "ExportDeclaration" ? entry.declaration : entry;
1038
+ return decl.kind === "SchemaDeclaration" &&
1039
+ target &&
1040
+ decl.id.span.start.line - 1 === target.line &&
1041
+ decl.id.span.start.column - 1 === target.character
1042
+ ? [decl]
1043
+ : [];
1044
+ });
1045
+ if (declaration.length === 1) {
1046
+ const decl = declaration[0];
1047
+ const signature = source.slice(decl.id.span.start.offset, decl.body.span.end.offset);
1048
+ return {
1049
+ contents: {
1050
+ kind: MarkupKind.Markdown,
1051
+ value: `\`\`\`fun\nschema ${signature}\n\`\`\``,
1052
+ },
1053
+ range: spanToRange(token.span),
1054
+ };
1055
+ }
1056
+ }
1057
+ const type = checked.checker.typeToString(resolvedType, node, ts.TypeFormatFlags.NoTruncation);
111
1058
  const documented = symbol.flags & ts.SymbolFlags.Alias
112
1059
  ? checked.checker.getAliasedSymbol(symbol)
113
1060
  : symbol;
@@ -211,42 +1158,21 @@ function importedSchemaHover(source, uri, position) {
211
1158
  return null;
212
1159
  }
213
1160
  }
214
- function isWordChar(ch) {
215
- return /[A-Za-z0-9_]/.test(ch);
216
- }
217
- function findHoverInTokens(tokens, posLine, posCol, currentLine, source, uri, skipSymbol = false) {
218
- // Find token on posLine that strictly or best matches posCol
219
- const lineTokens = [];
220
- for (let i = 0; i < tokens.length; i++) {
221
- const t = tokens[i];
222
- if (t.span.start.line === posLine) {
223
- lineTokens.push({ token: t, index: i });
224
- }
225
- }
226
- if (lineTokens.length === 0) {
1161
+ function findHoverInTokens(tokens, posLine, posCol, currentLine, source, uri, skipSymbol = false, documents) {
1162
+ const matched = findTokenAtPosition(tokens, posLine, posCol);
1163
+ if (!matched) {
227
1164
  return null;
228
1165
  }
229
- // 1. Check for token that strictly encompasses posCol
230
- let matchedIndex = -1;
231
- for (const { token, index } of lineTokens) {
232
- if (posCol >= token.span.start.column && posCol < token.span.end.column) {
233
- matchedIndex = index;
234
- break;
235
- }
1166
+ const { token, index: matchedIndex } = matched;
1167
+ if (token.type === TokenType.JSX_ATTRIBUTE_NAME) {
1168
+ return findJsxAttributeHover(source, uri, posLine, posCol, tokens, documents);
236
1169
  }
237
- // 2. If no strict match, check if cursor is at token end boundary
238
- if (matchedIndex === -1) {
239
- for (const { token, index } of lineTokens) {
240
- if (posCol === token.span.end.column) {
241
- matchedIndex = index;
242
- break;
243
- }
244
- }
245
- }
246
- if (matchedIndex === -1) {
1170
+ if (isJsxPunctuationOrTextToken(token.type)) {
247
1171
  return null;
248
1172
  }
249
- const token = tokens[matchedIndex];
1173
+ if (isJsxTagNameToken(tokens, matchedIndex)) {
1174
+ return findJsxTagHover(tokens, matchedIndex, posLine, posCol, source, uri, skipSymbol, documents);
1175
+ }
250
1176
  // Case A: token is a member after a dot (e.g. `succeed` in `Effect.succeed` or `scoped` in `Layer.scoped`)
251
1177
  if (matchedIndex >= 2 &&
252
1178
  tokens[matchedIndex - 1].type === TokenType.DOT &&
@@ -357,10 +1283,15 @@ function findHoverInTokens(tokens, posLine, posCol, currentLine, source, uri, sk
357
1283
  const ast = new Parser(tokens, filename, source).parse();
358
1284
  const resolution = inferPipelineCompanions(ast, new TypeScriptCompilationContext(filename)).stageResolutions.get(token.span.start.offset);
359
1285
  if (resolution) {
1286
+ const resolved = `${resolution.module}.${resolution.method}`;
1287
+ const typedHover = skipSymbol
1288
+ ? null
1289
+ : symbolHover(source, uri, token, resolution.module);
1290
+ const typedDetails = typedHover?.contents;
360
1291
  return {
361
1292
  contents: {
362
1293
  kind: MarkupKind.Markdown,
363
- value: `Resolves to \`${resolution.module}.${resolution.method}\`.`,
1294
+ value: `Resolves to \`${resolved}\`.${typeof typedDetails === "object" && "value" in typedDetails ? `\n\n${typedDetails.value}` : ""}`,
364
1295
  },
365
1296
  range: spanToRange(token.span),
366
1297
  };
@@ -401,7 +1332,34 @@ function findHoverInTokens(tokens, posLine, posCol, currentLine, source, uri, sk
401
1332
  }
402
1333
  return null;
403
1334
  }
404
- function findHoverInLineText(currentLine, lineIndex, charIndex) {
1335
+ function isSuppressedInFunxLineFallback(lines, lineIndex, charIndex, uri) {
1336
+ if (!uri.endsWith(".funx"))
1337
+ return false;
1338
+ const currentLine = lines[lineIndex] ?? "";
1339
+ const upToCursor = lines
1340
+ .slice(0, lineIndex)
1341
+ .concat(currentLine.slice(0, charIndex))
1342
+ .join("\n");
1343
+ const ctx = detectJsxContext(upToCursor);
1344
+ if (ctx.kind !== "normal")
1345
+ return true;
1346
+ if (charIndex < currentLine.length) {
1347
+ const throughChar = lines
1348
+ .slice(0, lineIndex)
1349
+ .concat(currentLine.slice(0, charIndex + 1))
1350
+ .join("\n");
1351
+ if (detectJsxContext(throughChar).kind !== "normal") {
1352
+ return true;
1353
+ }
1354
+ }
1355
+ return false;
1356
+ }
1357
+ function findHoverInLineText(currentLine, lineIndex, charIndex, lines, uri) {
1358
+ if (lines &&
1359
+ uri &&
1360
+ isSuppressedInFunxLineFallback(lines, lineIndex, charIndex, uri)) {
1361
+ return null;
1362
+ }
405
1363
  // 1. Check multi-character operators first (e.g. `???`, `|>`, `<-`, `=>`, and banned symbols)
406
1364
  const bannedOps = Object.keys(BANNED_SYMBOLS);
407
1365
  const operators = [
@@ -582,10 +1540,14 @@ function findHoverInLineText(currentLine, lineIndex, charIndex) {
582
1540
  }
583
1541
  return null;
584
1542
  }
585
- export function findHover(source, uri, position, skipSymbol = false) {
1543
+ export function findHover(source, uri, position, skipSymbolOrDocuments = false, documents) {
586
1544
  if (!source || source.trim().length === 0) {
587
1545
  return null;
588
1546
  }
1547
+ const skipSymbol = typeof skipSymbolOrDocuments === "boolean" ? skipSymbolOrDocuments : false;
1548
+ const resolvedDocuments = Array.isArray(skipSymbolOrDocuments)
1549
+ ? skipSymbolOrDocuments
1550
+ : documents;
589
1551
  const lines = source.split("\n");
590
1552
  const lineIndex = position.line;
591
1553
  const charIndex = position.character;
@@ -613,13 +1575,21 @@ export function findHover(source, uri, position, skipSymbol = false) {
613
1575
  const importedHover = importedSchemaHover(source, uri, position);
614
1576
  if (importedHover)
615
1577
  return importedHover;
616
- const hoverFromTokens = findHoverInTokens(tokens, posLine, posCol, currentLine, source, uri, skipSymbol);
1578
+ const hoverFromTokens = findHoverInTokens(tokens, posLine, posCol, currentLine, source, uri, skipSymbol, resolvedDocuments);
617
1579
  if (hoverFromTokens) {
618
1580
  return hoverFromTokens;
619
1581
  }
1582
+ const matched = findTokenAtPosition(tokens, posLine, posCol);
1583
+ if (matched &&
1584
+ (isJsxPunctuationOrTextToken(matched.token.type) ||
1585
+ isJsxTagNameToken(tokens, matched.index) ||
1586
+ matched.token.type === TokenType.STRING ||
1587
+ matched.token.type === TokenType.STRING_PART)) {
1588
+ return null;
1589
+ }
620
1590
  }
621
1591
  // 2. Fallback to line text-based inspection (e.g. if lexer threw or comments/unparsed code)
622
- return findHoverInLineText(currentLine, lineIndex, charIndex);
1592
+ return findHoverInLineText(currentLine, lineIndex, charIndex, lines, uri);
623
1593
  }
624
1594
  /** Async hover retains synchronous behavior for ordinary sources and compiles Wasm blocks when needed. */
625
1595
  export async function findHoverAsync(source, uri, position) {