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/src/lsp/completion.ts
CHANGED
|
@@ -1,13 +1,31 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, resolve } from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
1
4
|
import {
|
|
2
5
|
CompletionItemKind,
|
|
3
6
|
type CompletionItem,
|
|
4
7
|
type Position,
|
|
5
8
|
type Range,
|
|
6
9
|
} from "vscode-languageserver/node";
|
|
10
|
+
import type {
|
|
11
|
+
BindingDeclaration,
|
|
12
|
+
BindingTarget,
|
|
13
|
+
Expression,
|
|
14
|
+
Program,
|
|
15
|
+
RecordExpression,
|
|
16
|
+
TypeNode,
|
|
17
|
+
} from "../ast/types.js";
|
|
7
18
|
import {
|
|
8
19
|
PIPELINE_COMPANION_CATALOG,
|
|
9
20
|
pipelineCompanionCandidates,
|
|
10
21
|
} from "../compiler/pipelines/catalog.js";
|
|
22
|
+
import {
|
|
23
|
+
isExpectedSyntaxError,
|
|
24
|
+
isExpectedUriError,
|
|
25
|
+
isFileNotFoundError,
|
|
26
|
+
} from "../errors.js";
|
|
27
|
+
import { Lexer } from "../lexer/lexer.js";
|
|
28
|
+
import { Parser } from "../parser/parser.js";
|
|
11
29
|
import { DOC_CATALOG, getAllDocKeywords } from "./docs.js";
|
|
12
30
|
|
|
13
31
|
export interface IndexedDocument {
|
|
@@ -76,10 +94,1258 @@ const DEFERRED_PIPELINE_CONSTRUCTORS: ReadonlyArray<{
|
|
|
76
94
|
},
|
|
77
95
|
];
|
|
78
96
|
|
|
97
|
+
const INTRINSIC_JSX_TAGS = [
|
|
98
|
+
"div",
|
|
99
|
+
"span",
|
|
100
|
+
"button",
|
|
101
|
+
"input",
|
|
102
|
+
"form",
|
|
103
|
+
"main",
|
|
104
|
+
"section",
|
|
105
|
+
"header",
|
|
106
|
+
"footer",
|
|
107
|
+
"ul",
|
|
108
|
+
"li",
|
|
109
|
+
"a",
|
|
110
|
+
"p",
|
|
111
|
+
"h1",
|
|
112
|
+
"h2",
|
|
113
|
+
"h3",
|
|
114
|
+
"label",
|
|
115
|
+
"textarea",
|
|
116
|
+
"select",
|
|
117
|
+
"option",
|
|
118
|
+
"img",
|
|
119
|
+
"svg",
|
|
120
|
+
"path",
|
|
121
|
+
] as const;
|
|
122
|
+
|
|
123
|
+
const COMMON_JSX_PROPS = [
|
|
124
|
+
"class",
|
|
125
|
+
"className",
|
|
126
|
+
"id",
|
|
127
|
+
"style",
|
|
128
|
+
"key",
|
|
129
|
+
"children",
|
|
130
|
+
"onClick",
|
|
131
|
+
"onChange",
|
|
132
|
+
"onInput",
|
|
133
|
+
"onSubmit",
|
|
134
|
+
"disabled",
|
|
135
|
+
"href",
|
|
136
|
+
"type",
|
|
137
|
+
"value",
|
|
138
|
+
"placeholder",
|
|
139
|
+
"title",
|
|
140
|
+
] as const;
|
|
141
|
+
|
|
142
|
+
export type JsxCursorContext =
|
|
143
|
+
| { kind: "non-jsx" }
|
|
144
|
+
| { kind: "normal" }
|
|
145
|
+
| { kind: "jsx-children" }
|
|
146
|
+
| { kind: "jsx-open-tag"; prefix: string }
|
|
147
|
+
| { kind: "jsx-close-tag"; prefix: string; expectedTag: string | null }
|
|
148
|
+
| { kind: "jsx-member-tag"; objectName: string; prefix: string }
|
|
149
|
+
| {
|
|
150
|
+
kind: "jsx-attribute";
|
|
151
|
+
tagName: string;
|
|
152
|
+
prefix: string;
|
|
153
|
+
usedAttrs: Set<string>;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
type ScanFrame =
|
|
157
|
+
| {
|
|
158
|
+
kind: "code";
|
|
159
|
+
braceDepth: number;
|
|
160
|
+
lastSig: string;
|
|
161
|
+
prevLastSig: string;
|
|
162
|
+
returnTo?: "string" | "jsx-tag" | "jsx-children";
|
|
163
|
+
}
|
|
164
|
+
| { kind: "string"; returnTo: "code" | "jsx-tag" }
|
|
165
|
+
| { kind: "jsx-children"; tagName: string }
|
|
166
|
+
| {
|
|
167
|
+
kind: "jsx-tag";
|
|
168
|
+
isClosing: boolean;
|
|
169
|
+
tagName: string;
|
|
170
|
+
phase: "name" | "attrs" | "attr-val" | "close-ws";
|
|
171
|
+
usedAttrs: Set<string>;
|
|
172
|
+
currentAttr: string;
|
|
173
|
+
};
|
|
174
|
+
|
|
79
175
|
function escapeRegExp(value: string): string {
|
|
80
176
|
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
81
177
|
}
|
|
82
178
|
|
|
179
|
+
function isJsxOpenStart(
|
|
180
|
+
lastSig: string,
|
|
181
|
+
prevLastSig: string,
|
|
182
|
+
nextChar: string | undefined,
|
|
183
|
+
): boolean {
|
|
184
|
+
if (nextChar === "=" || nextChar === "<") return false;
|
|
185
|
+
if (nextChar !== undefined && !/[A-Za-z_>]/.test(nextChar)) return false;
|
|
186
|
+
if (lastSig === "" || lastSig === "\n") return true;
|
|
187
|
+
if (lastSig === ">" && prevLastSig === "=") return true;
|
|
188
|
+
if (/[=([{,:?|&!]/.test(lastSig)) return true;
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Scans `.funx` source up to cursor to determine the active JSX syntactic context. */
|
|
193
|
+
export function detectJsxContext(sourceUpToCursor: string): JsxCursorContext {
|
|
194
|
+
const stack: ScanFrame[] = [
|
|
195
|
+
{ kind: "code", braceDepth: 0, lastSig: "", prevLastSig: "" },
|
|
196
|
+
];
|
|
197
|
+
let i = 0;
|
|
198
|
+
const len = sourceUpToCursor.length;
|
|
199
|
+
|
|
200
|
+
while (i < len) {
|
|
201
|
+
const top = stack[stack.length - 1];
|
|
202
|
+
const ch = sourceUpToCursor[i];
|
|
203
|
+
|
|
204
|
+
if (top.kind === "string") {
|
|
205
|
+
if (ch === "\\") {
|
|
206
|
+
i += 2;
|
|
207
|
+
continue;
|
|
208
|
+
}
|
|
209
|
+
if (ch === '"') {
|
|
210
|
+
stack.pop();
|
|
211
|
+
i++;
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
if (ch === "{") {
|
|
215
|
+
stack.push({
|
|
216
|
+
kind: "code",
|
|
217
|
+
braceDepth: 0,
|
|
218
|
+
lastSig: "{",
|
|
219
|
+
prevLastSig: "",
|
|
220
|
+
returnTo: "string",
|
|
221
|
+
});
|
|
222
|
+
i++;
|
|
223
|
+
continue;
|
|
224
|
+
}
|
|
225
|
+
i++;
|
|
226
|
+
continue;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (top.kind === "jsx-children") {
|
|
230
|
+
if (ch === "<") {
|
|
231
|
+
if (sourceUpToCursor[i + 1] === "/") {
|
|
232
|
+
stack.push({
|
|
233
|
+
kind: "jsx-tag",
|
|
234
|
+
isClosing: true,
|
|
235
|
+
tagName: "",
|
|
236
|
+
phase: "name",
|
|
237
|
+
usedAttrs: new Set(),
|
|
238
|
+
currentAttr: "",
|
|
239
|
+
});
|
|
240
|
+
i += 2;
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
stack.push({
|
|
244
|
+
kind: "jsx-tag",
|
|
245
|
+
isClosing: false,
|
|
246
|
+
tagName: "",
|
|
247
|
+
phase: "name",
|
|
248
|
+
usedAttrs: new Set(),
|
|
249
|
+
currentAttr: "",
|
|
250
|
+
});
|
|
251
|
+
i++;
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
if (ch === "{") {
|
|
255
|
+
stack.push({
|
|
256
|
+
kind: "code",
|
|
257
|
+
braceDepth: 0,
|
|
258
|
+
lastSig: "{",
|
|
259
|
+
prevLastSig: "",
|
|
260
|
+
returnTo: "jsx-children",
|
|
261
|
+
});
|
|
262
|
+
i++;
|
|
263
|
+
continue;
|
|
264
|
+
}
|
|
265
|
+
i++;
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (top.kind === "jsx-tag") {
|
|
270
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === "/") {
|
|
271
|
+
const nl = sourceUpToCursor.indexOf("\n", i + 2);
|
|
272
|
+
if (nl === -1) return { kind: "non-jsx" };
|
|
273
|
+
i = nl + 1;
|
|
274
|
+
continue;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === ">") {
|
|
278
|
+
stack.pop();
|
|
279
|
+
i += 2;
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
if (ch === ">") {
|
|
284
|
+
stack.pop();
|
|
285
|
+
if (top.isClosing) {
|
|
286
|
+
for (let k = stack.length - 1; k >= 0; k--) {
|
|
287
|
+
if (stack[k].kind === "jsx-children") {
|
|
288
|
+
if (
|
|
289
|
+
!top.tagName ||
|
|
290
|
+
(stack[k] as { tagName: string }).tagName === top.tagName
|
|
291
|
+
) {
|
|
292
|
+
stack.splice(k);
|
|
293
|
+
break;
|
|
294
|
+
}
|
|
295
|
+
} else if (stack[k].kind === "code") {
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
} else {
|
|
300
|
+
stack.push({ kind: "jsx-children", tagName: top.tagName });
|
|
301
|
+
}
|
|
302
|
+
i++;
|
|
303
|
+
continue;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (top.phase === "name") {
|
|
307
|
+
if (/[A-Za-z0-9_$.-]/.test(ch)) {
|
|
308
|
+
top.tagName += ch;
|
|
309
|
+
i++;
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (/\s/.test(ch)) {
|
|
313
|
+
if (top.tagName.length > 0) {
|
|
314
|
+
top.phase = top.isClosing ? "close-ws" : "attrs";
|
|
315
|
+
}
|
|
316
|
+
i++;
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
i++;
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
if (top.phase === "close-ws") {
|
|
324
|
+
i++;
|
|
325
|
+
continue;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
if (top.phase === "attr-val") {
|
|
329
|
+
if (/\s/.test(ch)) {
|
|
330
|
+
i++;
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (ch === '"') {
|
|
334
|
+
top.phase = "attrs";
|
|
335
|
+
stack.push({ kind: "string", returnTo: "jsx-tag" });
|
|
336
|
+
i++;
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
if (ch === "{") {
|
|
340
|
+
top.phase = "attrs";
|
|
341
|
+
stack.push({
|
|
342
|
+
kind: "code",
|
|
343
|
+
braceDepth: 0,
|
|
344
|
+
lastSig: "{",
|
|
345
|
+
prevLastSig: "",
|
|
346
|
+
returnTo: "jsx-tag",
|
|
347
|
+
});
|
|
348
|
+
i++;
|
|
349
|
+
continue;
|
|
350
|
+
}
|
|
351
|
+
if (/[A-Za-z_$-]/.test(ch)) {
|
|
352
|
+
top.phase = "attrs";
|
|
353
|
+
top.currentAttr = ch;
|
|
354
|
+
i++;
|
|
355
|
+
continue;
|
|
356
|
+
}
|
|
357
|
+
top.phase = "attrs";
|
|
358
|
+
i++;
|
|
359
|
+
continue;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
// phase === "attrs"
|
|
363
|
+
if (/\s/.test(ch)) {
|
|
364
|
+
if (top.currentAttr) {
|
|
365
|
+
top.usedAttrs.add(top.currentAttr);
|
|
366
|
+
top.currentAttr = "";
|
|
367
|
+
}
|
|
368
|
+
i++;
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (ch === "=") {
|
|
372
|
+
if (top.currentAttr) {
|
|
373
|
+
top.usedAttrs.add(top.currentAttr);
|
|
374
|
+
top.currentAttr = "";
|
|
375
|
+
}
|
|
376
|
+
top.phase = "attr-val";
|
|
377
|
+
i++;
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
if (ch === '"') {
|
|
381
|
+
stack.push({ kind: "string", returnTo: "jsx-tag" });
|
|
382
|
+
i++;
|
|
383
|
+
continue;
|
|
384
|
+
}
|
|
385
|
+
if (ch === "{") {
|
|
386
|
+
stack.push({
|
|
387
|
+
kind: "code",
|
|
388
|
+
braceDepth: 0,
|
|
389
|
+
lastSig: "{",
|
|
390
|
+
prevLastSig: "",
|
|
391
|
+
returnTo: "jsx-tag",
|
|
392
|
+
});
|
|
393
|
+
i++;
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
if (/[A-Za-z0-9_$:-]/.test(ch)) {
|
|
397
|
+
top.currentAttr += ch;
|
|
398
|
+
i++;
|
|
399
|
+
continue;
|
|
400
|
+
}
|
|
401
|
+
i++;
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// top.kind === "code"
|
|
406
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === "/") {
|
|
407
|
+
const nl = sourceUpToCursor.indexOf("\n", i + 2);
|
|
408
|
+
if (nl === -1) return { kind: "non-jsx" };
|
|
409
|
+
top.prevLastSig = top.lastSig;
|
|
410
|
+
top.lastSig = "\n";
|
|
411
|
+
i = nl + 1;
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (ch === "/" && sourceUpToCursor[i + 1] === "*") {
|
|
415
|
+
const end = sourceUpToCursor.indexOf("*/", i + 2);
|
|
416
|
+
if (end === -1) return { kind: "non-jsx" };
|
|
417
|
+
i = end + 2;
|
|
418
|
+
continue;
|
|
419
|
+
}
|
|
420
|
+
if (ch === '"') {
|
|
421
|
+
top.prevLastSig = top.lastSig;
|
|
422
|
+
top.lastSig = '"';
|
|
423
|
+
stack.push({ kind: "string", returnTo: "code" });
|
|
424
|
+
i++;
|
|
425
|
+
continue;
|
|
426
|
+
}
|
|
427
|
+
if (ch === "{") {
|
|
428
|
+
top.braceDepth++;
|
|
429
|
+
top.prevLastSig = top.lastSig;
|
|
430
|
+
top.lastSig = "{";
|
|
431
|
+
i++;
|
|
432
|
+
continue;
|
|
433
|
+
}
|
|
434
|
+
if (ch === "}") {
|
|
435
|
+
if (top.braceDepth > 0) {
|
|
436
|
+
top.braceDepth--;
|
|
437
|
+
top.prevLastSig = top.lastSig;
|
|
438
|
+
top.lastSig = "}";
|
|
439
|
+
} else if (top.returnTo) {
|
|
440
|
+
stack.pop();
|
|
441
|
+
}
|
|
442
|
+
i++;
|
|
443
|
+
continue;
|
|
444
|
+
}
|
|
445
|
+
if (ch === "<") {
|
|
446
|
+
const next = sourceUpToCursor[i + 1];
|
|
447
|
+
if (next === "/") {
|
|
448
|
+
stack.push({
|
|
449
|
+
kind: "jsx-tag",
|
|
450
|
+
isClosing: true,
|
|
451
|
+
tagName: "",
|
|
452
|
+
phase: "name",
|
|
453
|
+
usedAttrs: new Set(),
|
|
454
|
+
currentAttr: "",
|
|
455
|
+
});
|
|
456
|
+
i += 2;
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
if (isJsxOpenStart(top.lastSig, top.prevLastSig, next)) {
|
|
460
|
+
stack.push({
|
|
461
|
+
kind: "jsx-tag",
|
|
462
|
+
isClosing: false,
|
|
463
|
+
tagName: "",
|
|
464
|
+
phase: "name",
|
|
465
|
+
usedAttrs: new Set(),
|
|
466
|
+
currentAttr: "",
|
|
467
|
+
});
|
|
468
|
+
i++;
|
|
469
|
+
continue;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
if (ch === "\n") {
|
|
473
|
+
top.prevLastSig = top.lastSig;
|
|
474
|
+
top.lastSig = "\n";
|
|
475
|
+
i++;
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
if (/\s/.test(ch)) {
|
|
479
|
+
i++;
|
|
480
|
+
continue;
|
|
481
|
+
}
|
|
482
|
+
top.prevLastSig = top.lastSig;
|
|
483
|
+
top.lastSig = ch;
|
|
484
|
+
i++;
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
const finalTop = stack[stack.length - 1];
|
|
488
|
+
if (finalTop.kind === "string") {
|
|
489
|
+
return { kind: "non-jsx" };
|
|
490
|
+
}
|
|
491
|
+
if (finalTop.kind === "jsx-children") {
|
|
492
|
+
return { kind: "jsx-children" };
|
|
493
|
+
}
|
|
494
|
+
if (finalTop.kind === "jsx-tag") {
|
|
495
|
+
if (finalTop.isClosing) {
|
|
496
|
+
let expectedTag: string | null = null;
|
|
497
|
+
for (let k = stack.length - 2; k >= 0; k--) {
|
|
498
|
+
if (stack[k].kind === "jsx-children") {
|
|
499
|
+
const name = (stack[k] as { tagName: string }).tagName;
|
|
500
|
+
if (name) expectedTag = name;
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
if (stack[k].kind === "code") break;
|
|
504
|
+
}
|
|
505
|
+
return { kind: "jsx-close-tag", prefix: finalTop.tagName, expectedTag };
|
|
506
|
+
}
|
|
507
|
+
if (finalTop.phase === "name") {
|
|
508
|
+
const dotIdx = finalTop.tagName.lastIndexOf(".");
|
|
509
|
+
if (dotIdx !== -1) {
|
|
510
|
+
return {
|
|
511
|
+
kind: "jsx-member-tag",
|
|
512
|
+
objectName: finalTop.tagName.slice(0, dotIdx),
|
|
513
|
+
prefix: finalTop.tagName.slice(dotIdx + 1),
|
|
514
|
+
};
|
|
515
|
+
}
|
|
516
|
+
return { kind: "jsx-open-tag", prefix: finalTop.tagName };
|
|
517
|
+
}
|
|
518
|
+
if (finalTop.phase === "attrs") {
|
|
519
|
+
return {
|
|
520
|
+
kind: "jsx-attribute",
|
|
521
|
+
tagName: finalTop.tagName,
|
|
522
|
+
prefix: finalTop.currentAttr,
|
|
523
|
+
usedAttrs: finalTop.usedAttrs,
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
return { kind: "normal" };
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function formatBindingTarget(target: BindingTarget): string {
|
|
531
|
+
if (target.kind === "Identifier" || target.kind === "UpperIdentifier") {
|
|
532
|
+
return target.name;
|
|
533
|
+
}
|
|
534
|
+
if (target.kind === "RecordPattern") {
|
|
535
|
+
return `{ ${target.fields
|
|
536
|
+
.map((f) =>
|
|
537
|
+
f.pattern
|
|
538
|
+
? `${f.key.name}: ${formatBindingTarget(f.pattern as BindingTarget)}`
|
|
539
|
+
: f.key.name,
|
|
540
|
+
)
|
|
541
|
+
.join(", ")} }`;
|
|
542
|
+
}
|
|
543
|
+
return `[${target.elements.map((e) => ("name" in e && typeof e.name === "object" && e.name && "name" in e.name ? String(e.name.name) : "_")).join(", ")}]`;
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
function formatTypeNode(typeNode: TypeNode): string {
|
|
547
|
+
switch (typeNode.kind) {
|
|
548
|
+
case "TypeReferenceNode": {
|
|
549
|
+
const args =
|
|
550
|
+
typeNode.typeArgs && typeNode.typeArgs.length > 0
|
|
551
|
+
? `<${typeNode.typeArgs.map(formatTypeNode).join(", ")}>`
|
|
552
|
+
: "";
|
|
553
|
+
return `${typeNode.name.name}${args}`;
|
|
554
|
+
}
|
|
555
|
+
case "QualifiedTypeReferenceNode": {
|
|
556
|
+
const args =
|
|
557
|
+
typeNode.typeArgs && typeNode.typeArgs.length > 0
|
|
558
|
+
? `<${typeNode.typeArgs.map(formatTypeNode).join(", ")}>`
|
|
559
|
+
: "";
|
|
560
|
+
return `${typeNode.parts.map((p) => p.name).join(".")}${args}`;
|
|
561
|
+
}
|
|
562
|
+
case "FunctionTypeNode": {
|
|
563
|
+
const params = typeNode.params
|
|
564
|
+
.map((p) =>
|
|
565
|
+
p.typeAnnotation
|
|
566
|
+
? `${formatBindingTarget(p.name)}: ${formatTypeNode(p.typeAnnotation)}`
|
|
567
|
+
: formatBindingTarget(p.name),
|
|
568
|
+
)
|
|
569
|
+
.join(", ");
|
|
570
|
+
return `(${params}) => ${formatTypeNode(typeNode.returnType)}`;
|
|
571
|
+
}
|
|
572
|
+
case "EffectTypeNode": {
|
|
573
|
+
const parts = [formatTypeNode(typeNode.success)];
|
|
574
|
+
if (typeNode.error) parts.push(formatTypeNode(typeNode.error));
|
|
575
|
+
if (typeNode.requirements) {
|
|
576
|
+
if (!typeNode.error) parts.push("never");
|
|
577
|
+
parts.push(formatTypeNode(typeNode.requirements));
|
|
578
|
+
}
|
|
579
|
+
return `Effect<${parts.join(", ")}>`;
|
|
580
|
+
}
|
|
581
|
+
case "RecordTypeNode":
|
|
582
|
+
return `{ ${typeNode.fields.map((f) => `${f.name.name}${f.optional ? "?" : ""}: ${formatTypeNode(f.typeAnnotation)}`).join(", ")} }`;
|
|
583
|
+
case "ArrayTypeNode":
|
|
584
|
+
return `Array<${formatTypeNode(typeNode.elementType)}>`;
|
|
585
|
+
case "UnionTypeNode":
|
|
586
|
+
return typeNode.types.map(formatTypeNode).join(" | ");
|
|
587
|
+
case "IntersectionTypeNode":
|
|
588
|
+
return typeNode.types.map(formatTypeNode).join(" & ");
|
|
589
|
+
case "LiteralTypeNode":
|
|
590
|
+
return typeof typeNode.value === "string"
|
|
591
|
+
? JSON.stringify(typeNode.value)
|
|
592
|
+
: String(typeNode.value);
|
|
593
|
+
case "ParenthesizedTypeNode":
|
|
594
|
+
return `(${formatTypeNode(typeNode.typeNode)})`;
|
|
595
|
+
case "TypeQueryNode":
|
|
596
|
+
return "typeof ...";
|
|
597
|
+
case "IndexedAccessTypeNode":
|
|
598
|
+
return `${formatTypeNode(typeNode.objectType)}[${formatTypeNode(typeNode.indexType)}]`;
|
|
599
|
+
case "TsEscapeTypeNode":
|
|
600
|
+
return `ts { ${typeNode.code.trim()} }`;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function tryParse(source: string, uri: string): Program | null {
|
|
605
|
+
try {
|
|
606
|
+
return new Parser(new Lexer(source, uri).tokenize(), uri).parse();
|
|
607
|
+
} catch (error) {
|
|
608
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
609
|
+
return null;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
function resolveModuleDoc(
|
|
614
|
+
fromUri: string,
|
|
615
|
+
modulePath: string,
|
|
616
|
+
documents: IndexedDocument[],
|
|
617
|
+
): IndexedDocument | null {
|
|
618
|
+
if (!modulePath.startsWith(".")) return null;
|
|
619
|
+
|
|
620
|
+
let base: string;
|
|
621
|
+
try {
|
|
622
|
+
base = resolve(dirname(fileURLToPath(fromUri)), modulePath);
|
|
623
|
+
} catch (error) {
|
|
624
|
+
if (!isExpectedUriError(error)) throw error;
|
|
625
|
+
return null;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
const candidates = [
|
|
629
|
+
base,
|
|
630
|
+
`${base}.fun`,
|
|
631
|
+
`${base}.funs`,
|
|
632
|
+
`${base}.funx`,
|
|
633
|
+
`${base}.ts`,
|
|
634
|
+
`${base}.tsx`,
|
|
635
|
+
resolve(base, "index.fun"),
|
|
636
|
+
resolve(base, "index.funs"),
|
|
637
|
+
resolve(base, "index.funx"),
|
|
638
|
+
];
|
|
639
|
+
|
|
640
|
+
for (const doc of documents) {
|
|
641
|
+
try {
|
|
642
|
+
if (candidates.includes(fileURLToPath(doc.uri))) return doc;
|
|
643
|
+
} catch (error) {
|
|
644
|
+
if (!isExpectedUriError(error)) throw error;
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
for (const candidate of candidates) {
|
|
649
|
+
try {
|
|
650
|
+
if (existsSync(candidate)) {
|
|
651
|
+
return {
|
|
652
|
+
uri: pathToFileURL(candidate).href,
|
|
653
|
+
text: readFileSync(candidate, "utf8"),
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
} catch (error) {
|
|
657
|
+
if (!isFileNotFoundError(error) && !isExpectedUriError(error))
|
|
658
|
+
throw error;
|
|
659
|
+
}
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
return null;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
function collectServiceMembersFromText(
|
|
666
|
+
text: string,
|
|
667
|
+
uri: string,
|
|
668
|
+
serviceName: string,
|
|
669
|
+
): Array<{ name: string; detail: string }> {
|
|
670
|
+
const ast = tryParse(text, uri);
|
|
671
|
+
if (ast) {
|
|
672
|
+
for (const top of ast.body) {
|
|
673
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
674
|
+
if (
|
|
675
|
+
inner.kind === "ServiceDeclaration" &&
|
|
676
|
+
inner.id.name === serviceName
|
|
677
|
+
) {
|
|
678
|
+
return inner.members.map((m) => ({
|
|
679
|
+
name: m.name.name,
|
|
680
|
+
detail: formatTypeNode(m.signature),
|
|
681
|
+
}));
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
const escaped = escapeRegExp(serviceName);
|
|
687
|
+
const blockMatch = new RegExp(
|
|
688
|
+
`(?:^|\\n)\\s*(?:export\\s+)?service\\s+${escaped}\\b[^\\n]*\\n([\\s\\S]*?)(?=\\n\\S|$)`,
|
|
689
|
+
).exec(text);
|
|
690
|
+
if (!blockMatch) return [];
|
|
691
|
+
|
|
692
|
+
const members: Array<{ name: string; detail: string }> = [];
|
|
693
|
+
for (const line of blockMatch[1].split(/\r?\n/)) {
|
|
694
|
+
const m = /^\s+([A-Za-z_$][\w$]*)\s*:\s*(.+)$/.exec(line);
|
|
695
|
+
if (m) {
|
|
696
|
+
members.push({ name: m[1], detail: m[2].trim() });
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
return members;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
function collectSchemaMembersFromText(
|
|
703
|
+
text: string,
|
|
704
|
+
uri: string,
|
|
705
|
+
schemaName: string,
|
|
706
|
+
): Array<{ name: string; kind: CompletionItemKind; detail: string }> {
|
|
707
|
+
const results: Array<{
|
|
708
|
+
name: string;
|
|
709
|
+
kind: CompletionItemKind;
|
|
710
|
+
detail: string;
|
|
711
|
+
}> = [];
|
|
712
|
+
const ast = tryParse(text, uri);
|
|
713
|
+
if (ast) {
|
|
714
|
+
for (const top of ast.body) {
|
|
715
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
716
|
+
if (inner.kind === "SchemaDeclaration" && inner.id.name === schemaName) {
|
|
717
|
+
if (inner.body.kind === "RecordSchema") {
|
|
718
|
+
for (const f of inner.body.fields) {
|
|
719
|
+
results.push({
|
|
720
|
+
name: f.name.name,
|
|
721
|
+
kind: CompletionItemKind.Field,
|
|
722
|
+
detail: formatTypeNode(f.typeAnnotation),
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
} else if (inner.body.kind === "TaggedUnionSchema") {
|
|
726
|
+
for (const v of inner.body.variants) {
|
|
727
|
+
results.push({
|
|
728
|
+
name: v.name.name,
|
|
729
|
+
kind: CompletionItemKind.EnumMember,
|
|
730
|
+
detail: `${schemaName} variant`,
|
|
731
|
+
});
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return results;
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
const escaped = escapeRegExp(schemaName);
|
|
740
|
+
const schema = new RegExp(
|
|
741
|
+
`(?:schema\\s+)?${escaped}\\s*=\\s*\\{([\\s\\S]*?)\\n\\}`,
|
|
742
|
+
"m",
|
|
743
|
+
).exec(text);
|
|
744
|
+
if (schema) {
|
|
745
|
+
for (const field of schema[1].matchAll(
|
|
746
|
+
/^\s*([A-Za-z_$][\w$]*)\s*:\s*([^,\n}]+)/gm,
|
|
747
|
+
)) {
|
|
748
|
+
results.push({
|
|
749
|
+
name: field[1],
|
|
750
|
+
kind: CompletionItemKind.Field,
|
|
751
|
+
detail: field[2].trim(),
|
|
752
|
+
});
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
const variants = new RegExp(
|
|
756
|
+
`schema\\s+${escaped}\\s*=([\\s\\S]*?)(?:\\n\\S|$)`,
|
|
757
|
+
"m",
|
|
758
|
+
).exec(text);
|
|
759
|
+
if (variants) {
|
|
760
|
+
for (const variant of variants[1].matchAll(/\|\s*([A-Z][A-Za-z0-9_$]*)/g)) {
|
|
761
|
+
results.push({
|
|
762
|
+
name: variant[1],
|
|
763
|
+
kind: CompletionItemKind.EnumMember,
|
|
764
|
+
detail: `${schemaName} variant`,
|
|
765
|
+
});
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
return results;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
function inferExprDetail(expr: Expression): string {
|
|
772
|
+
switch (expr.kind) {
|
|
773
|
+
case "FunctionExpression": {
|
|
774
|
+
const params = expr.params
|
|
775
|
+
.map((p) =>
|
|
776
|
+
p.typeAnnotation
|
|
777
|
+
? `${formatBindingTarget(p.name)}: ${formatTypeNode(p.typeAnnotation)}`
|
|
778
|
+
: formatBindingTarget(p.name),
|
|
779
|
+
)
|
|
780
|
+
.join(", ");
|
|
781
|
+
const ret = expr.returnType
|
|
782
|
+
? formatTypeNode(expr.returnType)
|
|
783
|
+
: "JSX.Element";
|
|
784
|
+
return `(${params}) => ${ret}`;
|
|
785
|
+
}
|
|
786
|
+
case "RecordExpression":
|
|
787
|
+
return "{ ... }";
|
|
788
|
+
case "NumberLiteral":
|
|
789
|
+
return "number";
|
|
790
|
+
case "StringLiteral":
|
|
791
|
+
return "string";
|
|
792
|
+
case "BooleanLiteral":
|
|
793
|
+
return "boolean";
|
|
794
|
+
default:
|
|
795
|
+
return "property";
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
function extractRecordFieldsFromRecordExpr(
|
|
800
|
+
expr: RecordExpression,
|
|
801
|
+
): Array<{ name: string; kind: CompletionItemKind; detail: string }> {
|
|
802
|
+
const results: Array<{
|
|
803
|
+
name: string;
|
|
804
|
+
kind: CompletionItemKind;
|
|
805
|
+
detail: string;
|
|
806
|
+
}> = [];
|
|
807
|
+
for (const entry of expr.entries) {
|
|
808
|
+
if (entry.kind === "FieldEntry") {
|
|
809
|
+
results.push({
|
|
810
|
+
name: entry.key.name,
|
|
811
|
+
kind:
|
|
812
|
+
entry.value.kind === "FunctionExpression"
|
|
813
|
+
? CompletionItemKind.Function
|
|
814
|
+
: CompletionItemKind.Property,
|
|
815
|
+
detail: inferExprDetail(entry.value),
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
return results;
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
function collectRecordBindingMembersFromText(
|
|
823
|
+
text: string,
|
|
824
|
+
uri: string,
|
|
825
|
+
bindingName: string,
|
|
826
|
+
): Array<{ name: string; kind: CompletionItemKind; detail: string }> {
|
|
827
|
+
const ast = tryParse(text, uri);
|
|
828
|
+
if (ast) {
|
|
829
|
+
for (const top of ast.body) {
|
|
830
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
831
|
+
if (
|
|
832
|
+
inner.kind === "BindingDeclaration" &&
|
|
833
|
+
"name" in inner.id &&
|
|
834
|
+
inner.id.name === bindingName
|
|
835
|
+
) {
|
|
836
|
+
if (inner.init.kind === "RecordExpression") {
|
|
837
|
+
return extractRecordFieldsFromRecordExpr(inner.init);
|
|
838
|
+
}
|
|
839
|
+
if (inner.typeAnnotation?.kind === "RecordTypeNode") {
|
|
840
|
+
return inner.typeAnnotation.fields.map((f) => ({
|
|
841
|
+
name: f.name.name,
|
|
842
|
+
kind: CompletionItemKind.Field,
|
|
843
|
+
detail: formatTypeNode(f.typeAnnotation),
|
|
844
|
+
}));
|
|
845
|
+
}
|
|
846
|
+
if (inner.typeAnnotation?.kind === "TypeReferenceNode") {
|
|
847
|
+
return collectSchemaMembersFromText(
|
|
848
|
+
text,
|
|
849
|
+
uri,
|
|
850
|
+
inner.typeAnnotation.name.name,
|
|
851
|
+
);
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// Regex + balanced-brace fallback when current buffer has incomplete syntax (e.g. `<Icons.`)
|
|
858
|
+
const headerRe = new RegExp(
|
|
859
|
+
`(?:^|\\n)\\s*(?:export\\s+)?(?:mut\\s+)?${escapeRegExp(bindingName)}\\s*(?::[^=\\n]+)?=\\s*\\{`,
|
|
860
|
+
);
|
|
861
|
+
const headerMatch = headerRe.exec(text);
|
|
862
|
+
if (!headerMatch) return [];
|
|
863
|
+
|
|
864
|
+
const openBraceIdx = headerMatch.index + headerMatch[0].length - 1;
|
|
865
|
+
let depth = 0;
|
|
866
|
+
let inString = false;
|
|
867
|
+
let lineStart = openBraceIdx + 1;
|
|
868
|
+
const results: Array<{
|
|
869
|
+
name: string;
|
|
870
|
+
kind: CompletionItemKind;
|
|
871
|
+
detail: string;
|
|
872
|
+
}> = [];
|
|
873
|
+
|
|
874
|
+
for (let i = openBraceIdx; i < text.length; i++) {
|
|
875
|
+
const ch = text[i];
|
|
876
|
+
if (inString) {
|
|
877
|
+
if (ch === "\\") {
|
|
878
|
+
i++;
|
|
879
|
+
continue;
|
|
880
|
+
}
|
|
881
|
+
if (ch === '"') inString = false;
|
|
882
|
+
continue;
|
|
883
|
+
}
|
|
884
|
+
if (ch === '"') {
|
|
885
|
+
inString = true;
|
|
886
|
+
continue;
|
|
887
|
+
}
|
|
888
|
+
if (ch === "/" && text[i + 1] === "/") {
|
|
889
|
+
const nl = text.indexOf("\n", i + 2);
|
|
890
|
+
i = nl === -1 ? text.length : nl;
|
|
891
|
+
lineStart = i + 1;
|
|
892
|
+
continue;
|
|
893
|
+
}
|
|
894
|
+
if (ch === "{") {
|
|
895
|
+
depth++;
|
|
896
|
+
if (depth === 1) lineStart = i + 1;
|
|
897
|
+
continue;
|
|
898
|
+
}
|
|
899
|
+
if (ch === "}") {
|
|
900
|
+
if (depth === 1) {
|
|
901
|
+
const segment = text.slice(lineStart, i).trim();
|
|
902
|
+
const field = /^([A-Za-z_$][\w$]*)\s*:/.exec(segment);
|
|
903
|
+
if (field) {
|
|
904
|
+
results.push({
|
|
905
|
+
name: field[1],
|
|
906
|
+
kind: CompletionItemKind.Property,
|
|
907
|
+
detail: "property",
|
|
908
|
+
});
|
|
909
|
+
}
|
|
910
|
+
break;
|
|
911
|
+
}
|
|
912
|
+
depth--;
|
|
913
|
+
continue;
|
|
914
|
+
}
|
|
915
|
+
if (depth === 1 && (ch === "\n" || ch === ",")) {
|
|
916
|
+
const segment = text.slice(lineStart, i).trim();
|
|
917
|
+
const field = /^([A-Za-z_$][\w$]*)\s*:/.exec(segment);
|
|
918
|
+
if (field) {
|
|
919
|
+
results.push({
|
|
920
|
+
name: field[1],
|
|
921
|
+
kind: CompletionItemKind.Property,
|
|
922
|
+
detail: "property",
|
|
923
|
+
});
|
|
924
|
+
}
|
|
925
|
+
lineStart = i + 1;
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
return results;
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
function collectExportedSymbolsFromText(
|
|
932
|
+
text: string,
|
|
933
|
+
uri: string,
|
|
934
|
+
): Array<{ name: string; kind: CompletionItemKind; detail: string }> {
|
|
935
|
+
const ast = tryParse(text, uri);
|
|
936
|
+
const results: Array<{
|
|
937
|
+
name: string;
|
|
938
|
+
kind: CompletionItemKind;
|
|
939
|
+
detail: string;
|
|
940
|
+
}> = [];
|
|
941
|
+
if (ast) {
|
|
942
|
+
for (const top of ast.body) {
|
|
943
|
+
if (top.kind !== "ExportDeclaration") continue;
|
|
944
|
+
const decl = top.declaration;
|
|
945
|
+
if (decl.kind === "BindingDeclaration" && "name" in decl.id) {
|
|
946
|
+
results.push({
|
|
947
|
+
name: decl.id.name,
|
|
948
|
+
kind:
|
|
949
|
+
decl.init.kind === "FunctionExpression"
|
|
950
|
+
? CompletionItemKind.Function
|
|
951
|
+
: CompletionItemKind.Variable,
|
|
952
|
+
detail: inferExprDetail(decl.init),
|
|
953
|
+
});
|
|
954
|
+
} else if (decl.kind === "SchemaDeclaration") {
|
|
955
|
+
results.push({
|
|
956
|
+
name: decl.id.name,
|
|
957
|
+
kind: CompletionItemKind.Struct,
|
|
958
|
+
detail: "schema",
|
|
959
|
+
});
|
|
960
|
+
} else if (decl.kind === "ServiceDeclaration") {
|
|
961
|
+
results.push({
|
|
962
|
+
name: decl.id.name,
|
|
963
|
+
kind: CompletionItemKind.Interface,
|
|
964
|
+
detail: "service",
|
|
965
|
+
});
|
|
966
|
+
} else if (decl.kind === "ErrorDeclaration") {
|
|
967
|
+
results.push({
|
|
968
|
+
name: decl.id.name,
|
|
969
|
+
kind: CompletionItemKind.Class,
|
|
970
|
+
detail: "error",
|
|
971
|
+
});
|
|
972
|
+
}
|
|
973
|
+
}
|
|
974
|
+
return results;
|
|
975
|
+
}
|
|
976
|
+
|
|
977
|
+
for (const found of text.matchAll(
|
|
978
|
+
/^\s*export\s+(?:(?:schema|error|service)\s+)?([A-Za-z_$][\w$]*)/gm,
|
|
979
|
+
)) {
|
|
980
|
+
results.push({
|
|
981
|
+
name: found[1],
|
|
982
|
+
kind: CompletionItemKind.Variable,
|
|
983
|
+
detail: "export",
|
|
984
|
+
});
|
|
985
|
+
}
|
|
986
|
+
return results;
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
function collectNamespaceImports(
|
|
990
|
+
source: string,
|
|
991
|
+
uri: string,
|
|
992
|
+
documents: IndexedDocument[],
|
|
993
|
+
): Map<string, { doc: IndexedDocument; modulePath: string }> {
|
|
994
|
+
const namespaces = new Map<
|
|
995
|
+
string,
|
|
996
|
+
{ doc: IndexedDocument; modulePath: string }
|
|
997
|
+
>();
|
|
998
|
+
for (const match of source.matchAll(
|
|
999
|
+
/^\s*import\s+\*\s+as\s+([A-Za-z_$][\w$]*)\s+from\s+["']([^"']+)["']/gm,
|
|
1000
|
+
)) {
|
|
1001
|
+
const localName = match[1];
|
|
1002
|
+
const modulePath = match[2];
|
|
1003
|
+
const targetDoc = resolveModuleDoc(uri, modulePath, documents);
|
|
1004
|
+
if (targetDoc) {
|
|
1005
|
+
namespaces.set(localName, { doc: targetDoc, modulePath });
|
|
1006
|
+
}
|
|
1007
|
+
}
|
|
1008
|
+
return namespaces;
|
|
1009
|
+
}
|
|
1010
|
+
|
|
1011
|
+
function collectImportedSymbols(
|
|
1012
|
+
source: string,
|
|
1013
|
+
uri: string,
|
|
1014
|
+
documents: IndexedDocument[],
|
|
1015
|
+
): Map<
|
|
1016
|
+
string,
|
|
1017
|
+
{ doc: IndexedDocument; exportedName: string; modulePath: string }
|
|
1018
|
+
> {
|
|
1019
|
+
const imported = new Map<
|
|
1020
|
+
string,
|
|
1021
|
+
{ doc: IndexedDocument; exportedName: string; modulePath: string }
|
|
1022
|
+
>();
|
|
1023
|
+
for (const match of source.matchAll(
|
|
1024
|
+
/^\s*import\s+(?:type\s+)?\{([^}]+)\}\s+from\s+["']([^"']+)["']/gm,
|
|
1025
|
+
)) {
|
|
1026
|
+
const specList = match[1];
|
|
1027
|
+
const modulePath = match[2];
|
|
1028
|
+
const targetDoc = resolveModuleDoc(uri, modulePath, documents);
|
|
1029
|
+
if (!targetDoc) continue;
|
|
1030
|
+
for (const rawSpec of specList.split(",")) {
|
|
1031
|
+
const cleaned = rawSpec.trim().replace(/^type\s+/, "");
|
|
1032
|
+
if (!cleaned) continue;
|
|
1033
|
+
const aliasMatch = /^([A-Za-z_$][\w$]*)\s+as\s+([A-Za-z_$][\w$]*)$/.exec(
|
|
1034
|
+
cleaned,
|
|
1035
|
+
);
|
|
1036
|
+
const exportedName = aliasMatch ? aliasMatch[1] : cleaned;
|
|
1037
|
+
const localName = aliasMatch ? aliasMatch[2] : cleaned;
|
|
1038
|
+
imported.set(localName, { doc: targetDoc, exportedName, modulePath });
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
return imported;
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
function findBindingInProgram(
|
|
1045
|
+
program: Program,
|
|
1046
|
+
name: string,
|
|
1047
|
+
): BindingDeclaration | null {
|
|
1048
|
+
for (const top of program.body) {
|
|
1049
|
+
const inner = top.kind === "ExportDeclaration" ? top.declaration : top;
|
|
1050
|
+
if (
|
|
1051
|
+
inner.kind === "BindingDeclaration" &&
|
|
1052
|
+
"name" in inner.id &&
|
|
1053
|
+
inner.id.name === name
|
|
1054
|
+
) {
|
|
1055
|
+
return inner;
|
|
1056
|
+
}
|
|
1057
|
+
}
|
|
1058
|
+
return null;
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
function resolvePropsFromTypeNode(
|
|
1062
|
+
typeNode: TypeNode,
|
|
1063
|
+
ownerText: string,
|
|
1064
|
+
ownerUri: string,
|
|
1065
|
+
documents: IndexedDocument[],
|
|
1066
|
+
): Array<{ name: string; type: string }> {
|
|
1067
|
+
if (typeNode.kind === "RecordTypeNode") {
|
|
1068
|
+
return typeNode.fields.map((f) => ({
|
|
1069
|
+
name: f.name.name,
|
|
1070
|
+
type: formatTypeNode(f.typeAnnotation),
|
|
1071
|
+
}));
|
|
1072
|
+
}
|
|
1073
|
+
if (typeNode.kind === "TypeReferenceNode") {
|
|
1074
|
+
const schemaName = typeNode.name.name;
|
|
1075
|
+
const localFields = collectSchemaMembersFromText(
|
|
1076
|
+
ownerText,
|
|
1077
|
+
ownerUri,
|
|
1078
|
+
schemaName,
|
|
1079
|
+
);
|
|
1080
|
+
if (localFields.length > 0) {
|
|
1081
|
+
return localFields.map((f) => ({ name: f.name, type: f.detail }));
|
|
1082
|
+
}
|
|
1083
|
+
const ownerImports = collectImportedSymbols(ownerText, ownerUri, documents);
|
|
1084
|
+
const importedSchema = ownerImports.get(schemaName);
|
|
1085
|
+
if (importedSchema) {
|
|
1086
|
+
return collectSchemaMembersFromText(
|
|
1087
|
+
importedSchema.doc.text,
|
|
1088
|
+
importedSchema.doc.uri,
|
|
1089
|
+
importedSchema.exportedName,
|
|
1090
|
+
).map((f) => ({ name: f.name, type: f.detail }));
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
return [];
|
|
1094
|
+
}
|
|
1095
|
+
|
|
1096
|
+
function resolveFunctionComponentProps(
|
|
1097
|
+
binding: BindingDeclaration,
|
|
1098
|
+
ownerText: string,
|
|
1099
|
+
ownerUri: string,
|
|
1100
|
+
documents: IndexedDocument[],
|
|
1101
|
+
): Array<{ name: string; type: string }> {
|
|
1102
|
+
if (binding.init.kind === "FunctionExpression") {
|
|
1103
|
+
const firstParam = binding.init.params[0];
|
|
1104
|
+
if (firstParam?.typeAnnotation) {
|
|
1105
|
+
return resolvePropsFromTypeNode(
|
|
1106
|
+
firstParam.typeAnnotation,
|
|
1107
|
+
ownerText,
|
|
1108
|
+
ownerUri,
|
|
1109
|
+
documents,
|
|
1110
|
+
);
|
|
1111
|
+
}
|
|
1112
|
+
}
|
|
1113
|
+
if (binding.typeAnnotation?.kind === "FunctionTypeNode") {
|
|
1114
|
+
const firstParam = binding.typeAnnotation.params[0];
|
|
1115
|
+
if (firstParam?.typeAnnotation) {
|
|
1116
|
+
return resolvePropsFromTypeNode(
|
|
1117
|
+
firstParam.typeAnnotation,
|
|
1118
|
+
ownerText,
|
|
1119
|
+
ownerUri,
|
|
1120
|
+
documents,
|
|
1121
|
+
);
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
return [];
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function parseCleanPrefixAst(source: string, uri: string): Program | null {
|
|
1128
|
+
const direct = tryParse(source, uri);
|
|
1129
|
+
if (direct) return direct;
|
|
1130
|
+
// When the user is mid-edit on a JSX tag, strip trailing lines until a clean AST parses
|
|
1131
|
+
const lines = source.split("\n");
|
|
1132
|
+
for (let end = lines.length - 1; end >= 1; end--) {
|
|
1133
|
+
const candidate = lines.slice(0, end).join("\n");
|
|
1134
|
+
const parsed = tryParse(candidate, uri);
|
|
1135
|
+
if (parsed) return parsed;
|
|
1136
|
+
}
|
|
1137
|
+
return null;
|
|
1138
|
+
}
|
|
1139
|
+
|
|
1140
|
+
function collectComponentProps(
|
|
1141
|
+
source: string,
|
|
1142
|
+
uri: string,
|
|
1143
|
+
tagName: string,
|
|
1144
|
+
documents: IndexedDocument[],
|
|
1145
|
+
): Array<{ name: string; type: string }> {
|
|
1146
|
+
const dotIdx = tagName.indexOf(".");
|
|
1147
|
+
if (dotIdx !== -1) {
|
|
1148
|
+
const objName = tagName.slice(0, dotIdx);
|
|
1149
|
+
const propName = tagName.slice(dotIdx + 1);
|
|
1150
|
+
let ownerText = source;
|
|
1151
|
+
let ownerUri = uri;
|
|
1152
|
+
let targetObjName = objName;
|
|
1153
|
+
|
|
1154
|
+
const imported = collectImportedSymbols(source, uri, documents).get(
|
|
1155
|
+
objName,
|
|
1156
|
+
);
|
|
1157
|
+
if (imported) {
|
|
1158
|
+
ownerText = imported.doc.text;
|
|
1159
|
+
ownerUri = imported.doc.uri;
|
|
1160
|
+
targetObjName = imported.exportedName;
|
|
1161
|
+
} else {
|
|
1162
|
+
const ns = collectNamespaceImports(source, uri, documents).get(objName);
|
|
1163
|
+
if (ns) {
|
|
1164
|
+
const nsAst = parseCleanPrefixAst(ns.doc.text, ns.doc.uri);
|
|
1165
|
+
const memberBinding = nsAst
|
|
1166
|
+
? findBindingInProgram(nsAst, propName)
|
|
1167
|
+
: null;
|
|
1168
|
+
if (memberBinding) {
|
|
1169
|
+
return resolveFunctionComponentProps(
|
|
1170
|
+
memberBinding,
|
|
1171
|
+
ns.doc.text,
|
|
1172
|
+
ns.doc.uri,
|
|
1173
|
+
documents,
|
|
1174
|
+
);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
const ast = parseCleanPrefixAst(ownerText, ownerUri);
|
|
1180
|
+
const binding = ast ? findBindingInProgram(ast, targetObjName) : null;
|
|
1181
|
+
if (binding && binding.init.kind === "RecordExpression") {
|
|
1182
|
+
const field = binding.init.entries.find(
|
|
1183
|
+
(e) => e.kind === "FieldEntry" && e.key.name === propName,
|
|
1184
|
+
);
|
|
1185
|
+
if (
|
|
1186
|
+
field &&
|
|
1187
|
+
field.kind === "FieldEntry" &&
|
|
1188
|
+
field.value.kind === "FunctionExpression"
|
|
1189
|
+
) {
|
|
1190
|
+
const firstParam = field.value.params[0];
|
|
1191
|
+
if (firstParam?.typeAnnotation) {
|
|
1192
|
+
return resolvePropsFromTypeNode(
|
|
1193
|
+
firstParam.typeAnnotation,
|
|
1194
|
+
ownerText,
|
|
1195
|
+
ownerUri,
|
|
1196
|
+
documents,
|
|
1197
|
+
);
|
|
1198
|
+
}
|
|
1199
|
+
}
|
|
1200
|
+
}
|
|
1201
|
+
return [];
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
let ownerText = source;
|
|
1205
|
+
let ownerUri = uri;
|
|
1206
|
+
let targetName = tagName;
|
|
1207
|
+
|
|
1208
|
+
const imported = collectImportedSymbols(source, uri, documents).get(tagName);
|
|
1209
|
+
if (imported) {
|
|
1210
|
+
ownerText = imported.doc.text;
|
|
1211
|
+
ownerUri = imported.doc.uri;
|
|
1212
|
+
targetName = imported.exportedName;
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
const ast = parseCleanPrefixAst(ownerText, ownerUri);
|
|
1216
|
+
if (ast) {
|
|
1217
|
+
const binding = findBindingInProgram(ast, targetName);
|
|
1218
|
+
if (binding) {
|
|
1219
|
+
const props = resolveFunctionComponentProps(
|
|
1220
|
+
binding,
|
|
1221
|
+
ownerText,
|
|
1222
|
+
ownerUri,
|
|
1223
|
+
documents,
|
|
1224
|
+
);
|
|
1225
|
+
if (props.length > 0) return props;
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
|
|
1229
|
+
// Regex fallback when AST parsing fails due to incomplete syntax
|
|
1230
|
+
const fnRe = new RegExp(
|
|
1231
|
+
`(?:^|\\n)\\s*(?:export\\s+)?${escapeRegExp(targetName)}\\s*(?::[^=\\n]+)?=\\s*\\(\\s*[A-Za-z_$][\\w$]*\\s*:\\s*([A-Za-z_$][\\w$]*|\\{[^}]*\\})\\s*\\)`,
|
|
1232
|
+
);
|
|
1233
|
+
const fnMatch = fnRe.exec(ownerText);
|
|
1234
|
+
if (fnMatch) {
|
|
1235
|
+
const paramType = fnMatch[1].trim();
|
|
1236
|
+
if (paramType.startsWith("{")) {
|
|
1237
|
+
const fields: Array<{ name: string; type: string }> = [];
|
|
1238
|
+
for (const f of paramType
|
|
1239
|
+
.slice(1, -1)
|
|
1240
|
+
.matchAll(/([A-Za-z_$][\w$]*)\s*:\s*([^,\n}]+)/g)) {
|
|
1241
|
+
fields.push({ name: f[1], type: f[2].trim() });
|
|
1242
|
+
}
|
|
1243
|
+
return fields;
|
|
1244
|
+
}
|
|
1245
|
+
const schemaFields = collectSchemaMembersFromText(
|
|
1246
|
+
ownerText,
|
|
1247
|
+
ownerUri,
|
|
1248
|
+
paramType,
|
|
1249
|
+
);
|
|
1250
|
+
if (schemaFields.length > 0) {
|
|
1251
|
+
return schemaFields.map((f) => ({ name: f.name, type: f.detail }));
|
|
1252
|
+
}
|
|
1253
|
+
const ownerImports = collectImportedSymbols(ownerText, ownerUri, documents);
|
|
1254
|
+
const importedSchema = ownerImports.get(paramType);
|
|
1255
|
+
if (importedSchema) {
|
|
1256
|
+
return collectSchemaMembersFromText(
|
|
1257
|
+
importedSchema.doc.text,
|
|
1258
|
+
importedSchema.doc.uri,
|
|
1259
|
+
importedSchema.exportedName,
|
|
1260
|
+
).map((f) => ({ name: f.name, type: f.detail }));
|
|
1261
|
+
}
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
return [];
|
|
1265
|
+
}
|
|
1266
|
+
|
|
1267
|
+
function collectPascalCaseComponents(
|
|
1268
|
+
priorSource: string,
|
|
1269
|
+
source: string,
|
|
1270
|
+
uri: string,
|
|
1271
|
+
documents: IndexedDocument[],
|
|
1272
|
+
): Set<string> {
|
|
1273
|
+
const components = new Set<string>();
|
|
1274
|
+
const nonComponentDecls = new Set<string>();
|
|
1275
|
+
|
|
1276
|
+
for (const found of source.matchAll(
|
|
1277
|
+
/\b(?:export\s+)?(?:schema|error|service)\s+([A-Z][\w$]*)/g,
|
|
1278
|
+
)) {
|
|
1279
|
+
nonComponentDecls.add(found[1]);
|
|
1280
|
+
}
|
|
1281
|
+
|
|
1282
|
+
for (const found of priorSource.matchAll(
|
|
1283
|
+
/^\s*(?:export\s+)?(?:mut\s+)?([A-Z][\w$]*)\s*(?:=|:)/gm,
|
|
1284
|
+
)) {
|
|
1285
|
+
if (!nonComponentDecls.has(found[1])) {
|
|
1286
|
+
components.add(found[1]);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
for (const [localName, info] of collectImportedSymbols(
|
|
1291
|
+
source,
|
|
1292
|
+
uri,
|
|
1293
|
+
documents,
|
|
1294
|
+
)) {
|
|
1295
|
+
if (!/^[A-Z]/.test(localName)) continue;
|
|
1296
|
+
const isNonComponent = new RegExp(
|
|
1297
|
+
`\\bexport\\s+(?:schema|error|service)\\s+${escapeRegExp(info.exportedName)}\\b`,
|
|
1298
|
+
).test(info.doc.text);
|
|
1299
|
+
if (!isNonComponent) {
|
|
1300
|
+
components.add(localName);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
|
|
1304
|
+
for (const [nsName] of collectNamespaceImports(source, uri, documents)) {
|
|
1305
|
+
if (/^[A-Z]/.test(nsName)) {
|
|
1306
|
+
components.add(nsName);
|
|
1307
|
+
}
|
|
1308
|
+
}
|
|
1309
|
+
|
|
1310
|
+
return components;
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
function makeItemAdder(
|
|
1314
|
+
prefix: string,
|
|
1315
|
+
range: Range,
|
|
1316
|
+
items: Map<string, CompletionItem>,
|
|
1317
|
+
exclude?: string,
|
|
1318
|
+
) {
|
|
1319
|
+
return (
|
|
1320
|
+
label: string,
|
|
1321
|
+
kind: CompletionItemKind,
|
|
1322
|
+
detail: string,
|
|
1323
|
+
documentation?: string,
|
|
1324
|
+
sortPrefix = "",
|
|
1325
|
+
) => {
|
|
1326
|
+
if (prefix && !label.toLowerCase().startsWith(prefix.toLowerCase())) return;
|
|
1327
|
+
if (exclude && label === exclude) return;
|
|
1328
|
+
items.set(label, {
|
|
1329
|
+
label,
|
|
1330
|
+
kind,
|
|
1331
|
+
detail,
|
|
1332
|
+
...(documentation ? { documentation } : {}),
|
|
1333
|
+
textEdit: { range, newText: label },
|
|
1334
|
+
sortText: `${sortPrefix}${label.toLowerCase()}`,
|
|
1335
|
+
});
|
|
1336
|
+
};
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
function sortCompletionItems(
|
|
1340
|
+
items: Map<string, CompletionItem>,
|
|
1341
|
+
): CompletionItem[] {
|
|
1342
|
+
return [...items.values()].sort(
|
|
1343
|
+
(a, b) =>
|
|
1344
|
+
String(a.sortText).localeCompare(String(b.sortText)) ||
|
|
1345
|
+
a.label.localeCompare(b.label),
|
|
1346
|
+
);
|
|
1347
|
+
}
|
|
1348
|
+
|
|
83
1349
|
/** Builds completion candidates from the current open workspace snapshot. */
|
|
84
1350
|
export function complete(
|
|
85
1351
|
source: string,
|
|
@@ -88,6 +1354,7 @@ export function complete(
|
|
|
88
1354
|
documents: IndexedDocument[],
|
|
89
1355
|
pipelineAnalysis?: { source: string; inputs: Array<[number, string]> },
|
|
90
1356
|
): CompletionItem[] {
|
|
1357
|
+
const isFunx = uri.endsWith(".funx");
|
|
91
1358
|
const lines = source.split("\n");
|
|
92
1359
|
const line = lines[position.line] ?? "";
|
|
93
1360
|
const before = line.slice(0, position.character);
|
|
@@ -95,53 +1362,198 @@ export function complete(
|
|
|
95
1362
|
lines.slice(0, position.line).join("\n") +
|
|
96
1363
|
(position.line > 0 ? "\n" : "") +
|
|
97
1364
|
before;
|
|
1365
|
+
const sourceUpToCursor = lines
|
|
1366
|
+
.slice(0, position.line)
|
|
1367
|
+
.concat(before)
|
|
1368
|
+
.join("\n");
|
|
1369
|
+
const jsxCtx: JsxCursorContext = isFunx
|
|
1370
|
+
? detectJsxContext(sourceUpToCursor)
|
|
1371
|
+
: { kind: "normal" };
|
|
1372
|
+
|
|
1373
|
+
if (isFunx && jsxCtx.kind === "non-jsx") {
|
|
1374
|
+
return [];
|
|
1375
|
+
}
|
|
1376
|
+
|
|
1377
|
+
if (isFunx && jsxCtx.kind === "jsx-open-tag") {
|
|
1378
|
+
const items = new Map<string, CompletionItem>();
|
|
1379
|
+
const range: Range = {
|
|
1380
|
+
start: {
|
|
1381
|
+
line: position.line,
|
|
1382
|
+
character: position.character - jsxCtx.prefix.length,
|
|
1383
|
+
},
|
|
1384
|
+
end: position,
|
|
1385
|
+
};
|
|
1386
|
+
const add = makeItemAdder(jsxCtx.prefix, range, items);
|
|
1387
|
+
for (const comp of collectPascalCaseComponents(
|
|
1388
|
+
priorSource,
|
|
1389
|
+
source,
|
|
1390
|
+
uri,
|
|
1391
|
+
documents,
|
|
1392
|
+
)) {
|
|
1393
|
+
add(comp, CompletionItemKind.Function, "JSX component", undefined, "0-");
|
|
1394
|
+
}
|
|
1395
|
+
for (const tag of INTRINSIC_JSX_TAGS) {
|
|
1396
|
+
add(tag, CompletionItemKind.Property, "JSX element", undefined, "1-");
|
|
1397
|
+
}
|
|
1398
|
+
return sortCompletionItems(items);
|
|
1399
|
+
}
|
|
1400
|
+
|
|
1401
|
+
if (isFunx && jsxCtx.kind === "jsx-close-tag") {
|
|
1402
|
+
const items = new Map<string, CompletionItem>();
|
|
1403
|
+
const range: Range = {
|
|
1404
|
+
start: {
|
|
1405
|
+
line: position.line,
|
|
1406
|
+
character: position.character - jsxCtx.prefix.length,
|
|
1407
|
+
},
|
|
1408
|
+
end: position,
|
|
1409
|
+
};
|
|
1410
|
+
const add = makeItemAdder(jsxCtx.prefix, range, items);
|
|
1411
|
+
if (jsxCtx.expectedTag) {
|
|
1412
|
+
add(jsxCtx.expectedTag, CompletionItemKind.Property, "Closing JSX tag");
|
|
1413
|
+
}
|
|
1414
|
+
return [...items.values()];
|
|
1415
|
+
}
|
|
1416
|
+
|
|
1417
|
+
if (isFunx && jsxCtx.kind === "jsx-attribute") {
|
|
1418
|
+
const items = new Map<string, CompletionItem>();
|
|
1419
|
+
const range: Range = {
|
|
1420
|
+
start: {
|
|
1421
|
+
line: position.line,
|
|
1422
|
+
character: position.character - jsxCtx.prefix.length,
|
|
1423
|
+
},
|
|
1424
|
+
end: position,
|
|
1425
|
+
};
|
|
1426
|
+
const add = makeItemAdder(jsxCtx.prefix, range, items);
|
|
1427
|
+
for (const prop of collectComponentProps(
|
|
1428
|
+
source,
|
|
1429
|
+
uri,
|
|
1430
|
+
jsxCtx.tagName,
|
|
1431
|
+
documents,
|
|
1432
|
+
)) {
|
|
1433
|
+
if (jsxCtx.usedAttrs.has(prop.name)) continue;
|
|
1434
|
+
add(
|
|
1435
|
+
prop.name,
|
|
1436
|
+
CompletionItemKind.Property,
|
|
1437
|
+
prop.type,
|
|
1438
|
+
`${jsxCtx.tagName} prop`,
|
|
1439
|
+
"0-",
|
|
1440
|
+
);
|
|
1441
|
+
}
|
|
1442
|
+
for (const common of COMMON_JSX_PROPS) {
|
|
1443
|
+
if (jsxCtx.usedAttrs.has(common) || items.has(common)) continue;
|
|
1444
|
+
add(
|
|
1445
|
+
common,
|
|
1446
|
+
CompletionItemKind.Property,
|
|
1447
|
+
"JSX attribute",
|
|
1448
|
+
undefined,
|
|
1449
|
+
"1-",
|
|
1450
|
+
);
|
|
1451
|
+
}
|
|
1452
|
+
return sortCompletionItems(items);
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
const isJsxMemberTag = isFunx && jsxCtx.kind === "jsx-member-tag";
|
|
98
1456
|
const match = before.match(/[\w$.-]*$/);
|
|
99
1457
|
const typedPrefix = match?.[0] ?? "";
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
const
|
|
1458
|
+
const deferredPipelineContext =
|
|
1459
|
+
!isJsxMemberTag && /\|>>\s*(?:[\w.]*)$/.test(before);
|
|
1460
|
+
const pipelineContext =
|
|
1461
|
+
!isJsxMemberTag &&
|
|
1462
|
+
!deferredPipelineContext &&
|
|
1463
|
+
/\|>\s*(?:[\w.]*)$/.test(before);
|
|
1464
|
+
const member = isJsxMemberTag
|
|
1465
|
+
? jsxCtx.objectName
|
|
1466
|
+
: !deferredPipelineContext && !pipelineContext
|
|
1467
|
+
? /([A-Za-z_$][\w$]*)\.$/.exec(before)?.[1]
|
|
1468
|
+
: undefined;
|
|
1469
|
+
const prefix = isJsxMemberTag ? jsxCtx.prefix : member ? "" : typedPrefix;
|
|
1470
|
+
const start = position.character - prefix.length;
|
|
103
1471
|
const range: Range = {
|
|
104
1472
|
start: { line: position.line, character: start },
|
|
105
1473
|
end: position,
|
|
106
1474
|
};
|
|
107
1475
|
const items = new Map<string, CompletionItem>();
|
|
108
|
-
const add = (
|
|
109
|
-
label: string,
|
|
110
|
-
kind: CompletionItemKind,
|
|
111
|
-
detail: string,
|
|
112
|
-
documentation?: string,
|
|
113
|
-
) => {
|
|
114
|
-
if (prefix && !label.toLowerCase().startsWith(prefix.toLowerCase())) return;
|
|
115
|
-
if (label === member) return;
|
|
116
|
-
items.set(label, {
|
|
117
|
-
label,
|
|
118
|
-
kind,
|
|
119
|
-
detail,
|
|
120
|
-
...(documentation ? { documentation } : {}),
|
|
121
|
-
textEdit: { range, newText: label },
|
|
122
|
-
sortText: label.toLowerCase(),
|
|
123
|
-
});
|
|
124
|
-
};
|
|
1476
|
+
const add = makeItemAdder(prefix, range, items, member);
|
|
125
1477
|
|
|
126
1478
|
if (member) {
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
1479
|
+
for (const item of collectSchemaMembersFromText(source, uri, member)) {
|
|
1480
|
+
add(item.name, item.kind, item.detail);
|
|
1481
|
+
}
|
|
1482
|
+
for (const svcMethod of collectServiceMembersFromText(
|
|
1483
|
+
source,
|
|
1484
|
+
uri,
|
|
1485
|
+
member,
|
|
1486
|
+
)) {
|
|
1487
|
+
add(
|
|
1488
|
+
svcMethod.name,
|
|
1489
|
+
CompletionItemKind.Method,
|
|
1490
|
+
svcMethod.detail,
|
|
1491
|
+
`${member}.${svcMethod.name}`,
|
|
1492
|
+
);
|
|
1493
|
+
}
|
|
1494
|
+
for (const recField of collectRecordBindingMembersFromText(
|
|
1495
|
+
source,
|
|
1496
|
+
uri,
|
|
1497
|
+
member,
|
|
1498
|
+
)) {
|
|
1499
|
+
add(recField.name, recField.kind, recField.detail);
|
|
1500
|
+
}
|
|
1501
|
+
|
|
1502
|
+
const importedTarget = collectImportedSymbols(source, uri, documents).get(
|
|
1503
|
+
member,
|
|
1504
|
+
);
|
|
1505
|
+
if (importedTarget) {
|
|
1506
|
+
for (const svcMethod of collectServiceMembersFromText(
|
|
1507
|
+
importedTarget.doc.text,
|
|
1508
|
+
importedTarget.doc.uri,
|
|
1509
|
+
importedTarget.exportedName,
|
|
1510
|
+
)) {
|
|
1511
|
+
add(
|
|
1512
|
+
svcMethod.name,
|
|
1513
|
+
CompletionItemKind.Method,
|
|
1514
|
+
svcMethod.detail,
|
|
1515
|
+
`${member}.${svcMethod.name} (from ${importedTarget.modulePath})`,
|
|
1516
|
+
);
|
|
1517
|
+
}
|
|
1518
|
+
for (const item of collectSchemaMembersFromText(
|
|
1519
|
+
importedTarget.doc.text,
|
|
1520
|
+
importedTarget.doc.uri,
|
|
1521
|
+
importedTarget.exportedName,
|
|
1522
|
+
)) {
|
|
1523
|
+
add(item.name, item.kind, item.detail);
|
|
1524
|
+
}
|
|
1525
|
+
for (const recField of collectRecordBindingMembersFromText(
|
|
1526
|
+
importedTarget.doc.text,
|
|
1527
|
+
importedTarget.doc.uri,
|
|
1528
|
+
importedTarget.exportedName,
|
|
1529
|
+
)) {
|
|
1530
|
+
add(
|
|
1531
|
+
recField.name,
|
|
1532
|
+
recField.kind,
|
|
1533
|
+
recField.detail,
|
|
1534
|
+
`${member}.${recField.name} (from ${importedTarget.modulePath})`,
|
|
1535
|
+
);
|
|
1536
|
+
}
|
|
1537
|
+
}
|
|
1538
|
+
|
|
1539
|
+
const namespaceTarget = collectNamespaceImports(source, uri, documents).get(
|
|
1540
|
+
member,
|
|
1541
|
+
);
|
|
1542
|
+
if (namespaceTarget) {
|
|
1543
|
+
for (const exp of collectExportedSymbolsFromText(
|
|
1544
|
+
namespaceTarget.doc.text,
|
|
1545
|
+
namespaceTarget.doc.uri,
|
|
1546
|
+
)) {
|
|
1547
|
+
add(
|
|
1548
|
+
exp.name,
|
|
1549
|
+
exp.kind,
|
|
1550
|
+
exp.detail,
|
|
1551
|
+
`${member}.${exp.name} (from ${namespaceTarget.modulePath})`,
|
|
1552
|
+
);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
if (member === "Effect") {
|
|
145
1557
|
for (const key of getAllDocKeywords().filter((key) =>
|
|
146
1558
|
key.startsWith("Effect."),
|
|
147
1559
|
)) {
|
|
@@ -153,6 +1565,7 @@ export function complete(
|
|
|
153
1565
|
doc.summary,
|
|
154
1566
|
);
|
|
155
1567
|
}
|
|
1568
|
+
}
|
|
156
1569
|
} else {
|
|
157
1570
|
const visible = new Set<string>();
|
|
158
1571
|
for (const doc of documents) {
|
|
@@ -187,10 +1600,6 @@ export function complete(
|
|
|
187
1600
|
}
|
|
188
1601
|
}
|
|
189
1602
|
}
|
|
190
|
-
const deferredPipelineContext = /\|>>\s*(?:[\w.]*)$/.test(before);
|
|
191
|
-
const pipelineContext =
|
|
192
|
-
!deferredPipelineContext && /\|>\s*(?:[\w.]*)$/.test(before);
|
|
193
|
-
const jsxContext = /<\s*[A-Za-z_$\w]*$/.test(before);
|
|
194
1603
|
if (!deferredPipelineContext) {
|
|
195
1604
|
for (const name of visible)
|
|
196
1605
|
add(name, CompletionItemKind.Variable, "Workspace symbol");
|
|
@@ -315,29 +1724,6 @@ export function complete(
|
|
|
315
1724
|
}
|
|
316
1725
|
}
|
|
317
1726
|
}
|
|
318
|
-
if (/\.funx?$/.test(uri) && jsxContext)
|
|
319
|
-
for (const tag of [
|
|
320
|
-
"div",
|
|
321
|
-
"span",
|
|
322
|
-
"button",
|
|
323
|
-
"input",
|
|
324
|
-
"form",
|
|
325
|
-
"main",
|
|
326
|
-
"section",
|
|
327
|
-
"header",
|
|
328
|
-
"footer",
|
|
329
|
-
"ul",
|
|
330
|
-
"li",
|
|
331
|
-
"a",
|
|
332
|
-
"p",
|
|
333
|
-
"h1",
|
|
334
|
-
"h2",
|
|
335
|
-
])
|
|
336
|
-
add(tag, CompletionItemKind.Property, "JSX element");
|
|
337
1727
|
}
|
|
338
|
-
return
|
|
339
|
-
(a, b) =>
|
|
340
|
-
String(a.sortText).localeCompare(String(b.sortText)) ||
|
|
341
|
-
a.label.localeCompare(b.label),
|
|
342
|
-
);
|
|
1728
|
+
return sortCompletionItems(items);
|
|
343
1729
|
}
|