funkscript 0.0.0-stage → 0.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +204 -2
- package/dist/Widget.tsx +9 -0
- package/dist/ast/types.d.ts +513 -0
- package/dist/ast/types.d.ts.map +1 -0
- package/dist/ast/types.js +5 -0
- package/dist/ast/types.js.map +1 -0
- package/dist/ast/walk.d.ts +8 -0
- package/dist/ast/walk.d.ts.map +1 -0
- package/dist/ast/walk.js +23 -0
- package/dist/ast/walk.js.map +1 -0
- package/dist/cli/build-bun.d.ts +24 -0
- package/dist/cli/build-bun.d.ts.map +1 -0
- package/dist/cli/build-bun.js +190 -0
- package/dist/cli/build-bun.js.map +1 -0
- package/dist/cli/build-watch.d.ts +21 -0
- package/dist/cli/build-watch.d.ts.map +1 -0
- package/dist/cli/build-watch.js +244 -0
- package/dist/cli/build-watch.js.map +1 -0
- package/dist/cli/build.d.ts +4 -0
- package/dist/cli/build.d.ts.map +1 -0
- package/dist/cli/build.js +338 -0
- package/dist/cli/build.js.map +1 -0
- package/dist/cli/check.d.ts +4 -0
- package/dist/cli/check.d.ts.map +1 -0
- package/dist/cli/check.js +278 -0
- package/dist/cli/check.js.map +1 -0
- package/dist/cli/commands.d.ts +13 -0
- package/dist/cli/commands.d.ts.map +1 -0
- package/dist/cli/commands.js +262 -0
- package/dist/cli/commands.js.map +1 -0
- package/dist/cli/doc.d.ts +3 -0
- package/dist/cli/doc.d.ts.map +1 -0
- package/dist/cli/doc.js +71 -0
- package/dist/cli/doc.js.map +1 -0
- package/dist/cli/doctor.d.ts +3 -0
- package/dist/cli/doctor.d.ts.map +1 -0
- package/dist/cli/doctor.js +121 -0
- package/dist/cli/doctor.js.map +1 -0
- package/dist/cli/emit.d.ts +4 -0
- package/dist/cli/emit.d.ts.map +1 -0
- package/dist/cli/emit.js +87 -0
- package/dist/cli/emit.js.map +1 -0
- package/dist/cli/explain.d.ts +3 -0
- package/dist/cli/explain.d.ts.map +1 -0
- package/dist/cli/explain.js +103 -0
- package/dist/cli/explain.js.map +1 -0
- package/dist/cli/fmt.d.ts +3 -0
- package/dist/cli/fmt.d.ts.map +1 -0
- package/dist/cli/fmt.js +146 -0
- package/dist/cli/fmt.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +186 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +10 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +412 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/io.d.ts +9 -0
- package/dist/cli/io.d.ts.map +1 -0
- package/dist/cli/io.js +113 -0
- package/dist/cli/io.js.map +1 -0
- package/dist/cli/output-collisions.d.ts +2 -0
- package/dist/cli/output-collisions.d.ts.map +1 -0
- package/dist/cli/output-collisions.js +39 -0
- package/dist/cli/output-collisions.js.map +1 -0
- package/dist/cli/pipeline-style.d.ts +3 -0
- package/dist/cli/pipeline-style.d.ts.map +1 -0
- package/dist/cli/pipeline-style.js +45 -0
- package/dist/cli/pipeline-style.js.map +1 -0
- package/dist/cli/repl.d.ts +37 -0
- package/dist/cli/repl.d.ts.map +1 -0
- package/dist/cli/repl.js +334 -0
- package/dist/cli/repl.js.map +1 -0
- package/dist/cli/run.d.ts +4 -0
- package/dist/cli/run.d.ts.map +1 -0
- package/dist/cli/run.js +185 -0
- package/dist/cli/run.js.map +1 -0
- package/dist/cli/test.d.ts +3 -0
- package/dist/cli/test.d.ts.map +1 -0
- package/dist/cli/test.js +124 -0
- package/dist/cli/test.js.map +1 -0
- package/dist/cli/tsc.d.ts +3 -0
- package/dist/cli/tsc.d.ts.map +1 -0
- package/dist/cli/tsc.js +143 -0
- package/dist/cli/tsc.js.map +1 -0
- package/dist/cli/typecheck.d.ts +23 -0
- package/dist/cli/typecheck.d.ts.map +1 -0
- package/dist/cli/typecheck.js +65 -0
- package/dist/cli/typecheck.js.map +1 -0
- package/dist/compiler/ast-inspection.d.ts +18 -0
- package/dist/compiler/ast-inspection.d.ts.map +1 -0
- package/dist/compiler/ast-inspection.js +96 -0
- package/dist/compiler/ast-inspection.js.map +1 -0
- package/dist/compiler/boolean-operators.d.ts +8 -0
- package/dist/compiler/boolean-operators.d.ts.map +1 -0
- package/dist/compiler/boolean-operators.js +84 -0
- package/dist/compiler/boolean-operators.js.map +1 -0
- package/dist/compiler/check.d.ts +87 -0
- package/dist/compiler/check.d.ts.map +1 -0
- package/dist/compiler/check.js +1830 -0
- package/dist/compiler/check.js.map +1 -0
- package/dist/compiler/diagnostics.d.ts +6 -0
- package/dist/compiler/diagnostics.d.ts.map +1 -0
- package/dist/compiler/diagnostics.js +136 -0
- package/dist/compiler/diagnostics.js.map +1 -0
- package/dist/compiler/effect-mutation-rule.d.ts +4 -0
- package/dist/compiler/effect-mutation-rule.d.ts.map +1 -0
- package/dist/compiler/effect-mutation-rule.js +348 -0
- package/dist/compiler/effect-mutation-rule.js.map +1 -0
- package/dist/compiler/entry-rules.d.ts +5 -0
- package/dist/compiler/entry-rules.d.ts.map +1 -0
- package/dist/compiler/entry-rules.js +89 -0
- package/dist/compiler/entry-rules.js.map +1 -0
- package/dist/compiler/imported-record-functions.d.ts +4 -0
- package/dist/compiler/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/imported-record-functions.js +706 -0
- package/dist/compiler/imported-record-functions.js.map +1 -0
- package/dist/compiler/imported-schemas.d.ts +21 -0
- package/dist/compiler/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/imported-schemas.js +461 -0
- package/dist/compiler/imported-schemas.js.map +1 -0
- package/dist/compiler/incremental-build.d.ts +23 -0
- package/dist/compiler/incremental-build.d.ts.map +1 -0
- package/dist/compiler/incremental-build.js +90 -0
- package/dist/compiler/incremental-build.js.map +1 -0
- package/dist/compiler/incremental-dependencies.d.ts +7 -0
- package/dist/compiler/incremental-dependencies.d.ts.map +1 -0
- package/dist/compiler/incremental-dependencies.js +190 -0
- package/dist/compiler/incremental-dependencies.js.map +1 -0
- package/dist/compiler/js-interop-nullability.d.ts +9 -0
- package/dist/compiler/js-interop-nullability.d.ts.map +1 -0
- package/dist/compiler/js-interop-nullability.js +57 -0
- package/dist/compiler/js-interop-nullability.js.map +1 -0
- package/dist/compiler/module-resolution.d.ts +6 -0
- package/dist/compiler/module-resolution.d.ts.map +1 -0
- package/dist/compiler/module-resolution.js +44 -0
- package/dist/compiler/module-resolution.js.map +1 -0
- package/dist/compiler/modules/output-collisions.d.ts +2 -0
- package/dist/compiler/modules/output-collisions.d.ts.map +1 -0
- package/dist/compiler/modules/output-collisions.js +39 -0
- package/dist/compiler/modules/output-collisions.js.map +1 -0
- package/dist/compiler/modules/output-plan.d.ts +7 -0
- package/dist/compiler/modules/output-plan.d.ts.map +1 -0
- package/dist/compiler/modules/output-plan.js +37 -0
- package/dist/compiler/modules/output-plan.js.map +1 -0
- package/dist/compiler/modules/resolution.d.ts +8 -0
- package/dist/compiler/modules/resolution.d.ts.map +1 -0
- package/dist/compiler/modules/resolution.js +48 -0
- package/dist/compiler/modules/resolution.js.map +1 -0
- package/dist/compiler/numeric-comparisons.d.ts +9 -0
- package/dist/compiler/numeric-comparisons.d.ts.map +1 -0
- package/dist/compiler/numeric-comparisons.js +153 -0
- package/dist/compiler/numeric-comparisons.js.map +1 -0
- package/dist/compiler/optional-arguments.d.ts +11 -0
- package/dist/compiler/optional-arguments.d.ts.map +1 -0
- package/dist/compiler/optional-arguments.js +246 -0
- package/dist/compiler/optional-arguments.js.map +1 -0
- package/dist/compiler/package-fingerprint.d.ts +7 -0
- package/dist/compiler/package-fingerprint.d.ts.map +1 -0
- package/dist/compiler/package-fingerprint.js +178 -0
- package/dist/compiler/package-fingerprint.js.map +1 -0
- package/dist/compiler/package-record-contracts.d.ts +5 -0
- package/dist/compiler/package-record-contracts.d.ts.map +1 -0
- package/dist/compiler/package-record-contracts.js +126 -0
- package/dist/compiler/package-record-contracts.js.map +1 -0
- package/dist/compiler/pipeline-companions.d.ts +18 -0
- package/dist/compiler/pipeline-companions.d.ts.map +1 -0
- package/dist/compiler/pipeline-companions.js +1042 -0
- package/dist/compiler/pipeline-companions.js.map +1 -0
- package/dist/compiler/pipelines/catalog.d.ts +15 -0
- package/dist/compiler/pipelines/catalog.d.ts.map +1 -0
- package/dist/compiler/pipelines/catalog.js +55 -0
- package/dist/compiler/pipelines/catalog.js.map +1 -0
- package/dist/compiler/pipelines/companions.d.ts +18 -0
- package/dist/compiler/pipelines/companions.d.ts.map +1 -0
- package/dist/compiler/pipelines/companions.js +1042 -0
- package/dist/compiler/pipelines/companions.js.map +1 -0
- package/dist/compiler/pipelines/resolution.d.ts +38 -0
- package/dist/compiler/pipelines/resolution.d.ts.map +1 -0
- package/dist/compiler/pipelines/resolution.js +571 -0
- package/dist/compiler/pipelines/resolution.js.map +1 -0
- package/dist/compiler/project-config.d.ts +28 -0
- package/dist/compiler/project-config.d.ts.map +1 -0
- package/dist/compiler/project-config.js +155 -0
- package/dist/compiler/project-config.js.map +1 -0
- package/dist/compiler/providers.d.ts +4 -0
- package/dist/compiler/providers.d.ts.map +1 -0
- package/dist/compiler/providers.js +101 -0
- package/dist/compiler/providers.js.map +1 -0
- package/dist/compiler/record-contracts.d.ts +6 -0
- package/dist/compiler/record-contracts.d.ts.map +1 -0
- package/dist/compiler/record-contracts.js +41 -0
- package/dist/compiler/record-contracts.js.map +1 -0
- package/dist/compiler/rules/control-flow.d.ts +10 -0
- package/dist/compiler/rules/control-flow.d.ts.map +1 -0
- package/dist/compiler/rules/control-flow.js +19 -0
- package/dist/compiler/rules/control-flow.js.map +1 -0
- package/dist/compiler/rules/diagnostic.d.ts +4 -0
- package/dist/compiler/rules/diagnostic.d.ts.map +1 -0
- package/dist/compiler/rules/diagnostic.js +2 -0
- package/dist/compiler/rules/diagnostic.js.map +1 -0
- package/dist/compiler/rules/module-scope-refs.d.ts +5 -0
- package/dist/compiler/rules/module-scope-refs.d.ts.map +1 -0
- package/dist/compiler/rules/module-scope-refs.js +47 -0
- package/dist/compiler/rules/module-scope-refs.js.map +1 -0
- package/dist/compiler/schemas/analysis.d.ts +13 -0
- package/dist/compiler/schemas/analysis.d.ts.map +1 -0
- package/dist/compiler/schemas/analysis.js +24 -0
- package/dist/compiler/schemas/analysis.js.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts +4 -0
- package/dist/compiler/schemas/imported-record-functions.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-record-functions.js +706 -0
- package/dist/compiler/schemas/imported-record-functions.js.map +1 -0
- package/dist/compiler/schemas/imported-schemas.d.ts +21 -0
- package/dist/compiler/schemas/imported-schemas.d.ts.map +1 -0
- package/dist/compiler/schemas/imported-schemas.js +461 -0
- package/dist/compiler/schemas/imported-schemas.js.map +1 -0
- package/dist/compiler/source-map.d.ts +6 -0
- package/dist/compiler/source-map.d.ts.map +1 -0
- package/dist/compiler/source-map.js +127 -0
- package/dist/compiler/source-map.js.map +1 -0
- package/dist/compiler/typescript-context.d.ts +33 -0
- package/dist/compiler/typescript-context.d.ts.map +1 -0
- package/dist/compiler/typescript-context.js +200 -0
- package/dist/compiler/typescript-context.js.map +1 -0
- package/dist/compiler.d.ts +77 -0
- package/dist/compiler.d.ts.map +1 -0
- package/dist/compiler.js +497 -0
- package/dist/compiler.js.map +1 -0
- package/dist/emitter/assemblyscript.d.ts +5 -0
- package/dist/emitter/assemblyscript.d.ts.map +1 -0
- package/dist/emitter/assemblyscript.js +979 -0
- package/dist/emitter/assemblyscript.js.map +1 -0
- package/dist/emitter/declarations.d.ts +46 -0
- package/dist/emitter/declarations.d.ts.map +1 -0
- package/dist/emitter/declarations.js +739 -0
- package/dist/emitter/declarations.js.map +1 -0
- package/dist/emitter/emitter.d.ts +165 -0
- package/dist/emitter/emitter.d.ts.map +1 -0
- package/dist/emitter/emitter.js +2448 -0
- package/dist/emitter/emitter.js.map +1 -0
- package/dist/emitter/imports.d.ts +6 -0
- package/dist/emitter/imports.d.ts.map +1 -0
- package/dist/emitter/imports.js +73 -0
- package/dist/emitter/imports.js.map +1 -0
- package/dist/emitter/indent.d.ts +3 -0
- package/dist/emitter/indent.d.ts.map +1 -0
- package/dist/emitter/indent.js +31 -0
- package/dist/emitter/indent.js.map +1 -0
- package/dist/emitter/jsx.d.ts +20 -0
- package/dist/emitter/jsx.d.ts.map +1 -0
- package/dist/emitter/jsx.js +82 -0
- package/dist/emitter/jsx.js.map +1 -0
- package/dist/emitter/local-bindings.d.ts +6 -0
- package/dist/emitter/local-bindings.d.ts.map +1 -0
- package/dist/emitter/local-bindings.js +32 -0
- package/dist/emitter/local-bindings.js.map +1 -0
- package/dist/emitter/match.d.ts +56 -0
- package/dist/emitter/match.d.ts.map +1 -0
- package/dist/emitter/match.js +1287 -0
- package/dist/emitter/match.js.map +1 -0
- package/dist/emitter/pipeline-catalog.d.ts +15 -0
- package/dist/emitter/pipeline-catalog.d.ts.map +1 -0
- package/dist/emitter/pipeline-catalog.js +55 -0
- package/dist/emitter/pipeline-catalog.js.map +1 -0
- package/dist/emitter/pipeline-resolution.d.ts +38 -0
- package/dist/emitter/pipeline-resolution.d.ts.map +1 -0
- package/dist/emitter/pipeline-resolution.js +571 -0
- package/dist/emitter/pipeline-resolution.js.map +1 -0
- package/dist/emitter/runtime-helpers.d.ts +10 -0
- package/dist/emitter/runtime-helpers.d.ts.map +1 -0
- package/dist/emitter/runtime-helpers.js +22 -0
- package/dist/emitter/runtime-helpers.js.map +1 -0
- package/dist/emitter/schemas.d.ts +36 -0
- package/dist/emitter/schemas.d.ts.map +1 -0
- package/dist/emitter/schemas.js +766 -0
- package/dist/emitter/schemas.js.map +1 -0
- package/dist/emitter/statements.d.ts +23 -0
- package/dist/emitter/statements.d.ts.map +1 -0
- package/dist/emitter/statements.js +216 -0
- package/dist/emitter/statements.js.map +1 -0
- package/dist/emitter/tagged-match.d.ts +23 -0
- package/dist/emitter/tagged-match.d.ts.map +1 -0
- package/dist/emitter/tagged-match.js +109 -0
- package/dist/emitter/tagged-match.js.map +1 -0
- package/dist/emitter/types.d.ts +22 -0
- package/dist/emitter/types.d.ts.map +1 -0
- package/dist/emitter/types.js +231 -0
- package/dist/emitter/types.js.map +1 -0
- package/dist/errors.d.ts +39 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +98 -0
- package/dist/errors.js.map +1 -0
- package/dist/formatter/comments.d.ts +25 -0
- package/dist/formatter/comments.d.ts.map +1 -0
- package/dist/formatter/comments.js +283 -0
- package/dist/formatter/comments.js.map +1 -0
- package/dist/formatter/index.d.ts +71 -0
- package/dist/formatter/index.d.ts.map +1 -0
- package/dist/formatter/index.js +1113 -0
- package/dist/formatter/index.js.map +1 -0
- package/dist/formatter/operator-precedence.d.ts +3 -0
- package/dist/formatter/operator-precedence.d.ts.map +1 -0
- package/dist/formatter/operator-precedence.js +27 -0
- package/dist/formatter/operator-precedence.js.map +1 -0
- package/dist/formatter/prettier.d.ts +7 -0
- package/dist/formatter/prettier.d.ts.map +1 -0
- package/dist/formatter/prettier.js +51 -0
- package/dist/formatter/prettier.js.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/interop/callback.d.ts +38 -0
- package/dist/interop/callback.d.ts.map +1 -0
- package/dist/interop/callback.js +130 -0
- package/dist/interop/callback.js.map +1 -0
- package/dist/interop/index.d.ts +6 -0
- package/dist/interop/index.d.ts.map +1 -0
- package/dist/interop/index.js +6 -0
- package/dist/interop/index.js.map +1 -0
- package/dist/interop/js.d.ts +16 -0
- package/dist/interop/js.d.ts.map +1 -0
- package/dist/interop/js.js +35 -0
- package/dist/interop/js.js.map +1 -0
- package/dist/interop/record.d.ts +9 -0
- package/dist/interop/record.d.ts.map +1 -0
- package/dist/interop/record.js +18 -0
- package/dist/interop/record.js.map +1 -0
- package/dist/interop/valibot.d.ts +9 -0
- package/dist/interop/valibot.d.ts.map +1 -0
- package/dist/interop/valibot.js +94 -0
- package/dist/interop/valibot.js.map +1 -0
- package/dist/interop/zod.d.ts +45 -0
- package/dist/interop/zod.d.ts.map +1 -0
- package/dist/interop/zod.js +143 -0
- package/dist/interop/zod.js.map +1 -0
- package/dist/lexer/lexer.d.ts +65 -0
- package/dist/lexer/lexer.d.ts.map +1 -0
- package/dist/lexer/lexer.js +1335 -0
- package/dist/lexer/lexer.js.map +1 -0
- package/dist/lexer/tokens.d.ts +96 -0
- package/dist/lexer/tokens.d.ts.map +1 -0
- package/dist/lexer/tokens.js +150 -0
- package/dist/lexer/tokens.js.map +1 -0
- package/dist/lsp/code-action-worker.d.ts +2 -0
- package/dist/lsp/code-action-worker.d.ts.map +1 -0
- package/dist/lsp/code-action-worker.js +17 -0
- package/dist/lsp/code-action-worker.js.map +1 -0
- package/dist/lsp/completion.d.ts +11 -0
- package/dist/lsp/completion.d.ts.map +1 -0
- package/dist/lsp/completion.js +260 -0
- package/dist/lsp/completion.js.map +1 -0
- package/dist/lsp/definition.d.ts +42 -0
- package/dist/lsp/definition.d.ts.map +1 -0
- package/dist/lsp/definition.js +1074 -0
- package/dist/lsp/definition.js.map +1 -0
- package/dist/lsp/diagnostics-worker.d.ts +2 -0
- package/dist/lsp/diagnostics-worker.d.ts.map +1 -0
- package/dist/lsp/diagnostics-worker.js +169 -0
- package/dist/lsp/diagnostics-worker.js.map +1 -0
- package/dist/lsp/docs.d.ts +37 -0
- package/dist/lsp/docs.d.ts.map +1 -0
- package/dist/lsp/docs.js +830 -0
- package/dist/lsp/docs.js.map +1 -0
- package/dist/lsp/error-channel.d.ts +3 -0
- package/dist/lsp/error-channel.d.ts.map +1 -0
- package/dist/lsp/error-channel.js +48 -0
- package/dist/lsp/error-channel.js.map +1 -0
- package/dist/lsp/hover.d.ts +5 -0
- package/dist/lsp/hover.d.ts.map +1 -0
- package/dist/lsp/hover.js +651 -0
- package/dist/lsp/hover.js.map +1 -0
- package/dist/lsp/imports.d.ts +5 -0
- package/dist/lsp/imports.d.ts.map +1 -0
- package/dist/lsp/imports.js +317 -0
- package/dist/lsp/imports.js.map +1 -0
- package/dist/lsp/index.d.ts +16 -0
- package/dist/lsp/index.d.ts.map +1 -0
- package/dist/lsp/index.js +17 -0
- package/dist/lsp/index.js.map +1 -0
- package/dist/lsp/inlay-hints.d.ts +3 -0
- package/dist/lsp/inlay-hints.d.ts.map +1 -0
- package/dist/lsp/inlay-hints.js +236 -0
- package/dist/lsp/inlay-hints.js.map +1 -0
- package/dist/lsp/interop-rename.d.ts +26 -0
- package/dist/lsp/interop-rename.d.ts.map +1 -0
- package/dist/lsp/interop-rename.js +346 -0
- package/dist/lsp/interop-rename.js.map +1 -0
- package/dist/lsp/match-arms.d.ts +3 -0
- package/dist/lsp/match-arms.d.ts.map +1 -0
- package/dist/lsp/match-arms.js +341 -0
- package/dist/lsp/match-arms.js.map +1 -0
- package/dist/lsp/navigation.d.ts +23 -0
- package/dist/lsp/navigation.d.ts.map +1 -0
- package/dist/lsp/navigation.js +430 -0
- package/dist/lsp/navigation.js.map +1 -0
- package/dist/lsp/parsed-documents.d.ts +25 -0
- package/dist/lsp/parsed-documents.d.ts.map +1 -0
- package/dist/lsp/parsed-documents.js +47 -0
- package/dist/lsp/parsed-documents.js.map +1 -0
- package/dist/lsp/rename-worker.d.ts +2 -0
- package/dist/lsp/rename-worker.d.ts.map +1 -0
- package/dist/lsp/rename-worker.js +27 -0
- package/dist/lsp/rename-worker.js.map +1 -0
- package/dist/lsp/server.d.ts +78 -0
- package/dist/lsp/server.d.ts.map +1 -0
- package/dist/lsp/server.js +1098 -0
- package/dist/lsp/server.js.map +1 -0
- package/dist/lsp/thunk-pipeline.d.ts +4 -0
- package/dist/lsp/thunk-pipeline.d.ts.map +1 -0
- package/dist/lsp/thunk-pipeline.js +95 -0
- package/dist/lsp/thunk-pipeline.js.map +1 -0
- package/dist/lsp/validation.d.ts +8 -0
- package/dist/lsp/validation.d.ts.map +1 -0
- package/dist/lsp/validation.js +124 -0
- package/dist/lsp/validation.js.map +1 -0
- package/dist/lsp/workspace.d.ts +8 -0
- package/dist/lsp/workspace.d.ts.map +1 -0
- package/dist/lsp/workspace.js +70 -0
- package/dist/lsp/workspace.js.map +1 -0
- package/dist/math.ts +1 -0
- package/dist/parser/declarations.d.ts +21 -0
- package/dist/parser/declarations.d.ts.map +1 -0
- package/dist/parser/declarations.js +626 -0
- package/dist/parser/declarations.js.map +1 -0
- package/dist/parser/errors.d.ts +9 -0
- package/dist/parser/errors.d.ts.map +1 -0
- package/dist/parser/errors.js +11 -0
- package/dist/parser/errors.js.map +1 -0
- package/dist/parser/index.d.ts +9 -0
- package/dist/parser/index.d.ts.map +1 -0
- package/dist/parser/index.js +9 -0
- package/dist/parser/index.js.map +1 -0
- package/dist/parser/jsx.d.ts +5 -0
- package/dist/parser/jsx.d.ts.map +1 -0
- package/dist/parser/jsx.js +188 -0
- package/dist/parser/jsx.js.map +1 -0
- package/dist/parser/operator-expressions.d.ts +16 -0
- package/dist/parser/operator-expressions.d.ts.map +1 -0
- package/dist/parser/operator-expressions.js +146 -0
- package/dist/parser/operator-expressions.js.map +1 -0
- package/dist/parser/parser.d.ts +104 -0
- package/dist/parser/parser.d.ts.map +1 -0
- package/dist/parser/parser.js +1216 -0
- package/dist/parser/parser.js.map +1 -0
- package/dist/parser/patterns.d.ts +9 -0
- package/dist/parser/patterns.d.ts.map +1 -0
- package/dist/parser/patterns.js +292 -0
- package/dist/parser/patterns.js.map +1 -0
- package/dist/parser/pipeline-expressions.d.ts +10 -0
- package/dist/parser/pipeline-expressions.d.ts.map +1 -0
- package/dist/parser/pipeline-expressions.js +57 -0
- package/dist/parser/pipeline-expressions.js.map +1 -0
- package/dist/parser/scope.d.ts +17 -0
- package/dist/parser/scope.d.ts.map +1 -0
- package/dist/parser/scope.js +56 -0
- package/dist/parser/scope.js.map +1 -0
- package/dist/parser/statements.d.ts +13 -0
- package/dist/parser/statements.d.ts.map +1 -0
- package/dist/parser/statements.js +737 -0
- package/dist/parser/statements.js.map +1 -0
- package/dist/parser/types.d.ts +13 -0
- package/dist/parser/types.d.ts.map +1 -0
- package/dist/parser/types.js +371 -0
- package/dist/parser/types.js.map +1 -0
- package/dist/plugins/bun-preload.d.ts +4 -0
- package/dist/plugins/bun-preload.d.ts.map +1 -0
- package/dist/plugins/bun-preload.js +18 -0
- package/dist/plugins/bun-preload.js.map +1 -0
- package/dist/plugins/bun.d.ts +115 -0
- package/dist/plugins/bun.d.ts.map +1 -0
- package/dist/plugins/bun.js +240 -0
- package/dist/plugins/bun.js.map +1 -0
- package/dist/plugins/esbuild.d.ts +45 -0
- package/dist/plugins/esbuild.d.ts.map +1 -0
- package/dist/plugins/esbuild.js +184 -0
- package/dist/plugins/esbuild.js.map +1 -0
- package/dist/plugins/type-view.d.ts +30 -0
- package/dist/plugins/type-view.d.ts.map +1 -0
- package/dist/plugins/type-view.js +245 -0
- package/dist/plugins/type-view.js.map +1 -0
- package/dist/plugins/vite.d.ts +56 -0
- package/dist/plugins/vite.d.ts.map +1 -0
- package/dist/plugins/vite.js +182 -0
- package/dist/plugins/vite.js.map +1 -0
- package/dist/service.ts +3 -0
- package/dist/service.ts.map +1 -0
- package/dist/testing/index.d.ts +24 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +56 -0
- package/dist/testing/index.js.map +1 -0
- package/dist/tooling/doc.d.ts +82 -0
- package/dist/tooling/doc.d.ts.map +1 -0
- package/dist/tooling/doc.js +624 -0
- package/dist/tooling/doc.js.map +1 -0
- package/dist/tooling/idiomatic.d.ts +20 -0
- package/dist/tooling/idiomatic.d.ts.map +1 -0
- package/dist/tooling/idiomatic.js +154 -0
- package/dist/tooling/idiomatic.js.map +1 -0
- package/dist/tooling/migrate.d.ts +62 -0
- package/dist/tooling/migrate.d.ts.map +1 -0
- package/dist/tooling/migrate.js +608 -0
- package/dist/tooling/migrate.js.map +1 -0
- package/dist/tooling/pipeline-style.d.ts +12 -0
- package/dist/tooling/pipeline-style.d.ts.map +1 -0
- package/dist/tooling/pipeline-style.js +208 -0
- package/dist/tooling/pipeline-style.js.map +1 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +25 -0
- package/dist/version.js.map +1 -0
- package/package.json +128 -4
- package/src/ast/types.ts +753 -0
- package/src/ast/walk.ts +35 -0
- package/src/cli/build-bun.ts +249 -0
- package/src/cli/build-watch.ts +299 -0
- package/src/cli/build.ts +450 -0
- package/src/cli/check.ts +342 -0
- package/src/cli/commands.ts +301 -0
- package/src/cli/doc.ts +81 -0
- package/src/cli/doctor.ts +173 -0
- package/src/cli/emit.ts +138 -0
- package/src/cli/explain.ts +127 -0
- package/src/cli/fmt.ts +170 -0
- package/src/cli/index.ts +227 -0
- package/src/cli/init.ts +491 -0
- package/src/cli/io.ts +150 -0
- package/src/cli/pipeline-style.ts +55 -0
- package/src/cli/repl.ts +443 -0
- package/src/cli/run.ts +238 -0
- package/src/cli/test.ts +148 -0
- package/src/cli/tsc.ts +207 -0
- package/src/cli/typecheck.ts +100 -0
- package/src/compiler/ast-inspection.ts +121 -0
- package/src/compiler/boolean-operators.ts +108 -0
- package/src/compiler/check.ts +2763 -0
- package/src/compiler/diagnostics.ts +179 -0
- package/src/compiler/effect-mutation-rule.ts +407 -0
- package/src/compiler/entry-rules.ts +116 -0
- package/src/compiler/incremental-build.ts +131 -0
- package/src/compiler/incremental-dependencies.ts +200 -0
- package/src/compiler/js-interop-nullability.ts +67 -0
- package/src/compiler/modules/output-collisions.ts +48 -0
- package/src/compiler/modules/output-plan.ts +46 -0
- package/src/compiler/modules/resolution.ts +56 -0
- package/src/compiler/numeric-comparisons.ts +213 -0
- package/src/compiler/optional-arguments.ts +335 -0
- package/src/compiler/package-fingerprint.ts +216 -0
- package/src/compiler/package-record-contracts.ts +156 -0
- package/src/compiler/pipelines/catalog.ts +1128 -0
- package/src/compiler/pipelines/companions.ts +1279 -0
- package/src/compiler/pipelines/resolution.ts +684 -0
- package/src/compiler/project-config.ts +221 -0
- package/src/compiler/record-contracts.ts +46 -0
- package/src/compiler/rules/control-flow.ts +57 -0
- package/src/compiler/rules/diagnostic.ts +11 -0
- package/src/compiler/rules/module-scope-refs.ts +63 -0
- package/src/compiler/schemas/analysis.ts +45 -0
- package/src/compiler/schemas/imported-record-functions.ts +984 -0
- package/src/compiler/schemas/imported-schemas.ts +761 -0
- package/src/compiler/source-map.ts +165 -0
- package/src/compiler/typescript-context.ts +250 -0
- package/src/compiler.ts +865 -0
- package/src/emitter/assemblyscript.ts +1220 -0
- package/src/emitter/declarations.ts +916 -0
- package/src/emitter/emitter.ts +3128 -0
- package/src/emitter/imports.ts +89 -0
- package/src/emitter/indent.ts +39 -0
- package/src/emitter/jsx.ts +122 -0
- package/src/emitter/local-bindings.ts +40 -0
- package/src/emitter/match.ts +1631 -0
- package/src/emitter/runtime-helpers.ts +31 -0
- package/src/emitter/schemas.ts +969 -0
- package/src/emitter/statements.ts +310 -0
- package/src/emitter/tagged-match.ts +171 -0
- package/src/emitter/types.ts +289 -0
- package/src/errors.ts +115 -0
- package/src/formatter/comments.ts +350 -0
- package/src/formatter/index.ts +1457 -0
- package/src/formatter/operator-precedence.ts +36 -0
- package/src/formatter/prettier.ts +61 -0
- package/src/index.ts +16 -0
- package/src/interop/callback.ts +188 -0
- package/src/interop/js.ts +66 -0
- package/src/interop/record.ts +36 -0
- package/src/interop/valibot.ts +141 -0
- package/src/interop/zod.ts +219 -0
- package/src/lexer/lexer.ts +1521 -0
- package/src/lexer/tokens.ts +174 -0
- package/src/lsp/code-action-worker.ts +31 -0
- package/src/lsp/completion.ts +343 -0
- package/src/lsp/definition.ts +1165 -0
- package/src/lsp/diagnostics-worker.ts +198 -0
- package/src/lsp/docs.ts +864 -0
- package/src/lsp/error-channel.ts +63 -0
- package/src/lsp/hover.ts +803 -0
- package/src/lsp/imports.ts +380 -0
- package/src/lsp/index.ts +55 -0
- package/src/lsp/inlay-hints.ts +308 -0
- package/src/lsp/interop-rename.ts +454 -0
- package/src/lsp/match-arms.ts +400 -0
- package/src/lsp/navigation.ts +553 -0
- package/src/lsp/parsed-documents.ts +64 -0
- package/src/lsp/rename-worker.ts +40 -0
- package/src/lsp/server.ts +1437 -0
- package/src/lsp/thunk-pipeline.ts +117 -0
- package/src/lsp/validation.ts +147 -0
- package/src/lsp/workspace.ts +74 -0
- package/src/parser/declarations.ts +808 -0
- package/src/parser/errors.ts +18 -0
- package/src/parser/jsx.ts +253 -0
- package/src/parser/operator-expressions.ts +170 -0
- package/src/parser/parser.ts +1565 -0
- package/src/parser/patterns.ts +342 -0
- package/src/parser/pipeline-expressions.ts +77 -0
- package/src/parser/scope.ts +69 -0
- package/src/parser/statements.ts +831 -0
- package/src/parser/types.ts +453 -0
- package/src/plugins/bun-preload.ts +25 -0
- package/src/plugins/bun.ts +448 -0
- package/src/plugins/esbuild.ts +308 -0
- package/src/plugins/type-view.ts +326 -0
- package/src/plugins/vite.ts +294 -0
- package/src/testing/index.ts +72 -0
- package/src/tooling/doc.ts +786 -0
- package/src/tooling/idiomatic.ts +202 -0
- package/src/tooling/pipeline-style.ts +248 -0
- package/src/version.ts +27 -0
|
@@ -0,0 +1,1437 @@
|
|
|
1
|
+
import { workspaceSnapshot, isExpectedFsAccessError } from "./workspace.js";
|
|
2
|
+
import { EventEmitter } from "node:events";
|
|
3
|
+
import * as Effect from "effect/Effect";
|
|
4
|
+
import type * as Fiber from "effect/Fiber";
|
|
5
|
+
import { existsSync, watch as watchDirectory, type FSWatcher } from "node:fs";
|
|
6
|
+
import { dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
7
|
+
import type { Readable, Writable } from "node:stream";
|
|
8
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
9
|
+
import { Worker } from "node:worker_threads";
|
|
10
|
+
import { FunScriptError, toErrorMessage } from "../errors.js";
|
|
11
|
+
|
|
12
|
+
function isExpectedUriError(error: unknown): boolean {
|
|
13
|
+
return error instanceof URIError || error instanceof TypeError;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function isExpectedSyntaxError(error: unknown): boolean {
|
|
17
|
+
return error instanceof FunScriptError || isExpectedUriError(error);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
import {
|
|
21
|
+
createConnection,
|
|
22
|
+
CodeActionKind,
|
|
23
|
+
ErrorCodes,
|
|
24
|
+
StreamMessageReader,
|
|
25
|
+
StreamMessageWriter,
|
|
26
|
+
TextDocumentSyncKind,
|
|
27
|
+
type CodeAction,
|
|
28
|
+
type CodeActionParams,
|
|
29
|
+
type CompletionItem,
|
|
30
|
+
type CompletionParams,
|
|
31
|
+
type Connection,
|
|
32
|
+
type DefinitionParams,
|
|
33
|
+
type Diagnostic,
|
|
34
|
+
type DidChangeTextDocumentParams,
|
|
35
|
+
type DidCloseTextDocumentParams,
|
|
36
|
+
type DidOpenTextDocumentParams,
|
|
37
|
+
type DocumentFormattingParams,
|
|
38
|
+
type DocumentRangeFormattingParams,
|
|
39
|
+
type DocumentSymbol,
|
|
40
|
+
type DocumentSymbolParams,
|
|
41
|
+
type Hover,
|
|
42
|
+
type HoverParams,
|
|
43
|
+
type InitializeParams,
|
|
44
|
+
type InitializeResult,
|
|
45
|
+
type InlayHint,
|
|
46
|
+
type InlayHintParams,
|
|
47
|
+
type Location,
|
|
48
|
+
type LocationLink,
|
|
49
|
+
type Message,
|
|
50
|
+
type NotificationMessage,
|
|
51
|
+
type PrepareRenameParams,
|
|
52
|
+
type PrepareRenameResult,
|
|
53
|
+
type PublishDiagnosticsParams,
|
|
54
|
+
type ReferenceParams,
|
|
55
|
+
type RenameParams,
|
|
56
|
+
type RequestMessage,
|
|
57
|
+
type ResponseMessage,
|
|
58
|
+
type SymbolInformation,
|
|
59
|
+
type TextDocumentItem,
|
|
60
|
+
type TextEdit,
|
|
61
|
+
type WorkspaceEdit,
|
|
62
|
+
type WorkspaceSymbolParams,
|
|
63
|
+
} from "vscode-languageserver/node";
|
|
64
|
+
import {
|
|
65
|
+
loadFormatConfigForFile,
|
|
66
|
+
loadProjectConfigForFile,
|
|
67
|
+
} from "../compiler/project-config.js";
|
|
68
|
+
import { format } from "../formatter/index.js";
|
|
69
|
+
import { convertPipelineStyle } from "../tooling/pipeline-style.js";
|
|
70
|
+
import { FUNSCRIPT_VERSION } from "../version.js";
|
|
71
|
+
import { complete } from "./completion.js";
|
|
72
|
+
import { findHoverAsync } from "./hover.js";
|
|
73
|
+
import {
|
|
74
|
+
findAutoImportCodeActions,
|
|
75
|
+
findRemoveUnusedImportsCodeActions,
|
|
76
|
+
} from "./imports.js";
|
|
77
|
+
import { findInlayHints } from "./inlay-hints.js";
|
|
78
|
+
import { InteropRenameSession, renameInterop } from "./interop-rename.js";
|
|
79
|
+
import { findFillMatchArmsCodeActions } from "./match-arms.js";
|
|
80
|
+
import { findThunkPipelineCodeActions } from "./thunk-pipeline.js";
|
|
81
|
+
import { findErrorChannelCodeActions } from "./error-channel.js";
|
|
82
|
+
import {
|
|
83
|
+
documentSymbols,
|
|
84
|
+
findWorkspaceDefinition,
|
|
85
|
+
prepareRename,
|
|
86
|
+
references,
|
|
87
|
+
rename,
|
|
88
|
+
workspaceSymbols,
|
|
89
|
+
} from "./navigation.js";
|
|
90
|
+
import { ParsedDocumentCache } from "./parsed-documents.js";
|
|
91
|
+
import { validateFunScript, validateSyntax } from "./validation.js";
|
|
92
|
+
export { toDiagnostic, validateFunScript } from "./validation.js";
|
|
93
|
+
|
|
94
|
+
type InteropDocumentNotification =
|
|
95
|
+
| { kind: "upsert"; textDocument: TextDocumentItem }
|
|
96
|
+
| { kind: "close"; uri: string };
|
|
97
|
+
|
|
98
|
+
class NormalizingMessageReader extends StreamMessageReader {
|
|
99
|
+
public override listen(
|
|
100
|
+
callback: Parameters<StreamMessageReader["listen"]>[0],
|
|
101
|
+
) {
|
|
102
|
+
return super.listen((msg) => {
|
|
103
|
+
const record = msg as unknown as {
|
|
104
|
+
method?: unknown;
|
|
105
|
+
params?: { capabilities?: Record<string, unknown> };
|
|
106
|
+
};
|
|
107
|
+
if (record && record.method === "initialize") {
|
|
108
|
+
if (!record.params) record.params = {};
|
|
109
|
+
if (!record.params.capabilities) record.params.capabilities = {};
|
|
110
|
+
}
|
|
111
|
+
callback(msg);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export class FunScriptLspServer extends EventEmitter {
|
|
117
|
+
private documents: Map<string, TextDocumentItem> = new Map();
|
|
118
|
+
private interopDocuments: Map<string, TextDocumentItem> = new Map();
|
|
119
|
+
private isInitialized = false;
|
|
120
|
+
private isShutdown = false;
|
|
121
|
+
private clientCapabilities: InitializeParams["capabilities"] | undefined =
|
|
122
|
+
undefined;
|
|
123
|
+
private workspaceRoots: string[] = [];
|
|
124
|
+
private readonly projectConfigWatchers = new Map<string, FSWatcher>();
|
|
125
|
+
private readonly interopRenameSession = new InteropRenameSession();
|
|
126
|
+
private readonly parsedDocuments = new ParsedDocumentCache();
|
|
127
|
+
private readonly pipelineCompletionInputs = new Map<
|
|
128
|
+
string,
|
|
129
|
+
{ source: string; version: number; inputs: Array<[number, string]> }
|
|
130
|
+
>();
|
|
131
|
+
private codeActionWorker?: Worker;
|
|
132
|
+
private codeActionWorkerId = 0;
|
|
133
|
+
private readonly pendingCodeActions = new Map<
|
|
134
|
+
number,
|
|
135
|
+
{
|
|
136
|
+
version: number;
|
|
137
|
+
text: string;
|
|
138
|
+
uri: string;
|
|
139
|
+
resolve: (result: CodeAction[]) => void;
|
|
140
|
+
}
|
|
141
|
+
>();
|
|
142
|
+
private renameWorker?: Worker;
|
|
143
|
+
private renameWorkerId = 0;
|
|
144
|
+
private documentRevision = 0;
|
|
145
|
+
private readonly pendingRenames = new Map<
|
|
146
|
+
number,
|
|
147
|
+
{
|
|
148
|
+
revision: number;
|
|
149
|
+
resolve: (
|
|
150
|
+
result: ReturnType<typeof prepareRename> | ReturnType<typeof rename>,
|
|
151
|
+
) => void;
|
|
152
|
+
}
|
|
153
|
+
>();
|
|
154
|
+
private connection: Connection | null = null;
|
|
155
|
+
private diagnosticDebounceFiber: Fiber.Fiber<void, never> | undefined;
|
|
156
|
+
private diagnosticRevision = 0;
|
|
157
|
+
private diagnosticWorker?: Worker;
|
|
158
|
+
private diagnosticBusy = false;
|
|
159
|
+
private queuedDiagnostics?: {
|
|
160
|
+
revision: number;
|
|
161
|
+
documents: TextDocumentItem[];
|
|
162
|
+
};
|
|
163
|
+
private readonly syntaxErrors = new Set<string>();
|
|
164
|
+
|
|
165
|
+
constructor() {
|
|
166
|
+
super();
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public listen(readerStream?: Readable, writerStream?: Writable): Connection {
|
|
170
|
+
const reader = readerStream
|
|
171
|
+
? new NormalizingMessageReader(readerStream)
|
|
172
|
+
: undefined;
|
|
173
|
+
const writer = writerStream
|
|
174
|
+
? new StreamMessageWriter(writerStream)
|
|
175
|
+
: undefined;
|
|
176
|
+
|
|
177
|
+
const connection =
|
|
178
|
+
reader && writer
|
|
179
|
+
? createConnection(reader, writer)
|
|
180
|
+
: createConnection(process.stdin, process.stdout);
|
|
181
|
+
|
|
182
|
+
this.connection = connection;
|
|
183
|
+
this.setupConnection(connection);
|
|
184
|
+
connection.listen();
|
|
185
|
+
return connection;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
private setupConnection(connection: Connection): void {
|
|
189
|
+
connection.onInitialize((params) => this.onInitializeHandler(params));
|
|
190
|
+
connection.onInitialized(() => {
|
|
191
|
+
this.emit("initialized");
|
|
192
|
+
});
|
|
193
|
+
connection.onShutdown(() => {
|
|
194
|
+
this.onShutdownHandler();
|
|
195
|
+
});
|
|
196
|
+
connection.onExit(() => {
|
|
197
|
+
this.onExitHandler();
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
connection.onDidOpenTextDocument((params) => {
|
|
201
|
+
this.onDidOpenHandler(params);
|
|
202
|
+
});
|
|
203
|
+
connection.onDidChangeTextDocument((params) => {
|
|
204
|
+
this.onDidChangeHandler(params);
|
|
205
|
+
});
|
|
206
|
+
connection.onDidCloseTextDocument((params) => {
|
|
207
|
+
this.onDidCloseHandler(params);
|
|
208
|
+
});
|
|
209
|
+
connection.onNotification("funscript/interopDocument", (params) =>
|
|
210
|
+
this.onInteropDocument(params as InteropDocumentNotification),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
connection.onCodeAction((params) => this.codeActionInWorker(params));
|
|
214
|
+
connection.onDocumentFormatting((params) =>
|
|
215
|
+
this.onFormattingHandler(params),
|
|
216
|
+
);
|
|
217
|
+
connection.onDocumentRangeFormatting((params) =>
|
|
218
|
+
this.onRangeFormattingHandler(params),
|
|
219
|
+
);
|
|
220
|
+
connection.onDefinition((params) => this.onDefinitionHandler(params));
|
|
221
|
+
connection.onHover((params) => this.onHoverHandler(params));
|
|
222
|
+
connection.onCompletion((params) => this.onCompletionHandler(params));
|
|
223
|
+
connection.onDocumentSymbol((params) =>
|
|
224
|
+
this.onDocumentSymbolHandler(params),
|
|
225
|
+
);
|
|
226
|
+
connection.onWorkspaceSymbol((params) =>
|
|
227
|
+
this.onWorkspaceSymbolHandler(params),
|
|
228
|
+
);
|
|
229
|
+
connection.onReferences((params) => this.onReferencesHandler(params));
|
|
230
|
+
connection.onPrepareRename((params) =>
|
|
231
|
+
this.renameInWorker("prepare", params),
|
|
232
|
+
);
|
|
233
|
+
connection.onRenameRequest((params) =>
|
|
234
|
+
this.renameInWorker("rename", params),
|
|
235
|
+
);
|
|
236
|
+
connection.onRequest("textDocument/inlayHint", (params) =>
|
|
237
|
+
this.onInlayHintHandler(params as InlayHintParams),
|
|
238
|
+
);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
public onInitializeHandler(params: InitializeParams): InitializeResult {
|
|
242
|
+
this.isInitialized = true;
|
|
243
|
+
this.clientCapabilities = params?.capabilities;
|
|
244
|
+
this.stopRenameWorker();
|
|
245
|
+
this.stopCodeActionWorker();
|
|
246
|
+
this.stopDiagnosticWorker();
|
|
247
|
+
this.documentRevision++;
|
|
248
|
+
this.interopDocuments.clear();
|
|
249
|
+
this.interopRenameSession.dispose();
|
|
250
|
+
this.parsedDocuments.clear();
|
|
251
|
+
this.pipelineCompletionInputs.clear();
|
|
252
|
+
const roots =
|
|
253
|
+
params?.workspaceFolders?.map((folder) => folder.uri) ??
|
|
254
|
+
(params?.rootUri ? [params.rootUri] : []);
|
|
255
|
+
this.workspaceRoots = roots.flatMap((uri) => {
|
|
256
|
+
if (!uri.startsWith("file:")) return [];
|
|
257
|
+
try {
|
|
258
|
+
return [resolve(fileURLToPath(uri))];
|
|
259
|
+
} catch (error) {
|
|
260
|
+
if (!isExpectedUriError(error)) throw error;
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
this.syncProjectConfigWatchers();
|
|
265
|
+
return {
|
|
266
|
+
capabilities: {
|
|
267
|
+
textDocumentSync: TextDocumentSyncKind.Full,
|
|
268
|
+
documentFormattingProvider: true,
|
|
269
|
+
documentRangeFormattingProvider: true,
|
|
270
|
+
definitionProvider: true,
|
|
271
|
+
documentSymbolProvider: true,
|
|
272
|
+
workspaceSymbolProvider: true,
|
|
273
|
+
referencesProvider: true,
|
|
274
|
+
renameProvider: { prepareProvider: true },
|
|
275
|
+
hoverProvider: true,
|
|
276
|
+
completionProvider: {
|
|
277
|
+
resolveProvider: false,
|
|
278
|
+
triggerCharacters: [".", "<", ">"],
|
|
279
|
+
},
|
|
280
|
+
codeActionProvider: true,
|
|
281
|
+
inlayHintProvider: { resolveProvider: false },
|
|
282
|
+
},
|
|
283
|
+
serverInfo: {
|
|
284
|
+
name: "funscript-lsp",
|
|
285
|
+
version: FUNSCRIPT_VERSION,
|
|
286
|
+
},
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public onShutdownHandler(): null {
|
|
291
|
+
this.isShutdown = true;
|
|
292
|
+
this.stopRenameWorker();
|
|
293
|
+
this.stopCodeActionWorker();
|
|
294
|
+
this.stopDiagnosticWorker();
|
|
295
|
+
this.stopProjectConfigWatchers();
|
|
296
|
+
return null;
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
public onExitHandler(): void {
|
|
300
|
+
const exitCode = this.isShutdown ? 0 : 1;
|
|
301
|
+
this.emit("exit", exitCode);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
public onDidOpenHandler(params: DidOpenTextDocumentParams): void {
|
|
305
|
+
if (params?.textDocument) {
|
|
306
|
+
this.documentRevision++;
|
|
307
|
+
this.cancelCodeActionsFor(params.textDocument.uri);
|
|
308
|
+
this.documents.set(params.textDocument.uri, params.textDocument);
|
|
309
|
+
this.syncProjectConfigWatchers();
|
|
310
|
+
const diagnostics = validateSyntax(
|
|
311
|
+
params.textDocument.text,
|
|
312
|
+
params.textDocument.uri,
|
|
313
|
+
).diagnostics;
|
|
314
|
+
if (diagnostics.length) this.syntaxErrors.add(params.textDocument.uri);
|
|
315
|
+
else this.syntaxErrors.delete(params.textDocument.uri);
|
|
316
|
+
this.publishDiagnostics(
|
|
317
|
+
params.textDocument.uri,
|
|
318
|
+
params.textDocument.version,
|
|
319
|
+
diagnostics,
|
|
320
|
+
);
|
|
321
|
+
this.scheduleTypeDiagnostics();
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
public onDidChangeHandler(params: DidChangeTextDocumentParams): void {
|
|
326
|
+
if (params?.textDocument && Array.isArray(params.contentChanges)) {
|
|
327
|
+
this.documentRevision++;
|
|
328
|
+
this.cancelCodeActionsFor(params.textDocument.uri);
|
|
329
|
+
const doc = this.documents.get(params.textDocument.uri);
|
|
330
|
+
const lastChange =
|
|
331
|
+
params.contentChanges[params.contentChanges.length - 1];
|
|
332
|
+
const newText = lastChange ? lastChange.text : (doc?.text ?? "");
|
|
333
|
+
const updatedVersion =
|
|
334
|
+
params.textDocument.version ?? (doc ? doc.version + 1 : 1);
|
|
335
|
+
const updatedDoc: TextDocumentItem = {
|
|
336
|
+
uri: params.textDocument.uri,
|
|
337
|
+
languageId: doc?.languageId ?? "funscript",
|
|
338
|
+
version: updatedVersion,
|
|
339
|
+
text: newText,
|
|
340
|
+
};
|
|
341
|
+
this.documents.set(params.textDocument.uri, updatedDoc);
|
|
342
|
+
this.syncProjectConfigWatchers();
|
|
343
|
+
const diagnostics = validateSyntax(
|
|
344
|
+
newText,
|
|
345
|
+
params.textDocument.uri,
|
|
346
|
+
).diagnostics;
|
|
347
|
+
if (diagnostics.length) this.syntaxErrors.add(updatedDoc.uri);
|
|
348
|
+
else this.syntaxErrors.delete(updatedDoc.uri);
|
|
349
|
+
this.publishDiagnostics(
|
|
350
|
+
params.textDocument.uri,
|
|
351
|
+
updatedVersion,
|
|
352
|
+
diagnostics,
|
|
353
|
+
);
|
|
354
|
+
this.scheduleTypeDiagnostics();
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
public onDidCloseHandler(params: DidCloseTextDocumentParams): void {
|
|
359
|
+
if (params?.textDocument) {
|
|
360
|
+
this.documentRevision++;
|
|
361
|
+
this.cancelCodeActionsFor(params.textDocument.uri);
|
|
362
|
+
this.documents.delete(params.textDocument.uri);
|
|
363
|
+
this.pipelineCompletionInputs.delete(params.textDocument.uri);
|
|
364
|
+
this.syncProjectConfigWatchers();
|
|
365
|
+
this.syntaxErrors.delete(params.textDocument.uri);
|
|
366
|
+
this.scheduleTypeDiagnostics();
|
|
367
|
+
this.publishDiagnostics(params.textDocument.uri, undefined, []);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
public onFormattingHandler(
|
|
372
|
+
params: DocumentFormattingParams,
|
|
373
|
+
): TextEdit[] | null {
|
|
374
|
+
const uri = params?.textDocument?.uri;
|
|
375
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
376
|
+
if (!doc) {
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (doc.text.trim().length === 0) {
|
|
381
|
+
return [];
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
try {
|
|
385
|
+
const indentSize =
|
|
386
|
+
typeof params?.options?.tabSize === "number" &&
|
|
387
|
+
params.options.tabSize > 0
|
|
388
|
+
? params.options.tabSize
|
|
389
|
+
: undefined;
|
|
390
|
+
const filename = uri ? new URL(uri).pathname : undefined;
|
|
391
|
+
const projectFormat = filename
|
|
392
|
+
? loadFormatConfigForFile(filename)
|
|
393
|
+
: undefined;
|
|
394
|
+
const formatted = format(doc.text, {
|
|
395
|
+
...(indentSize !== undefined ? { indentSize } : {}),
|
|
396
|
+
...projectFormat,
|
|
397
|
+
...(filename ? { filename } : {}),
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
const lines = doc.text.split("\n");
|
|
401
|
+
const lastLine = Math.max(0, lines.length - 1);
|
|
402
|
+
const lastChar = lines[lastLine].length;
|
|
403
|
+
|
|
404
|
+
const edit: TextEdit = {
|
|
405
|
+
range: {
|
|
406
|
+
start: { line: 0, character: 0 },
|
|
407
|
+
end: { line: lastLine, character: lastChar },
|
|
408
|
+
},
|
|
409
|
+
newText: formatted,
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
return [edit];
|
|
413
|
+
} catch (error) {
|
|
414
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
415
|
+
return null;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
private codeActionInWorker(params: CodeActionParams): Promise<CodeAction[]> {
|
|
420
|
+
const doc = this.documents.get(params.textDocument.uri);
|
|
421
|
+
if (!doc) return Promise.resolve([]);
|
|
422
|
+
if (!this.codeActionWorker) {
|
|
423
|
+
try {
|
|
424
|
+
const worker = new Worker(
|
|
425
|
+
new URL("./code-action-worker.js", import.meta.url),
|
|
426
|
+
{ execArgv: [] },
|
|
427
|
+
);
|
|
428
|
+
worker.unref();
|
|
429
|
+
this.codeActionWorker = worker;
|
|
430
|
+
worker.on(
|
|
431
|
+
"message",
|
|
432
|
+
(message: { id: number; result: CodeAction[] }) => {
|
|
433
|
+
const pending = this.pendingCodeActions.get(message.id);
|
|
434
|
+
if (!pending) return;
|
|
435
|
+
this.pendingCodeActions.delete(message.id);
|
|
436
|
+
const current = this.documents.get(pending.uri);
|
|
437
|
+
pending.resolve(
|
|
438
|
+
current?.version === pending.version &&
|
|
439
|
+
current.text === pending.text
|
|
440
|
+
? message.result
|
|
441
|
+
: [],
|
|
442
|
+
);
|
|
443
|
+
},
|
|
444
|
+
);
|
|
445
|
+
const failed = () => {
|
|
446
|
+
if (this.codeActionWorker !== worker) return;
|
|
447
|
+
this.codeActionWorker = undefined;
|
|
448
|
+
for (const pending of this.pendingCodeActions.values())
|
|
449
|
+
pending.resolve([]);
|
|
450
|
+
this.pendingCodeActions.clear();
|
|
451
|
+
};
|
|
452
|
+
worker.on("error", failed);
|
|
453
|
+
worker.on("exit", failed);
|
|
454
|
+
} catch (error) {
|
|
455
|
+
this.connection?.console.warn(
|
|
456
|
+
`Failed to start codeActionWorker: ${toErrorMessage(error)}`,
|
|
457
|
+
);
|
|
458
|
+
return Promise.resolve([]);
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
const id = ++this.codeActionWorkerId;
|
|
462
|
+
return new Promise((resolve) => {
|
|
463
|
+
this.pendingCodeActions.set(id, {
|
|
464
|
+
version: doc.version,
|
|
465
|
+
text: doc.text,
|
|
466
|
+
uri: doc.uri,
|
|
467
|
+
resolve,
|
|
468
|
+
});
|
|
469
|
+
try {
|
|
470
|
+
this.codeActionWorker!.postMessage({ id, doc, params });
|
|
471
|
+
} catch (error) {
|
|
472
|
+
this.connection?.console.warn(
|
|
473
|
+
`Failed to post to codeActionWorker: ${toErrorMessage(error)}`,
|
|
474
|
+
);
|
|
475
|
+
this.pendingCodeActions.delete(id);
|
|
476
|
+
resolve([]);
|
|
477
|
+
}
|
|
478
|
+
});
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
private cancelCodeActionsFor(uri: string): void {
|
|
482
|
+
for (const [id, pending] of this.pendingCodeActions.entries()) {
|
|
483
|
+
if (pending.uri === uri) {
|
|
484
|
+
this.pendingCodeActions.delete(id);
|
|
485
|
+
pending.resolve([]);
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
private stopCodeActionWorker(): void {
|
|
491
|
+
const worker = this.codeActionWorker;
|
|
492
|
+
this.codeActionWorker = undefined;
|
|
493
|
+
for (const pending of this.pendingCodeActions.values()) pending.resolve([]);
|
|
494
|
+
this.pendingCodeActions.clear();
|
|
495
|
+
if (worker) void worker.terminate();
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
public onCodeActionHandler(params: CodeActionParams): CodeAction[] {
|
|
499
|
+
const uri = params?.textDocument?.uri;
|
|
500
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
501
|
+
if (!doc || !doc.text.trim()) return [];
|
|
502
|
+
const actions: CodeAction[] = [];
|
|
503
|
+
const lines = doc.text.split("\n");
|
|
504
|
+
const wholeRange = {
|
|
505
|
+
start: { line: 0, character: 0 },
|
|
506
|
+
end: { line: lines.length - 1, character: lines.at(-1)!.length },
|
|
507
|
+
};
|
|
508
|
+
const offset = (position: { line: number; character: number }) =>
|
|
509
|
+
lines
|
|
510
|
+
.slice(0, position.line)
|
|
511
|
+
.reduce((n, line) => n + line.length + 1, 0) + position.character;
|
|
512
|
+
try {
|
|
513
|
+
const filename = uri ? fileURLToPath(uri) : undefined;
|
|
514
|
+
const formatted = format(doc.text, {
|
|
515
|
+
...(filename ? loadFormatConfigForFile(filename) : {}),
|
|
516
|
+
filename,
|
|
517
|
+
});
|
|
518
|
+
if (formatted !== doc.text)
|
|
519
|
+
actions.push({
|
|
520
|
+
title: "Format document",
|
|
521
|
+
kind: "source",
|
|
522
|
+
edit: {
|
|
523
|
+
changes: { [uri]: [{ range: wholeRange, newText: formatted }] },
|
|
524
|
+
},
|
|
525
|
+
});
|
|
526
|
+
} catch (error) {
|
|
527
|
+
/* Invalid source has no formatting action. */
|
|
528
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
try {
|
|
532
|
+
const matchActions = findFillMatchArmsCodeActions(
|
|
533
|
+
doc.text,
|
|
534
|
+
uri,
|
|
535
|
+
params.range,
|
|
536
|
+
);
|
|
537
|
+
actions.push(...matchActions);
|
|
538
|
+
} catch (error) {
|
|
539
|
+
/* Code actions gracefully decline on invalid syntax. */
|
|
540
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
try {
|
|
544
|
+
const autoImportActions = findAutoImportCodeActions(
|
|
545
|
+
doc.text,
|
|
546
|
+
uri,
|
|
547
|
+
params.range,
|
|
548
|
+
);
|
|
549
|
+
actions.push(...autoImportActions);
|
|
550
|
+
} catch (error) {
|
|
551
|
+
/* Auto import gracefully declines. */
|
|
552
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
try {
|
|
556
|
+
const unusedImportActions = findRemoveUnusedImportsCodeActions(
|
|
557
|
+
doc.text,
|
|
558
|
+
uri,
|
|
559
|
+
params.range,
|
|
560
|
+
);
|
|
561
|
+
actions.push(...unusedImportActions);
|
|
562
|
+
} catch (error) {
|
|
563
|
+
/* Remove unused imports gracefully declines. */
|
|
564
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
actions.push(...findThunkPipelineCodeActions(doc.text, uri, params.range));
|
|
568
|
+
|
|
569
|
+
try {
|
|
570
|
+
const errorChannelActions = findErrorChannelCodeActions(
|
|
571
|
+
doc.text,
|
|
572
|
+
uri,
|
|
573
|
+
params.range,
|
|
574
|
+
params.context?.diagnostics,
|
|
575
|
+
);
|
|
576
|
+
actions.push(...errorChannelActions);
|
|
577
|
+
} catch (error) {
|
|
578
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
if (!doc.text.includes("|>")) return actions;
|
|
582
|
+
const filename = uri.startsWith("file:") ? fileURLToPath(uri) : uri;
|
|
583
|
+
const redundantDiag = params.context?.diagnostics?.find((d) =>
|
|
584
|
+
typeof d.message === "string"
|
|
585
|
+
? d.message.includes("Redundant pipeline prefix")
|
|
586
|
+
: d.message?.value?.includes("Redundant pipeline prefix"),
|
|
587
|
+
);
|
|
588
|
+
if (redundantDiag) {
|
|
589
|
+
try {
|
|
590
|
+
const result = convertPipelineStyle(doc.text, filename, "bare", {
|
|
591
|
+
start: offset(params.range.start),
|
|
592
|
+
end: offset(params.range.end),
|
|
593
|
+
});
|
|
594
|
+
if (result.changed) {
|
|
595
|
+
actions.push({
|
|
596
|
+
title: "Remove redundant pipeline prefix",
|
|
597
|
+
kind: CodeActionKind.QuickFix,
|
|
598
|
+
diagnostics: [redundantDiag],
|
|
599
|
+
isPreferred: true,
|
|
600
|
+
edit: {
|
|
601
|
+
changes: { [uri]: [{ range: wholeRange, newText: result.text }] },
|
|
602
|
+
},
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
} catch (error) {
|
|
606
|
+
/* Incomplete or ambiguous source cannot safely be rewritten. */
|
|
607
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
608
|
+
}
|
|
609
|
+
}
|
|
610
|
+
for (const style of ["bare", "qualified"] as const) {
|
|
611
|
+
try {
|
|
612
|
+
const result = convertPipelineStyle(doc.text, filename, style, {
|
|
613
|
+
start: offset(params.range.start),
|
|
614
|
+
end: offset(params.range.end),
|
|
615
|
+
});
|
|
616
|
+
if (result.changed)
|
|
617
|
+
actions.push({
|
|
618
|
+
title:
|
|
619
|
+
style === "bare"
|
|
620
|
+
? "Use bare pipeline stages"
|
|
621
|
+
: "Qualify pipeline stages",
|
|
622
|
+
kind: "refactor.rewrite",
|
|
623
|
+
edit: {
|
|
624
|
+
changes: { [uri]: [{ range: wholeRange, newText: result.text }] },
|
|
625
|
+
},
|
|
626
|
+
});
|
|
627
|
+
} catch (error) {
|
|
628
|
+
/* Incomplete or ambiguous source cannot safely be rewritten. */
|
|
629
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
return actions;
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
public onRangeFormattingHandler(
|
|
636
|
+
params: DocumentRangeFormattingParams,
|
|
637
|
+
): TextEdit[] | null {
|
|
638
|
+
const uri = params?.textDocument?.uri;
|
|
639
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
640
|
+
if (!doc) return null;
|
|
641
|
+
|
|
642
|
+
// The formatter currently operates on complete syntax trees. Only accept a
|
|
643
|
+
// range that covers the full document; partial edits could alter unrelated code.
|
|
644
|
+
const lines = doc.text.split("\n");
|
|
645
|
+
const lastLine = lines.length - 1;
|
|
646
|
+
const end = params.range?.end;
|
|
647
|
+
const start = params.range?.start;
|
|
648
|
+
if (
|
|
649
|
+
!start ||
|
|
650
|
+
!end ||
|
|
651
|
+
start.line !== 0 ||
|
|
652
|
+
start.character !== 0 ||
|
|
653
|
+
end.line < lastLine ||
|
|
654
|
+
(end.line === lastLine && end.character < lines[lastLine].length)
|
|
655
|
+
) {
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
return this.onFormattingHandler({
|
|
659
|
+
textDocument: params.textDocument,
|
|
660
|
+
options: params.options,
|
|
661
|
+
});
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
public onDefinitionHandler(
|
|
665
|
+
params: DefinitionParams,
|
|
666
|
+
): Location | Location[] | LocationLink[] | null {
|
|
667
|
+
const uri = params?.textDocument?.uri;
|
|
668
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
669
|
+
if (!doc || !params?.position) {
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
|
|
673
|
+
const clientSupportsLink = Boolean(
|
|
674
|
+
this.clientCapabilities?.textDocument?.definition?.linkSupport,
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
return findWorkspaceDefinition(
|
|
678
|
+
doc.text,
|
|
679
|
+
uri,
|
|
680
|
+
params.position,
|
|
681
|
+
this.workspaceSnapshot()?.fun ?? this.getDocuments(),
|
|
682
|
+
clientSupportsLink,
|
|
683
|
+
);
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
public async onHoverHandler(params: HoverParams): Promise<Hover | null> {
|
|
687
|
+
const uri = params?.textDocument?.uri;
|
|
688
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
689
|
+
if (!doc || !params?.position) {
|
|
690
|
+
return null;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return findHoverAsync(doc.text, uri, params.position);
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
public onInlayHintHandler(params: InlayHintParams): InlayHint[] {
|
|
697
|
+
const uri = params?.textDocument?.uri;
|
|
698
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
699
|
+
if (!doc) return [];
|
|
700
|
+
return findInlayHints(doc.text, uri, params?.range);
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
public onCompletionHandler(params: CompletionParams): CompletionItem[] {
|
|
704
|
+
const uri = params?.textDocument?.uri;
|
|
705
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
706
|
+
if (!doc || !params?.position) return [];
|
|
707
|
+
return complete(
|
|
708
|
+
doc.text,
|
|
709
|
+
uri,
|
|
710
|
+
params.position,
|
|
711
|
+
this.getDocuments(),
|
|
712
|
+
this.pipelineCompletionInputs.get(uri),
|
|
713
|
+
);
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
public onDocumentSymbolHandler(
|
|
717
|
+
params: DocumentSymbolParams,
|
|
718
|
+
): DocumentSymbol[] {
|
|
719
|
+
const uri = params?.textDocument?.uri;
|
|
720
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
721
|
+
return doc ? documentSymbols(doc.text, uri) : [];
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
public onWorkspaceSymbolHandler(
|
|
725
|
+
params: WorkspaceSymbolParams,
|
|
726
|
+
): SymbolInformation[] {
|
|
727
|
+
return workspaceSymbols(this.getDocuments(), params?.query ?? "");
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
public onReferencesHandler(params: ReferenceParams): Location[] {
|
|
731
|
+
const uri = params?.textDocument?.uri;
|
|
732
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
733
|
+
return doc
|
|
734
|
+
? references(
|
|
735
|
+
doc.text,
|
|
736
|
+
uri,
|
|
737
|
+
params.position,
|
|
738
|
+
this.workspaceSnapshot()?.fun ?? this.getDocuments(),
|
|
739
|
+
params.context.includeDeclaration,
|
|
740
|
+
)
|
|
741
|
+
: [];
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
public onPrepareRenameHandler(
|
|
745
|
+
params: PrepareRenameParams,
|
|
746
|
+
): PrepareRenameResult | null {
|
|
747
|
+
const uri = params?.textDocument?.uri;
|
|
748
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
749
|
+
const snapshot = this.workspaceSnapshot();
|
|
750
|
+
if (this.isInitialized && (!this.workspaceRoots.length || !snapshot))
|
|
751
|
+
return null;
|
|
752
|
+
if (!doc) return null;
|
|
753
|
+
const selected = prepareRename(
|
|
754
|
+
doc.text,
|
|
755
|
+
uri,
|
|
756
|
+
params.position,
|
|
757
|
+
snapshot?.fun ?? this.getDocuments(),
|
|
758
|
+
this.parsedDocuments,
|
|
759
|
+
);
|
|
760
|
+
if (!selected || !("placeholder" in selected)) return null;
|
|
761
|
+
return this.onRenameHandler({
|
|
762
|
+
textDocument: params.textDocument,
|
|
763
|
+
position: params.position,
|
|
764
|
+
newName: selected.placeholder,
|
|
765
|
+
})
|
|
766
|
+
? selected
|
|
767
|
+
: null;
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
/** Synchronize an immutable editor snapshot inside the dedicated rename worker. */
|
|
771
|
+
public setRenameWorkerDocuments(docs: TextDocumentItem[]): void {
|
|
772
|
+
this.documents = new Map(docs.map((doc) => [doc.uri, doc]));
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
private onInteropDocument(params: InteropDocumentNotification): void {
|
|
776
|
+
if (
|
|
777
|
+
params?.kind === "upsert" &&
|
|
778
|
+
params.textDocument &&
|
|
779
|
+
/\.[cm]?[jt]sx?$/.test(params.textDocument.uri)
|
|
780
|
+
) {
|
|
781
|
+
const current = this.interopDocuments.get(params.textDocument.uri);
|
|
782
|
+
if (
|
|
783
|
+
current &&
|
|
784
|
+
current.version === params.textDocument.version &&
|
|
785
|
+
current.text === params.textDocument.text &&
|
|
786
|
+
current.languageId === params.textDocument.languageId
|
|
787
|
+
)
|
|
788
|
+
return;
|
|
789
|
+
this.documentRevision++;
|
|
790
|
+
this.interopDocuments.set(params.textDocument.uri, params.textDocument);
|
|
791
|
+
} else if (
|
|
792
|
+
params?.kind === "close" &&
|
|
793
|
+
this.interopDocuments.delete(params.uri)
|
|
794
|
+
) {
|
|
795
|
+
this.documentRevision++;
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
private renameInWorker(
|
|
800
|
+
method: "prepare",
|
|
801
|
+
params: PrepareRenameParams,
|
|
802
|
+
): Promise<ReturnType<typeof prepareRename>>;
|
|
803
|
+
private renameInWorker(
|
|
804
|
+
method: "rename",
|
|
805
|
+
params: RenameParams,
|
|
806
|
+
): Promise<ReturnType<typeof rename>>;
|
|
807
|
+
private renameInWorker(
|
|
808
|
+
method: "prepare" | "rename",
|
|
809
|
+
params: PrepareRenameParams | RenameParams,
|
|
810
|
+
): Promise<ReturnType<typeof prepareRename> | ReturnType<typeof rename>> {
|
|
811
|
+
if (!this.renameWorker) {
|
|
812
|
+
try {
|
|
813
|
+
const worker = new Worker(
|
|
814
|
+
new URL("./rename-worker.js", import.meta.url),
|
|
815
|
+
{ execArgv: [] },
|
|
816
|
+
);
|
|
817
|
+
worker.unref();
|
|
818
|
+
this.renameWorker = worker;
|
|
819
|
+
worker.on("message", (message: { id: number; result: unknown }) => {
|
|
820
|
+
const pending = this.pendingRenames.get(message.id);
|
|
821
|
+
if (!pending) return;
|
|
822
|
+
this.pendingRenames.delete(message.id);
|
|
823
|
+
pending.resolve(
|
|
824
|
+
pending.revision === this.documentRevision
|
|
825
|
+
? (message.result as
|
|
826
|
+
ReturnType<typeof prepareRename> | ReturnType<typeof rename>)
|
|
827
|
+
: null,
|
|
828
|
+
);
|
|
829
|
+
});
|
|
830
|
+
const failed = () => {
|
|
831
|
+
if (this.renameWorker !== worker) return;
|
|
832
|
+
this.renameWorker = undefined;
|
|
833
|
+
for (const pending of this.pendingRenames.values())
|
|
834
|
+
pending.resolve(null);
|
|
835
|
+
this.pendingRenames.clear();
|
|
836
|
+
};
|
|
837
|
+
worker.on("error", failed);
|
|
838
|
+
worker.on("exit", failed);
|
|
839
|
+
} catch (error) {
|
|
840
|
+
this.connection?.console.warn(
|
|
841
|
+
`Failed to start renameWorker: ${toErrorMessage(error)}`,
|
|
842
|
+
);
|
|
843
|
+
return Promise.resolve(null);
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
const id = ++this.renameWorkerId;
|
|
847
|
+
return new Promise((resolve) => {
|
|
848
|
+
this.pendingRenames.set(id, { revision: this.documentRevision, resolve });
|
|
849
|
+
try {
|
|
850
|
+
this.renameWorker!.postMessage({
|
|
851
|
+
id,
|
|
852
|
+
method,
|
|
853
|
+
params,
|
|
854
|
+
roots: this.workspaceRoots.map((root) => pathToFileURL(root).href),
|
|
855
|
+
documents: [
|
|
856
|
+
...this.documents.values(),
|
|
857
|
+
...this.interopDocuments.values(),
|
|
858
|
+
],
|
|
859
|
+
});
|
|
860
|
+
} catch (error) {
|
|
861
|
+
this.connection?.console.warn(
|
|
862
|
+
`Failed to post to renameWorker: ${toErrorMessage(error)}`,
|
|
863
|
+
);
|
|
864
|
+
this.pendingRenames.delete(id);
|
|
865
|
+
resolve(null);
|
|
866
|
+
}
|
|
867
|
+
});
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
private stopRenameWorker(): void {
|
|
871
|
+
const worker = this.renameWorker;
|
|
872
|
+
this.renameWorker = undefined;
|
|
873
|
+
for (const pending of this.pendingRenames.values()) pending.resolve(null);
|
|
874
|
+
this.pendingRenames.clear();
|
|
875
|
+
if (worker) void worker.terminate();
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
public onRenameHandler(params: RenameParams): WorkspaceEdit | null {
|
|
879
|
+
const uri = params?.textDocument?.uri;
|
|
880
|
+
const doc = uri ? this.documents.get(uri) : undefined;
|
|
881
|
+
if (!doc) return null;
|
|
882
|
+
if (this.isInitialized && !this.inWorkspace(uri)) return null;
|
|
883
|
+
const snapshot = this.workspaceSnapshot();
|
|
884
|
+
if (this.isInitialized && (!this.workspaceRoots.length || !snapshot))
|
|
885
|
+
return null;
|
|
886
|
+
const docs = snapshot?.fun ?? this.getDocuments();
|
|
887
|
+
this.parsedDocuments.retain(docs);
|
|
888
|
+
const selected = prepareRename(
|
|
889
|
+
doc.text,
|
|
890
|
+
uri,
|
|
891
|
+
params.position,
|
|
892
|
+
docs,
|
|
893
|
+
this.parsedDocuments,
|
|
894
|
+
);
|
|
895
|
+
if (!selected || !("placeholder" in selected)) return null;
|
|
896
|
+
const name = selected.placeholder;
|
|
897
|
+
const identifier = new RegExp(
|
|
898
|
+
`(^|[^\\w$])${name.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}([^\\w$]|$)`,
|
|
899
|
+
);
|
|
900
|
+
for (const file of docs) {
|
|
901
|
+
if (!identifier.test(file.text)) continue;
|
|
902
|
+
if (!this.parsedDocuments.get(file).ast) return null;
|
|
903
|
+
}
|
|
904
|
+
let edit = rename(
|
|
905
|
+
doc.text,
|
|
906
|
+
uri,
|
|
907
|
+
params.position,
|
|
908
|
+
params.newName,
|
|
909
|
+
docs,
|
|
910
|
+
this.parsedDocuments,
|
|
911
|
+
);
|
|
912
|
+
if (
|
|
913
|
+
this.isInitialized &&
|
|
914
|
+
edit?.changes &&
|
|
915
|
+
Object.keys(edit.changes).some((target) => !this.inWorkspace(target))
|
|
916
|
+
)
|
|
917
|
+
return null;
|
|
918
|
+
if (edit?.changes)
|
|
919
|
+
for (const file of docs) {
|
|
920
|
+
if (!edit.changes[file.uri]) continue;
|
|
921
|
+
const ast = this.parsedDocuments.get(file).ast;
|
|
922
|
+
if (!ast) return null;
|
|
923
|
+
for (const item of ast.body) {
|
|
924
|
+
if (
|
|
925
|
+
item.kind !== "ExportDeclaration" ||
|
|
926
|
+
item.declaration.kind !== "SchemaDeclaration"
|
|
927
|
+
)
|
|
928
|
+
continue;
|
|
929
|
+
const id = item.declaration.id;
|
|
930
|
+
if (
|
|
931
|
+
!edit.changes[file.uri].some(
|
|
932
|
+
(change) =>
|
|
933
|
+
change.range.start.line === id.span.start.line - 1 &&
|
|
934
|
+
change.range.start.character === id.span.start.column - 1,
|
|
935
|
+
)
|
|
936
|
+
)
|
|
937
|
+
continue;
|
|
938
|
+
const companion = new RegExp(
|
|
939
|
+
`\\b${id.name}(?:FromUnknown|DecodeChecked|Checked)\\b`,
|
|
940
|
+
);
|
|
941
|
+
if (
|
|
942
|
+
[...docs, ...(snapshot?.interop ?? [])].some((candidate) =>
|
|
943
|
+
companion.test(candidate.text),
|
|
944
|
+
)
|
|
945
|
+
)
|
|
946
|
+
return null;
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
if (edit && snapshot) {
|
|
950
|
+
try {
|
|
951
|
+
edit = renameInterop(
|
|
952
|
+
docs,
|
|
953
|
+
snapshot.interop,
|
|
954
|
+
edit,
|
|
955
|
+
name,
|
|
956
|
+
params.newName,
|
|
957
|
+
this.workspaceRoots,
|
|
958
|
+
this.interopRenameSession,
|
|
959
|
+
this.parsedDocuments,
|
|
960
|
+
);
|
|
961
|
+
} catch (error) {
|
|
962
|
+
if (!isExpectedSyntaxError(error)) throw error;
|
|
963
|
+
return null;
|
|
964
|
+
}
|
|
965
|
+
}
|
|
966
|
+
if (
|
|
967
|
+
this.isInitialized &&
|
|
968
|
+
edit?.changes &&
|
|
969
|
+
Object.keys(edit.changes).some((target) => !this.inWorkspace(target))
|
|
970
|
+
)
|
|
971
|
+
return null;
|
|
972
|
+
return edit;
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
private inWorkspace(uri: string): boolean {
|
|
976
|
+
if (!uri.startsWith("file:")) return false;
|
|
977
|
+
let path: string;
|
|
978
|
+
try {
|
|
979
|
+
path = fileURLToPath(uri);
|
|
980
|
+
} catch (error) {
|
|
981
|
+
if (!isExpectedUriError(error)) throw error;
|
|
982
|
+
return false;
|
|
983
|
+
}
|
|
984
|
+
return this.workspaceRoots.some((root) => {
|
|
985
|
+
const child = relative(root, path);
|
|
986
|
+
return (
|
|
987
|
+
child !== ".." &&
|
|
988
|
+
!child.startsWith(`..${process.platform === "win32" ? "\\" : "/"}`) &&
|
|
989
|
+
!isAbsolute(child)
|
|
990
|
+
);
|
|
991
|
+
});
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
private workspaceSnapshot() {
|
|
995
|
+
return workspaceSnapshot(
|
|
996
|
+
this.workspaceRoots,
|
|
997
|
+
this.documents.values(),
|
|
998
|
+
this.interopDocuments.values(),
|
|
999
|
+
);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
public async handleMessage(msg: Message): Promise<ResponseMessage | void> {
|
|
1003
|
+
if ("id" in msg && msg.id !== undefined && msg.id !== null) {
|
|
1004
|
+
return this.handleRequest(msg as RequestMessage);
|
|
1005
|
+
} else if ("method" in msg) {
|
|
1006
|
+
this.handleNotification(msg as NotificationMessage);
|
|
1007
|
+
return undefined;
|
|
1008
|
+
}
|
|
1009
|
+
return undefined;
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
private async handleRequest(req: RequestMessage): Promise<ResponseMessage> {
|
|
1013
|
+
if (req.method === "initialize") {
|
|
1014
|
+
const result = this.onInitializeHandler(req.params as InitializeParams);
|
|
1015
|
+
return {
|
|
1016
|
+
jsonrpc: "2.0",
|
|
1017
|
+
id: req.id,
|
|
1018
|
+
result,
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
if (!this.isInitialized) {
|
|
1023
|
+
return {
|
|
1024
|
+
jsonrpc: "2.0",
|
|
1025
|
+
id: req.id,
|
|
1026
|
+
error: {
|
|
1027
|
+
code: ErrorCodes.ServerNotInitialized,
|
|
1028
|
+
message: "Server has not been initialized",
|
|
1029
|
+
},
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
if (this.isShutdown) {
|
|
1034
|
+
return {
|
|
1035
|
+
jsonrpc: "2.0",
|
|
1036
|
+
id: req.id,
|
|
1037
|
+
error: {
|
|
1038
|
+
code: ErrorCodes.InvalidRequest,
|
|
1039
|
+
message: "Server is shut down",
|
|
1040
|
+
},
|
|
1041
|
+
};
|
|
1042
|
+
}
|
|
1043
|
+
|
|
1044
|
+
if (req.method === "shutdown") {
|
|
1045
|
+
const result = this.onShutdownHandler();
|
|
1046
|
+
return {
|
|
1047
|
+
jsonrpc: "2.0",
|
|
1048
|
+
id: req.id,
|
|
1049
|
+
result,
|
|
1050
|
+
};
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
if (req.method === "textDocument/formatting") {
|
|
1054
|
+
const result = this.onFormattingHandler(
|
|
1055
|
+
req.params as DocumentFormattingParams,
|
|
1056
|
+
);
|
|
1057
|
+
return {
|
|
1058
|
+
jsonrpc: "2.0",
|
|
1059
|
+
id: req.id,
|
|
1060
|
+
result,
|
|
1061
|
+
};
|
|
1062
|
+
}
|
|
1063
|
+
|
|
1064
|
+
if (req.method === "textDocument/codeAction") {
|
|
1065
|
+
return {
|
|
1066
|
+
jsonrpc: "2.0",
|
|
1067
|
+
id: req.id,
|
|
1068
|
+
result: await this.codeActionInWorker(req.params as CodeActionParams),
|
|
1069
|
+
};
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
if (req.method === "textDocument/definition") {
|
|
1073
|
+
const result = this.onDefinitionHandler(req.params as DefinitionParams);
|
|
1074
|
+
return {
|
|
1075
|
+
jsonrpc: "2.0",
|
|
1076
|
+
id: req.id,
|
|
1077
|
+
result,
|
|
1078
|
+
};
|
|
1079
|
+
}
|
|
1080
|
+
|
|
1081
|
+
if (req.method === "textDocument/hover") {
|
|
1082
|
+
const result = await this.onHoverHandler(req.params as HoverParams);
|
|
1083
|
+
return {
|
|
1084
|
+
jsonrpc: "2.0",
|
|
1085
|
+
id: req.id,
|
|
1086
|
+
result,
|
|
1087
|
+
};
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
if (req.method === "textDocument/inlayHint") {
|
|
1091
|
+
const result = this.onInlayHintHandler(req.params as InlayHintParams);
|
|
1092
|
+
return {
|
|
1093
|
+
jsonrpc: "2.0",
|
|
1094
|
+
id: req.id,
|
|
1095
|
+
result,
|
|
1096
|
+
};
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
if (req.method === "textDocument/completion") {
|
|
1100
|
+
return {
|
|
1101
|
+
jsonrpc: "2.0",
|
|
1102
|
+
id: req.id,
|
|
1103
|
+
result: this.onCompletionHandler(req.params as CompletionParams),
|
|
1104
|
+
};
|
|
1105
|
+
}
|
|
1106
|
+
|
|
1107
|
+
if (req.method === "textDocument/documentSymbol")
|
|
1108
|
+
return {
|
|
1109
|
+
jsonrpc: "2.0",
|
|
1110
|
+
id: req.id,
|
|
1111
|
+
result: this.onDocumentSymbolHandler(
|
|
1112
|
+
req.params as DocumentSymbolParams,
|
|
1113
|
+
),
|
|
1114
|
+
};
|
|
1115
|
+
if (req.method === "workspace/symbol")
|
|
1116
|
+
return {
|
|
1117
|
+
jsonrpc: "2.0",
|
|
1118
|
+
id: req.id,
|
|
1119
|
+
result: this.onWorkspaceSymbolHandler(
|
|
1120
|
+
req.params as WorkspaceSymbolParams,
|
|
1121
|
+
),
|
|
1122
|
+
};
|
|
1123
|
+
if (req.method === "textDocument/references")
|
|
1124
|
+
return {
|
|
1125
|
+
jsonrpc: "2.0",
|
|
1126
|
+
id: req.id,
|
|
1127
|
+
result: this.onReferencesHandler(req.params as ReferenceParams),
|
|
1128
|
+
};
|
|
1129
|
+
if (req.method === "textDocument/prepareRename")
|
|
1130
|
+
return {
|
|
1131
|
+
jsonrpc: "2.0",
|
|
1132
|
+
id: req.id,
|
|
1133
|
+
result: await this.renameInWorker(
|
|
1134
|
+
"prepare",
|
|
1135
|
+
req.params as PrepareRenameParams,
|
|
1136
|
+
),
|
|
1137
|
+
};
|
|
1138
|
+
if (req.method === "textDocument/rename")
|
|
1139
|
+
return {
|
|
1140
|
+
jsonrpc: "2.0",
|
|
1141
|
+
id: req.id,
|
|
1142
|
+
result: await this.renameInWorker("rename", req.params as RenameParams),
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
return {
|
|
1146
|
+
jsonrpc: "2.0",
|
|
1147
|
+
id: req.id,
|
|
1148
|
+
error: {
|
|
1149
|
+
code: ErrorCodes.MethodNotFound,
|
|
1150
|
+
message: `Method not found: ${req.method}`,
|
|
1151
|
+
},
|
|
1152
|
+
};
|
|
1153
|
+
}
|
|
1154
|
+
|
|
1155
|
+
private handleNotification(notif: NotificationMessage): void {
|
|
1156
|
+
if (notif.method === "funscript/interopDocument") {
|
|
1157
|
+
this.onInteropDocument(notif.params as InteropDocumentNotification);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
if (notif.method === "initialized") {
|
|
1161
|
+
this.emit("initialized");
|
|
1162
|
+
return;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
if (notif.method === "exit") {
|
|
1166
|
+
this.onExitHandler();
|
|
1167
|
+
return;
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
if (notif.method === "textDocument/didOpen") {
|
|
1171
|
+
this.onDidOpenHandler(notif.params as DidOpenTextDocumentParams);
|
|
1172
|
+
return;
|
|
1173
|
+
}
|
|
1174
|
+
|
|
1175
|
+
if (notif.method === "textDocument/didChange") {
|
|
1176
|
+
this.onDidChangeHandler(notif.params as DidChangeTextDocumentParams);
|
|
1177
|
+
return;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
if (notif.method === "textDocument/didClose") {
|
|
1181
|
+
this.onDidCloseHandler(notif.params as DidCloseTextDocumentParams);
|
|
1182
|
+
return;
|
|
1183
|
+
}
|
|
1184
|
+
}
|
|
1185
|
+
|
|
1186
|
+
public validateSource(source: string, uri: string): Diagnostic[] {
|
|
1187
|
+
return validateFunScript(source, uri);
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
private resolveWorkerUrl(filename: string): URL {
|
|
1191
|
+
const localUrl = new URL(`./${filename}`, import.meta.url);
|
|
1192
|
+
// Source-level tests and development load the compiled worker from dist.
|
|
1193
|
+
return existsSync(fileURLToPath(localUrl))
|
|
1194
|
+
? localUrl
|
|
1195
|
+
: new URL(`../../dist/lsp/${filename}`, import.meta.url);
|
|
1196
|
+
}
|
|
1197
|
+
|
|
1198
|
+
private scheduleTypeDiagnostics(): void {
|
|
1199
|
+
const revision = ++this.diagnosticRevision;
|
|
1200
|
+
this.diagnosticDebounceFiber?.interruptUnsafe();
|
|
1201
|
+
this.diagnosticDebounceFiber = Effect.runFork(
|
|
1202
|
+
Effect.sleep("250 millis").pipe(
|
|
1203
|
+
Effect.andThen(
|
|
1204
|
+
Effect.sync(() => {
|
|
1205
|
+
this.diagnosticDebounceFiber = undefined;
|
|
1206
|
+
const request = { revision, documents: this.getDocuments() };
|
|
1207
|
+
if (!request.documents.length && !this.diagnosticWorker) return;
|
|
1208
|
+
if (this.diagnosticBusy) this.queuedDiagnostics = request;
|
|
1209
|
+
else this.dispatchDiagnostics(request);
|
|
1210
|
+
}),
|
|
1211
|
+
),
|
|
1212
|
+
),
|
|
1213
|
+
);
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
private dispatchDiagnostics(request: {
|
|
1217
|
+
revision: number;
|
|
1218
|
+
documents: TextDocumentItem[];
|
|
1219
|
+
}): void {
|
|
1220
|
+
if (!this.diagnosticWorker) {
|
|
1221
|
+
try {
|
|
1222
|
+
const worker = new Worker(
|
|
1223
|
+
this.resolveWorkerUrl("diagnostics-worker.js"),
|
|
1224
|
+
{
|
|
1225
|
+
execArgv: [],
|
|
1226
|
+
},
|
|
1227
|
+
);
|
|
1228
|
+
worker.unref();
|
|
1229
|
+
this.diagnosticWorker = worker;
|
|
1230
|
+
worker.on(
|
|
1231
|
+
"message",
|
|
1232
|
+
(response: {
|
|
1233
|
+
revision: number;
|
|
1234
|
+
complete?: boolean;
|
|
1235
|
+
diagnostics?: PublishDiagnosticsParams[];
|
|
1236
|
+
pipelineInputs?: Array<{
|
|
1237
|
+
uri: string;
|
|
1238
|
+
version: number;
|
|
1239
|
+
source: string;
|
|
1240
|
+
inputs: Array<[number, string]>;
|
|
1241
|
+
}>;
|
|
1242
|
+
error?: string;
|
|
1243
|
+
}) => {
|
|
1244
|
+
if (this.diagnosticWorker !== worker) return;
|
|
1245
|
+
if (response.error)
|
|
1246
|
+
console.error("FunkScript type checking failed:", response.error);
|
|
1247
|
+
if (
|
|
1248
|
+
!response.error &&
|
|
1249
|
+
response.revision === this.diagnosticRevision
|
|
1250
|
+
) {
|
|
1251
|
+
for (const result of response.diagnostics ?? [])
|
|
1252
|
+
if (!this.syntaxErrors.has(result.uri))
|
|
1253
|
+
this.publishDiagnostics(
|
|
1254
|
+
result.uri,
|
|
1255
|
+
result.version,
|
|
1256
|
+
result.diagnostics,
|
|
1257
|
+
);
|
|
1258
|
+
for (const result of response.pipelineInputs ?? [])
|
|
1259
|
+
this.pipelineCompletionInputs.set(result.uri, {
|
|
1260
|
+
source: result.source,
|
|
1261
|
+
version: result.version,
|
|
1262
|
+
inputs: result.inputs,
|
|
1263
|
+
});
|
|
1264
|
+
}
|
|
1265
|
+
if (response.complete === false) return;
|
|
1266
|
+
this.diagnosticBusy = false;
|
|
1267
|
+
const queued = this.queuedDiagnostics;
|
|
1268
|
+
this.queuedDiagnostics = undefined;
|
|
1269
|
+
if (queued && queued.revision === this.diagnosticRevision)
|
|
1270
|
+
this.dispatchDiagnostics(queued);
|
|
1271
|
+
},
|
|
1272
|
+
);
|
|
1273
|
+
const failed = (error?: Error) => {
|
|
1274
|
+
if (this.diagnosticWorker !== worker) return;
|
|
1275
|
+
this.diagnosticWorker = undefined;
|
|
1276
|
+
this.diagnosticBusy = false;
|
|
1277
|
+
this.queuedDiagnostics = undefined;
|
|
1278
|
+
if (error)
|
|
1279
|
+
console.error(
|
|
1280
|
+
"FunkScript diagnostic worker failed:",
|
|
1281
|
+
error.message,
|
|
1282
|
+
);
|
|
1283
|
+
};
|
|
1284
|
+
worker.on("error", failed);
|
|
1285
|
+
worker.on("exit", () => failed());
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
console.error("FunkScript diagnostic worker failed:", error);
|
|
1288
|
+
return;
|
|
1289
|
+
}
|
|
1290
|
+
}
|
|
1291
|
+
this.diagnosticBusy = true;
|
|
1292
|
+
try {
|
|
1293
|
+
this.diagnosticWorker.postMessage(request);
|
|
1294
|
+
} catch (error) {
|
|
1295
|
+
this.diagnosticBusy = false;
|
|
1296
|
+
console.error("FunkScript diagnostic worker failed:", error);
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
|
|
1300
|
+
private stopDiagnosticWorker(): void {
|
|
1301
|
+
this.diagnosticDebounceFiber?.interruptUnsafe();
|
|
1302
|
+
this.diagnosticDebounceFiber = undefined;
|
|
1303
|
+
this.diagnosticRevision++;
|
|
1304
|
+
this.diagnosticBusy = false;
|
|
1305
|
+
this.queuedDiagnostics = undefined;
|
|
1306
|
+
const worker = this.diagnosticWorker;
|
|
1307
|
+
this.diagnosticWorker = undefined;
|
|
1308
|
+
if (worker) void worker.terminate();
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
private syncProjectConfigWatchers(): void {
|
|
1312
|
+
const directories = new Set(this.workspaceRoots);
|
|
1313
|
+
for (const document of this.documents.values()) {
|
|
1314
|
+
try {
|
|
1315
|
+
const filename = fileURLToPath(document.uri);
|
|
1316
|
+
const workspaceRoot = this.workspaceRoots
|
|
1317
|
+
.filter((root) => {
|
|
1318
|
+
const rel = relative(root, filename);
|
|
1319
|
+
return (
|
|
1320
|
+
rel === "" ||
|
|
1321
|
+
(rel !== ".." && !rel.startsWith(`..${sep}`) && !isAbsolute(rel))
|
|
1322
|
+
);
|
|
1323
|
+
})
|
|
1324
|
+
.sort((a, b) => b.length - a.length)[0];
|
|
1325
|
+
const cwd = resolve(process.cwd());
|
|
1326
|
+
const cwdRelative = relative(cwd, filename);
|
|
1327
|
+
const watchRoot =
|
|
1328
|
+
workspaceRoot ??
|
|
1329
|
+
(cwdRelative === "" ||
|
|
1330
|
+
(cwdRelative !== ".." &&
|
|
1331
|
+
!cwdRelative.startsWith(`..${sep}`) &&
|
|
1332
|
+
!isAbsolute(cwdRelative))
|
|
1333
|
+
? cwd
|
|
1334
|
+
: dirname(filename));
|
|
1335
|
+
let directory = dirname(filename);
|
|
1336
|
+
for (;;) {
|
|
1337
|
+
directories.add(directory);
|
|
1338
|
+
if (directory === watchRoot || dirname(directory) === directory)
|
|
1339
|
+
break;
|
|
1340
|
+
directory = dirname(directory);
|
|
1341
|
+
}
|
|
1342
|
+
const policyRoot = loadProjectConfigForFile(filename).root;
|
|
1343
|
+
if (existsSync(join(policyRoot, "funscript.config.fun")))
|
|
1344
|
+
directories.add(policyRoot);
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
/* Non-file documents do not have project config files. */
|
|
1347
|
+
if (!isExpectedUriError(error)) throw error;
|
|
1348
|
+
}
|
|
1349
|
+
}
|
|
1350
|
+
|
|
1351
|
+
for (const [directory, watcher] of this.projectConfigWatchers) {
|
|
1352
|
+
if (directories.has(directory)) continue;
|
|
1353
|
+
watcher.close();
|
|
1354
|
+
this.projectConfigWatchers.delete(directory);
|
|
1355
|
+
}
|
|
1356
|
+
for (const directory of directories) {
|
|
1357
|
+
if (this.projectConfigWatchers.has(directory) || !existsSync(directory))
|
|
1358
|
+
continue;
|
|
1359
|
+
try {
|
|
1360
|
+
const watcher = watchDirectory(directory, (_event, filename) => {
|
|
1361
|
+
if (filename?.toString() === "funscript.config.fun")
|
|
1362
|
+
this.scheduleTypeDiagnostics();
|
|
1363
|
+
});
|
|
1364
|
+
watcher.on("error", () => {
|
|
1365
|
+
watcher.close();
|
|
1366
|
+
this.projectConfigWatchers.delete(directory);
|
|
1367
|
+
});
|
|
1368
|
+
this.projectConfigWatchers.set(directory, watcher);
|
|
1369
|
+
} catch (error) {
|
|
1370
|
+
/* Some virtual or restricted workspaces cannot be watched. */
|
|
1371
|
+
if (!isExpectedFsAccessError(error)) {
|
|
1372
|
+
this.connection?.console.warn(
|
|
1373
|
+
`Failed to watch ${directory}: ${toErrorMessage(error)}`,
|
|
1374
|
+
);
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
}
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1380
|
+
private stopProjectConfigWatchers(): void {
|
|
1381
|
+
for (const watcher of this.projectConfigWatchers.values()) watcher.close();
|
|
1382
|
+
this.projectConfigWatchers.clear();
|
|
1383
|
+
}
|
|
1384
|
+
|
|
1385
|
+
public publishDiagnostics(
|
|
1386
|
+
uri: string,
|
|
1387
|
+
version: number | undefined,
|
|
1388
|
+
diagnostics: Diagnostic[],
|
|
1389
|
+
): void {
|
|
1390
|
+
const params: PublishDiagnosticsParams = {
|
|
1391
|
+
uri,
|
|
1392
|
+
...(version !== undefined ? { version } : {}),
|
|
1393
|
+
diagnostics,
|
|
1394
|
+
};
|
|
1395
|
+
|
|
1396
|
+
this.emit("diagnostics", params);
|
|
1397
|
+
|
|
1398
|
+
if (this.connection) {
|
|
1399
|
+
void this.connection.sendDiagnostics(params);
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
public onExit(callback: (code: number) => void): this {
|
|
1404
|
+
this.on("exit", callback);
|
|
1405
|
+
return this;
|
|
1406
|
+
}
|
|
1407
|
+
|
|
1408
|
+
public getDocument(uri: string): TextDocumentItem | undefined {
|
|
1409
|
+
return this.documents.get(uri);
|
|
1410
|
+
}
|
|
1411
|
+
|
|
1412
|
+
public getDocuments(): TextDocumentItem[] {
|
|
1413
|
+
return Array.from(this.documents.values());
|
|
1414
|
+
}
|
|
1415
|
+
|
|
1416
|
+
public getConnection(): Connection | null {
|
|
1417
|
+
return this.connection;
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
public dispose(): void {
|
|
1421
|
+
this.stopDiagnosticWorker();
|
|
1422
|
+
this.stopProjectConfigWatchers();
|
|
1423
|
+
this.stopCodeActionWorker();
|
|
1424
|
+
this.interopRenameSession.dispose();
|
|
1425
|
+
this.parsedDocuments.clear();
|
|
1426
|
+
this.stopRenameWorker();
|
|
1427
|
+
if (this.connection) {
|
|
1428
|
+
this.connection.dispose();
|
|
1429
|
+
this.connection = null;
|
|
1430
|
+
}
|
|
1431
|
+
this.documents.clear();
|
|
1432
|
+
this.pipelineCompletionInputs.clear();
|
|
1433
|
+
this.syntaxErrors.clear();
|
|
1434
|
+
this.interopDocuments.clear();
|
|
1435
|
+
this.removeAllListeners();
|
|
1436
|
+
}
|
|
1437
|
+
}
|