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.
- package/README.md +23 -5
- package/dist/ast/types.d.ts.map +1 -1
- package/dist/ast/types.js.map +1 -1
- package/dist/ast/walk.d.ts.map +1 -1
- package/dist/ast/walk.js.map +1 -1
- package/dist/cli/build-bun.d.ts.map +1 -1
- package/dist/cli/build-bun.js.map +1 -1
- package/dist/cli/build-watch.d.ts.map +1 -1
- package/dist/cli/build-watch.js +9 -27
- package/dist/cli/build-watch.js.map +1 -1
- package/dist/cli/build.d.ts +1 -1
- package/dist/cli/build.d.ts.map +1 -1
- package/dist/cli/build.js +3 -58
- package/dist/cli/build.js.map +1 -1
- package/dist/cli/check-policy.d.ts +9 -0
- package/dist/cli/check-policy.d.ts.map +1 -0
- package/dist/cli/check-policy.js +39 -0
- package/dist/cli/check-policy.js.map +1 -0
- package/dist/cli/check.d.ts.map +1 -1
- package/dist/cli/check.js +16 -30
- package/dist/cli/check.js.map +1 -1
- package/dist/cli/commands.d.ts.map +1 -1
- package/dist/cli/commands.js +11 -0
- package/dist/cli/commands.js.map +1 -1
- package/dist/cli/doc.d.ts.map +1 -1
- package/dist/cli/doc.js.map +1 -1
- package/dist/cli/doctor.d.ts.map +1 -1
- package/dist/cli/doctor.js +5 -7
- package/dist/cli/doctor.js.map +1 -1
- package/dist/cli/emit.d.ts +1 -1
- package/dist/cli/emit.d.ts.map +1 -1
- package/dist/cli/emit.js.map +1 -1
- package/dist/cli/explain.d.ts.map +1 -1
- package/dist/cli/explain.js.map +1 -1
- package/dist/cli/fmt.d.ts.map +1 -1
- package/dist/cli/fmt.js.map +1 -1
- package/dist/cli/index.d.ts.map +1 -1
- package/dist/cli/index.js +3 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/init.d.ts +1 -1
- package/dist/cli/init.d.ts.map +1 -1
- package/dist/cli/init.js +66 -21
- package/dist/cli/init.js.map +1 -1
- package/dist/cli/io.d.ts.map +1 -1
- package/dist/cli/io.js.map +1 -1
- package/dist/cli/pipeline-style.d.ts.map +1 -1
- package/dist/cli/pipeline-style.js.map +1 -1
- package/dist/cli/query.d.ts +3 -0
- package/dist/cli/query.d.ts.map +1 -0
- package/dist/cli/query.js +152 -0
- package/dist/cli/query.js.map +1 -0
- package/dist/cli/repl.d.ts.map +1 -1
- package/dist/cli/repl.js.map +1 -1
- package/dist/cli/run.d.ts.map +1 -1
- package/dist/cli/run.js +2 -29
- package/dist/cli/run.js.map +1 -1
- package/dist/cli/test.d.ts +1 -1
- package/dist/cli/test.d.ts.map +1 -1
- package/dist/cli/test.js.map +1 -1
- package/dist/cli/tsc.d.ts.map +1 -1
- package/dist/cli/tsc.js +6 -8
- package/dist/cli/tsc.js.map +1 -1
- package/dist/cli/typecheck.d.ts.map +1 -1
- package/dist/cli/typecheck.js.map +1 -1
- package/dist/compiler/ast-inspection.d.ts.map +1 -1
- package/dist/compiler/ast-inspection.js.map +1 -1
- package/dist/compiler/boolean-operators.d.ts.map +1 -1
- package/dist/compiler/boolean-operators.js +12 -2
- package/dist/compiler/boolean-operators.js.map +1 -1
- package/dist/compiler/check.d.ts.map +1 -1
- package/dist/compiler/check.js +113 -131
- package/dist/compiler/check.js.map +1 -1
- package/dist/compiler/diagnostics-json.d.ts +73 -0
- package/dist/compiler/diagnostics-json.d.ts.map +1 -0
- package/dist/compiler/diagnostics-json.js +957 -0
- package/dist/compiler/diagnostics-json.js.map +1 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -1
- package/dist/compiler/diagnostics.js.map +1 -1
- package/dist/compiler/effect-mutation-rule.d.ts.map +1 -1
- package/dist/compiler/effect-mutation-rule.js.map +1 -1
- package/dist/compiler/entry-rules.d.ts.map +1 -1
- package/dist/compiler/entry-rules.js.map +1 -1
- package/dist/compiler/escape-audit.d.ts +46 -0
- package/dist/compiler/escape-audit.d.ts.map +1 -0
- package/dist/compiler/escape-audit.js +682 -0
- package/dist/compiler/escape-audit.js.map +1 -0
- package/dist/compiler/incremental-build.d.ts.map +1 -1
- package/dist/compiler/incremental-build.js.map +1 -1
- package/dist/compiler/incremental-dependencies.d.ts.map +1 -1
- package/dist/compiler/incremental-dependencies.js.map +1 -1
- package/dist/compiler/js-interop-nullability.d.ts.map +1 -1
- package/dist/compiler/js-interop-nullability.js.map +1 -1
- package/dist/compiler/modules/output-collisions.d.ts.map +1 -1
- package/dist/compiler/modules/output-collisions.js.map +1 -1
- package/dist/compiler/modules/output-plan.d.ts.map +1 -1
- package/dist/compiler/modules/output-plan.js +10 -5
- package/dist/compiler/modules/output-plan.js.map +1 -1
- package/dist/compiler/modules/resolution.d.ts.map +1 -1
- package/dist/compiler/modules/resolution.js +2 -1
- package/dist/compiler/modules/resolution.js.map +1 -1
- package/dist/compiler/modules/source-files.d.ts +5 -0
- package/dist/compiler/modules/source-files.d.ts.map +1 -0
- package/dist/compiler/modules/source-files.js +13 -0
- package/dist/compiler/modules/source-files.js.map +1 -0
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -1
- package/dist/compiler/numeric-comparisons.js +13 -7
- package/dist/compiler/numeric-comparisons.js.map +1 -1
- package/dist/compiler/optional-arguments.d.ts.map +1 -1
- package/dist/compiler/optional-arguments.js.map +1 -1
- package/dist/compiler/package-fingerprint.d.ts.map +1 -1
- package/dist/compiler/package-fingerprint.js.map +1 -1
- package/dist/compiler/package-record-contracts.d.ts.map +1 -1
- package/dist/compiler/package-record-contracts.js.map +1 -1
- package/dist/compiler/pipelines/catalog.d.ts.map +1 -1
- package/dist/compiler/pipelines/catalog.js.map +1 -1
- package/dist/compiler/pipelines/companions.d.ts.map +1 -1
- package/dist/compiler/pipelines/companions.js.map +1 -1
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -1
- package/dist/compiler/pipelines/resolution.js +24 -23
- package/dist/compiler/pipelines/resolution.js.map +1 -1
- package/dist/compiler/project-config.d.ts.map +1 -1
- package/dist/compiler/project-config.js +29 -19
- package/dist/compiler/project-config.js.map +1 -1
- package/dist/compiler/query.d.ts +53 -0
- package/dist/compiler/query.d.ts.map +1 -0
- package/dist/compiler/query.js +781 -0
- package/dist/compiler/query.js.map +1 -0
- package/dist/compiler/record-contracts.d.ts.map +1 -1
- package/dist/compiler/record-contracts.js.map +1 -1
- package/dist/compiler/rules/control-flow.d.ts.map +1 -1
- package/dist/compiler/rules/control-flow.js.map +1 -1
- package/dist/compiler/rules/diagnostic.d.ts.map +1 -1
- package/dist/compiler/rules/diagnostic.js.map +1 -1
- package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -1
- package/dist/compiler/rules/module-scope-refs.js.map +1 -1
- package/dist/compiler/rules/resource-escape.d.ts +7 -0
- package/dist/compiler/rules/resource-escape.d.ts.map +1 -0
- package/dist/compiler/rules/resource-escape.js +146 -0
- package/dist/compiler/rules/resource-escape.js.map +1 -0
- package/dist/compiler/rules/resource-providers.d.ts +19 -0
- package/dist/compiler/rules/resource-providers.d.ts.map +1 -0
- package/dist/compiler/rules/resource-providers.js +222 -0
- package/dist/compiler/rules/resource-providers.js.map +1 -0
- package/dist/compiler/schemas/analysis.d.ts.map +1 -1
- package/dist/compiler/schemas/analysis.js.map +1 -1
- package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -1
- package/dist/compiler/schemas/imported-record-functions.js.map +1 -1
- package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -1
- package/dist/compiler/schemas/imported-schemas.js.map +1 -1
- package/dist/compiler/source-map.d.ts.map +1 -1
- package/dist/compiler/source-map.js +2 -7
- package/dist/compiler/source-map.js.map +1 -1
- package/dist/compiler/type-view-paths.d.ts +6 -0
- package/dist/compiler/type-view-paths.d.ts.map +1 -0
- package/dist/compiler/type-view-paths.js +12 -0
- package/dist/compiler/type-view-paths.js.map +1 -0
- package/dist/compiler/typescript-context.d.ts.map +1 -1
- package/dist/compiler/typescript-context.js +5 -7
- package/dist/compiler/typescript-context.js.map +1 -1
- package/dist/compiler.d.ts.map +1 -1
- package/dist/compiler.js.map +1 -1
- package/dist/emitter/assemblyscript.d.ts.map +1 -1
- package/dist/emitter/assemblyscript.js +120 -136
- package/dist/emitter/assemblyscript.js.map +1 -1
- package/dist/emitter/declarations.d.ts.map +1 -1
- package/dist/emitter/declarations.js.map +1 -1
- package/dist/emitter/emitter.d.ts +3 -1
- package/dist/emitter/emitter.d.ts.map +1 -1
- package/dist/emitter/emitter.js +10 -1
- package/dist/emitter/emitter.js.map +1 -1
- package/dist/emitter/imports.d.ts.map +1 -1
- package/dist/emitter/imports.js.map +1 -1
- package/dist/emitter/indent.d.ts.map +1 -1
- package/dist/emitter/indent.js.map +1 -1
- package/dist/emitter/jsx.d.ts.map +1 -1
- package/dist/emitter/jsx.js.map +1 -1
- package/dist/emitter/local-bindings.d.ts.map +1 -1
- package/dist/emitter/local-bindings.js.map +1 -1
- package/dist/emitter/match.d.ts.map +1 -1
- package/dist/emitter/match.js.map +1 -1
- package/dist/emitter/runtime-helpers.d.ts.map +1 -1
- package/dist/emitter/runtime-helpers.js.map +1 -1
- package/dist/emitter/schemas.d.ts.map +1 -1
- package/dist/emitter/schemas.js.map +1 -1
- package/dist/emitter/statements.d.ts +1 -0
- package/dist/emitter/statements.d.ts.map +1 -1
- package/dist/emitter/statements.js +1 -0
- package/dist/emitter/statements.js.map +1 -1
- package/dist/emitter/tagged-match.d.ts.map +1 -1
- package/dist/emitter/tagged-match.js.map +1 -1
- package/dist/emitter/types.d.ts.map +1 -1
- package/dist/emitter/types.js.map +1 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/formatter/comments.d.ts.map +1 -1
- package/dist/formatter/comments.js +13 -0
- package/dist/formatter/comments.js.map +1 -1
- package/dist/formatter/index.d.ts +9 -0
- package/dist/formatter/index.d.ts.map +1 -1
- package/dist/formatter/index.js +215 -5
- package/dist/formatter/index.js.map +1 -1
- package/dist/formatter/operator-precedence.d.ts.map +1 -1
- package/dist/formatter/operator-precedence.js.map +1 -1
- package/dist/formatter/prettier.d.ts.map +1 -1
- package/dist/formatter/prettier.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/interop/callback.d.ts.map +1 -1
- package/dist/interop/callback.js.map +1 -1
- package/dist/interop/js.d.ts.map +1 -1
- package/dist/interop/js.js.map +1 -1
- package/dist/interop/record.d.ts.map +1 -1
- package/dist/interop/record.js.map +1 -1
- package/dist/interop/valibot.d.ts.map +1 -1
- package/dist/interop/valibot.js.map +1 -1
- package/dist/interop/zod.d.ts.map +1 -1
- package/dist/interop/zod.js.map +1 -1
- package/dist/lexer/lexer.d.ts +1 -0
- package/dist/lexer/lexer.d.ts.map +1 -1
- package/dist/lexer/lexer.js +26 -10
- package/dist/lexer/lexer.js.map +1 -1
- package/dist/lexer/tokens.d.ts.map +1 -1
- package/dist/lexer/tokens.js.map +1 -1
- package/dist/lsp/code-action-worker.d.ts.map +1 -1
- package/dist/lsp/code-action-worker.js.map +1 -1
- package/dist/lsp/completion.d.ts +25 -0
- package/dist/lsp/completion.d.ts.map +1 -1
- package/dist/lsp/completion.js +1114 -51
- package/dist/lsp/completion.js.map +1 -1
- package/dist/lsp/definition.d.ts +2 -0
- package/dist/lsp/definition.d.ts.map +1 -1
- package/dist/lsp/definition.js +52 -58
- package/dist/lsp/definition.js.map +1 -1
- package/dist/lsp/diagnostics-worker.d.ts.map +1 -1
- package/dist/lsp/diagnostics-worker.js +1 -1
- package/dist/lsp/diagnostics-worker.js.map +1 -1
- package/dist/lsp/docs.d.ts +1 -1
- package/dist/lsp/docs.d.ts.map +1 -1
- package/dist/lsp/docs.js +4 -3
- package/dist/lsp/docs.js.map +1 -1
- package/dist/lsp/error-channel.d.ts.map +1 -1
- package/dist/lsp/error-channel.js.map +1 -1
- package/dist/lsp/hover.d.ts +5 -1
- package/dist/lsp/hover.d.ts.map +1 -1
- package/dist/lsp/hover.js +1016 -46
- package/dist/lsp/hover.js.map +1 -1
- package/dist/lsp/imports.d.ts +2 -0
- package/dist/lsp/imports.d.ts.map +1 -1
- package/dist/lsp/imports.js +45 -21
- package/dist/lsp/imports.js.map +1 -1
- package/dist/lsp/index.d.ts.map +1 -1
- package/dist/lsp/index.js.map +1 -1
- package/dist/lsp/inlay-hints.d.ts.map +1 -1
- package/dist/lsp/inlay-hints.js.map +1 -1
- package/dist/lsp/interop-rename.d.ts.map +1 -1
- package/dist/lsp/interop-rename.js.map +1 -1
- package/dist/lsp/match-arms.d.ts.map +1 -1
- package/dist/lsp/match-arms.js.map +1 -1
- package/dist/lsp/navigation.d.ts +1 -1
- package/dist/lsp/navigation.d.ts.map +1 -1
- package/dist/lsp/navigation.js +30 -12
- package/dist/lsp/navigation.js.map +1 -1
- package/dist/lsp/parsed-documents.d.ts.map +1 -1
- package/dist/lsp/parsed-documents.js.map +1 -1
- package/dist/lsp/range-format.d.ts +4 -0
- package/dist/lsp/range-format.d.ts.map +1 -0
- package/dist/lsp/range-format.js +88 -0
- package/dist/lsp/range-format.js.map +1 -0
- package/dist/lsp/rename-worker.d.ts.map +1 -1
- package/dist/lsp/rename-worker.js.map +1 -1
- package/dist/lsp/schema-import-hover.d.ts +8 -0
- package/dist/lsp/schema-import-hover.d.ts.map +1 -0
- package/dist/lsp/schema-import-hover.js +52 -0
- package/dist/lsp/schema-import-hover.js.map +1 -0
- package/dist/lsp/server.d.ts +3 -1
- package/dist/lsp/server.d.ts.map +1 -1
- package/dist/lsp/server.js +73 -48
- package/dist/lsp/server.js.map +1 -1
- package/dist/lsp/signature-help.d.ts +6 -0
- package/dist/lsp/signature-help.d.ts.map +1 -0
- package/dist/lsp/signature-help.js +183 -0
- package/dist/lsp/signature-help.js.map +1 -0
- package/dist/lsp/thunk-pipeline.d.ts.map +1 -1
- package/dist/lsp/thunk-pipeline.js.map +1 -1
- package/dist/lsp/validation.d.ts.map +1 -1
- package/dist/lsp/validation.js +3 -2
- package/dist/lsp/validation.js.map +1 -1
- package/dist/lsp/workspace.d.ts +3 -1
- package/dist/lsp/workspace.d.ts.map +1 -1
- package/dist/lsp/workspace.js +66 -10
- package/dist/lsp/workspace.js.map +1 -1
- package/dist/parser/declarations.d.ts.map +1 -1
- package/dist/parser/declarations.js +22 -1
- package/dist/parser/declarations.js.map +1 -1
- package/dist/parser/errors.d.ts.map +1 -1
- package/dist/parser/errors.js.map +1 -1
- package/dist/parser/jsx.d.ts.map +1 -1
- package/dist/parser/jsx.js.map +1 -1
- package/dist/parser/operator-expressions.d.ts.map +1 -1
- package/dist/parser/operator-expressions.js.map +1 -1
- package/dist/parser/parser.d.ts.map +1 -1
- package/dist/parser/parser.js.map +1 -1
- package/dist/parser/patterns.d.ts.map +1 -1
- package/dist/parser/patterns.js.map +1 -1
- package/dist/parser/pipeline-expressions.d.ts.map +1 -1
- package/dist/parser/pipeline-expressions.js.map +1 -1
- package/dist/parser/scope.d.ts.map +1 -1
- package/dist/parser/scope.js.map +1 -1
- package/dist/parser/statements.d.ts.map +1 -1
- package/dist/parser/statements.js.map +1 -1
- package/dist/parser/types.d.ts.map +1 -1
- package/dist/parser/types.js.map +1 -1
- package/dist/plugins/bun-preload.d.ts.map +1 -1
- package/dist/plugins/bun-preload.js.map +1 -1
- package/dist/plugins/bun.d.ts +2 -18
- package/dist/plugins/bun.d.ts.map +1 -1
- package/dist/plugins/bun.js +5 -30
- package/dist/plugins/bun.js.map +1 -1
- package/dist/plugins/esbuild.d.ts +1 -1
- package/dist/plugins/esbuild.d.ts.map +1 -1
- package/dist/plugins/esbuild.js +10 -36
- package/dist/plugins/esbuild.js.map +1 -1
- package/dist/plugins/server-boundary.d.ts +14 -0
- package/dist/plugins/server-boundary.d.ts.map +1 -0
- package/dist/plugins/server-boundary.js +25 -0
- package/dist/plugins/server-boundary.js.map +1 -0
- package/dist/plugins/type-view.d.ts.map +1 -1
- package/dist/plugins/type-view.js +5 -3
- package/dist/plugins/type-view.js.map +1 -1
- package/dist/plugins/vite.d.ts +2 -18
- package/dist/plugins/vite.d.ts.map +1 -1
- package/dist/plugins/vite.js +4 -29
- package/dist/plugins/vite.js.map +1 -1
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing/index.js.map +1 -1
- package/dist/tooling/doc.d.ts.map +1 -1
- package/dist/tooling/doc.js.map +1 -1
- package/dist/tooling/idiomatic.d.ts.map +1 -1
- package/dist/tooling/idiomatic.js.map +1 -1
- package/dist/tooling/pipeline-style.d.ts.map +1 -1
- package/dist/tooling/pipeline-style.js.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +13 -6
- package/src/cli/build-watch.ts +10 -29
- package/src/cli/build.ts +9 -60
- package/src/cli/check-policy.ts +54 -0
- package/src/cli/check.ts +19 -31
- package/src/cli/commands.ts +13 -0
- package/src/cli/doctor.ts +10 -7
- package/src/cli/index.ts +3 -0
- package/src/cli/init.ts +66 -21
- package/src/cli/query.ts +191 -0
- package/src/cli/run.ts +5 -30
- package/src/cli/tsc.ts +10 -8
- package/src/compiler/boolean-operators.ts +11 -2
- package/src/compiler/check.ts +152 -180
- package/src/compiler/diagnostics-json.ts +1205 -0
- package/src/compiler/escape-audit.ts +913 -0
- package/src/compiler/modules/output-plan.ts +11 -9
- package/src/compiler/modules/resolution.ts +2 -1
- package/src/compiler/modules/source-files.ts +13 -0
- package/src/compiler/numeric-comparisons.ts +14 -8
- package/src/compiler/pipelines/resolution.ts +30 -26
- package/src/compiler/project-config.ts +30 -19
- package/src/compiler/query.ts +1177 -0
- package/src/compiler/rules/resource-escape.ts +223 -0
- package/src/compiler/rules/resource-providers.ts +293 -0
- package/src/compiler/source-map.ts +3 -7
- package/src/compiler/type-view-paths.ts +10 -0
- package/src/compiler/typescript-context.ts +6 -7
- package/src/emitter/assemblyscript.ts +101 -147
- package/src/emitter/emitter.ts +13 -1
- package/src/emitter/statements.ts +2 -0
- package/src/formatter/comments.ts +14 -0
- package/src/formatter/index.ts +299 -4
- package/src/index.ts +3 -0
- package/src/lexer/lexer.ts +39 -20
- package/src/lsp/completion.ts +1452 -66
- package/src/lsp/definition.ts +50 -58
- package/src/lsp/diagnostics-worker.ts +1 -4
- package/src/lsp/docs.ts +4 -3
- package/src/lsp/hover.ts +1465 -44
- package/src/lsp/imports.ts +75 -22
- package/src/lsp/navigation.ts +41 -22
- package/src/lsp/range-format.ts +102 -0
- package/src/lsp/schema-import-hover.ts +76 -0
- package/src/lsp/server.ts +99 -69
- package/src/lsp/signature-help.ts +226 -0
- package/src/lsp/validation.ts +3 -2
- package/src/lsp/workspace.ts +63 -9
- package/src/parser/declarations.ts +27 -1
- package/src/plugins/bun.ts +14 -66
- package/src/plugins/esbuild.ts +16 -55
- package/src/plugins/server-boundary.ts +41 -0
- package/src/plugins/type-view.ts +11 -3
- package/src/plugins/vite.ts +12 -62
- package/dist/Widget.tsx +0 -9
- package/dist/cli/output-collisions.d.ts +0 -2
- package/dist/cli/output-collisions.d.ts.map +0 -1
- package/dist/cli/output-collisions.js +0 -39
- package/dist/cli/output-collisions.js.map +0 -1
- package/dist/compiler/imported-record-functions.d.ts +0 -4
- package/dist/compiler/imported-record-functions.d.ts.map +0 -1
- package/dist/compiler/imported-record-functions.js +0 -706
- package/dist/compiler/imported-record-functions.js.map +0 -1
- package/dist/compiler/imported-schemas.d.ts +0 -21
- package/dist/compiler/imported-schemas.d.ts.map +0 -1
- package/dist/compiler/imported-schemas.js +0 -461
- package/dist/compiler/imported-schemas.js.map +0 -1
- package/dist/compiler/module-resolution.d.ts +0 -6
- package/dist/compiler/module-resolution.d.ts.map +0 -1
- package/dist/compiler/module-resolution.js +0 -44
- package/dist/compiler/module-resolution.js.map +0 -1
- package/dist/compiler/pipeline-companions.d.ts +0 -18
- package/dist/compiler/pipeline-companions.d.ts.map +0 -1
- package/dist/compiler/pipeline-companions.js +0 -1042
- package/dist/compiler/pipeline-companions.js.map +0 -1
- package/dist/compiler/providers.d.ts +0 -4
- package/dist/compiler/providers.d.ts.map +0 -1
- package/dist/compiler/providers.js +0 -101
- package/dist/compiler/providers.js.map +0 -1
- package/dist/emitter/pipeline-catalog.d.ts +0 -15
- package/dist/emitter/pipeline-catalog.d.ts.map +0 -1
- package/dist/emitter/pipeline-catalog.js +0 -55
- package/dist/emitter/pipeline-catalog.js.map +0 -1
- package/dist/emitter/pipeline-resolution.d.ts +0 -38
- package/dist/emitter/pipeline-resolution.d.ts.map +0 -1
- package/dist/emitter/pipeline-resolution.js +0 -571
- package/dist/emitter/pipeline-resolution.js.map +0 -1
- package/dist/interop/index.d.ts +0 -6
- package/dist/interop/index.d.ts.map +0 -1
- package/dist/interop/index.js +0 -6
- package/dist/interop/index.js.map +0 -1
- package/dist/math.ts +0 -1
- package/dist/parser/index.d.ts +0 -9
- package/dist/parser/index.d.ts.map +0 -1
- package/dist/parser/index.js +0 -9
- package/dist/parser/index.js.map +0 -1
- package/dist/service.ts +0 -3
- package/dist/service.ts.map +0 -1
- package/dist/tooling/migrate.d.ts +0 -62
- package/dist/tooling/migrate.d.ts.map +0 -1
- package/dist/tooling/migrate.js +0 -608
- 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 {
|
|
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 {
|
|
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 {
|
|
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
|
|
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) &&
|
|
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
|
|
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
|
|
215
|
-
|
|
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
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 \`${
|
|
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
|
|
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,
|
|
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) {
|