@soundscript/soundscript 0.1.13 → 0.1.15
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/package.json +15 -6
- package/project-transform/index.js +2 -0
- package/project-transform/index.ts +8 -0
- package/project-transform/src/annotation_syntax.js +948 -0
- package/project-transform/src/annotation_syntax.ts +1217 -0
- package/project-transform/src/build_package.js +475 -0
- package/project-transform/src/build_package.ts +683 -0
- package/project-transform/src/bundled/portable-web-globals.d.ts +153 -0
- package/project-transform/src/bundled/runtime_externs.js +220 -0
- package/project-transform/src/bundled/runtime_externs.ts +237 -0
- package/project-transform/src/bundled/sound-libs/lib.decorators.d.ts +385 -0
- package/project-transform/src/bundled/sound-libs/lib.decorators.legacy.d.ts +22 -0
- package/project-transform/src/bundled/sound-libs/lib.dom.asynciterable.d.ts +42 -0
- package/project-transform/src/bundled/sound-libs/lib.dom.d.ts +39440 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.collection.d.ts +149 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.core.d.ts +657 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.d.ts +28 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.generator.d.ts +77 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.iterable.d.ts +616 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.promise.d.ts +80 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.proxy.d.ts +128 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.reflect.d.ts +144 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.d.ts +46 -0
- package/project-transform/src/bundled/sound-libs/lib.es2015.symbol.wellknown.d.ts +170 -0
- package/project-transform/src/bundled/sound-libs/lib.es2016.array.include.d.ts +116 -0
- package/project-transform/src/bundled/sound-libs/lib.es2016.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.arraybuffer.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.date.d.ts +31 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.object.d.ts +49 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.string.d.ts +45 -0
- package/project-transform/src/bundled/sound-libs/lib.es2017.typedarrays.d.ts +53 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.asyncgenerator.d.ts +77 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.asynciterable.d.ts +57 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.promise.d.ts +30 -0
- package/project-transform/src/bundled/sound-libs/lib.es2018.regexp.d.ts +37 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.array.d.ts +79 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.object.d.ts +47 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.string.d.ts +37 -0
- package/project-transform/src/bundled/sound-libs/lib.es2019.symbol.d.ts +24 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.bigint.d.ts +765 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.d.ts +27 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.date.d.ts +42 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.number.d.ts +28 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.promise.d.ts +49 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.string.d.ts +44 -0
- package/project-transform/src/bundled/sound-libs/lib.es2020.symbol.wellknown.d.ts +41 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.d.ts +23 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.promise.d.ts +48 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.string.d.ts +33 -0
- package/project-transform/src/bundled/sound-libs/lib.es2021.weakref.d.ts +78 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.array.d.ts +121 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.error.d.ts +75 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.object.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.regexp.d.ts +39 -0
- package/project-transform/src/bundled/sound-libs/lib.es2022.string.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.array.d.ts +924 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.collection.d.ts +21 -0
- package/project-transform/src/bundled/sound-libs/lib.es2023.d.ts +22 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.arraybuffer.d.ts +65 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.collection.d.ts +29 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.d.ts +26 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.object.d.ts +33 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.promise.d.ts +35 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.regexp.d.ts +25 -0
- package/project-transform/src/bundled/sound-libs/lib.es2024.string.d.ts +29 -0
- package/project-transform/src/bundled/sound-libs/lib.es5.d.ts +4924 -0
- package/project-transform/src/bundled/sound_stdlib.js +142 -0
- package/project-transform/src/bundled/sound_stdlib.ts +180 -0
- package/project-transform/src/checker/analyze_project.js +1361 -0
- package/project-transform/src/checker/analyze_project.ts +2246 -0
- package/project-transform/src/checker/diagnostics.js +112 -0
- package/project-transform/src/checker/diagnostics.ts +222 -0
- package/project-transform/src/checker/engine/context.js +235 -0
- package/project-transform/src/checker/engine/context.ts +340 -0
- package/project-transform/src/checker/engine/diagnostic_codes.js +72 -0
- package/project-transform/src/checker/engine/diagnostic_codes.ts +95 -0
- package/project-transform/src/checker/engine/facts.js +35 -0
- package/project-transform/src/checker/engine/facts.ts +48 -0
- package/project-transform/src/checker/engine/types.js +1 -0
- package/project-transform/src/checker/engine/types.ts +485 -0
- package/project-transform/src/checker/proof_escape_hatch_diagnostics.js +104 -0
- package/project-transform/src/checker/proof_escape_hatch_diagnostics.ts +173 -0
- package/project-transform/src/checker/rules/async_surface.js +231 -0
- package/project-transform/src/checker/rules/async_surface.ts +335 -0
- package/project-transform/src/checker/rules/class_lifecycle.js +798 -0
- package/project-transform/src/checker/rules/class_lifecycle.ts +1276 -0
- package/project-transform/src/checker/rules/directive_validation.js +571 -0
- package/project-transform/src/checker/rules/directive_validation.ts +938 -0
- package/project-transform/src/checker/rules/directives.js +23 -0
- package/project-transform/src/checker/rules/directives.ts +25 -0
- package/project-transform/src/checker/rules/flow.js +202 -0
- package/project-transform/src/checker/rules/flow.ts +333 -0
- package/project-transform/src/checker/rules/flow_facts.js +601 -0
- package/project-transform/src/checker/rules/flow_facts.ts +978 -0
- package/project-transform/src/checker/rules/flow_invalidation.js +1119 -0
- package/project-transform/src/checker/rules/flow_invalidation.ts +2150 -0
- package/project-transform/src/checker/rules/flow_shared.js +2822 -0
- package/project-transform/src/checker/rules/flow_shared.ts +4383 -0
- package/project-transform/src/checker/rules/foreign_boundary.js +120 -0
- package/project-transform/src/checker/rules/foreign_boundary.ts +196 -0
- package/project-transform/src/checker/rules/foreign_projection.js +279 -0
- package/project-transform/src/checker/rules/foreign_projection.ts +425 -0
- package/project-transform/src/checker/rules/generated_helpers.js +13 -0
- package/project-transform/src/checker/rules/generated_helpers.ts +18 -0
- package/project-transform/src/checker/rules/index.js +35 -0
- package/project-transform/src/checker/rules/index.ts +49 -0
- package/project-transform/src/checker/rules/namespace_object.js +845 -0
- package/project-transform/src/checker/rules/namespace_object.ts +1224 -0
- package/project-transform/src/checker/rules/non_ordinary_recovery.js +1328 -0
- package/project-transform/src/checker/rules/non_ordinary_recovery.ts +2391 -0
- package/project-transform/src/checker/rules/null_prototype.js +3 -0
- package/project-transform/src/checker/rules/null_prototype.ts +6 -0
- package/project-transform/src/checker/rules/overloads.js +181 -0
- package/project-transform/src/checker/rules/overloads.ts +317 -0
- package/project-transform/src/checker/rules/predicate_verification.js +691 -0
- package/project-transform/src/checker/rules/predicate_verification.ts +1088 -0
- package/project-transform/src/checker/rules/prototype_hardening.js +237 -0
- package/project-transform/src/checker/rules/prototype_hardening.ts +343 -0
- package/project-transform/src/checker/rules/receiver_discipline.js +263 -0
- package/project-transform/src/checker/rules/receiver_discipline.ts +356 -0
- package/project-transform/src/checker/rules/relations.js +6861 -0
- package/project-transform/src/checker/rules/relations.ts +12158 -0
- package/project-transform/src/checker/rules/resolved_builtins.js +274 -0
- package/project-transform/src/checker/rules/resolved_builtins.ts +438 -0
- package/project-transform/src/checker/rules/trust.js +217 -0
- package/project-transform/src/checker/rules/trust.ts +301 -0
- package/project-transform/src/checker/rules/type_guards.js +173 -0
- package/project-transform/src/checker/rules/type_guards.ts +257 -0
- package/project-transform/src/checker/rules/universal.js +17 -0
- package/project-transform/src/checker/rules/universal.ts +22 -0
- package/project-transform/src/checker/rules/unsafe_value_origin.js +80 -0
- package/project-transform/src/checker/rules/unsafe_value_origin.ts +125 -0
- package/project-transform/src/checker/rules/unsound_imports.js +218 -0
- package/project-transform/src/checker/rules/unsound_imports.ts +301 -0
- package/project-transform/src/checker/rules/unsound_syntax.js +1695 -0
- package/project-transform/src/checker/rules/unsound_syntax.ts +2540 -0
- package/project-transform/src/checker/rules/value_types.js +206 -0
- package/project-transform/src/checker/rules/value_types.ts +407 -0
- package/project-transform/src/checker/timing.js +43 -0
- package/project-transform/src/checker/timing.ts +78 -0
- package/project-transform/src/checker/unsupported_feature_messages.js +337 -0
- package/project-transform/src/checker/unsupported_feature_messages.ts +531 -0
- package/project-transform/src/cli.js +892 -0
- package/project-transform/src/cli.ts +1476 -0
- package/project-transform/src/compiler/compile_project.js +319 -0
- package/project-transform/src/compiler/compile_project.ts +508 -0
- package/project-transform/src/compiler/errors.js +10 -0
- package/project-transform/src/compiler/errors.ts +29 -0
- package/project-transform/src/compiler/ir.js +1 -0
- package/project-transform/src/compiler/ir.ts +1526 -0
- package/project-transform/src/compiler/lower.js +30550 -0
- package/project-transform/src/compiler/lower.ts +43645 -0
- package/project-transform/src/compiler/lower_arrays.js +140 -0
- package/project-transform/src/compiler/lower_arrays.ts +190 -0
- package/project-transform/src/compiler/lower_strings.js +121 -0
- package/project-transform/src/compiler/lower_strings.ts +198 -0
- package/project-transform/src/compiler/lower_tagged.js +329 -0
- package/project-transform/src/compiler/lower_tagged.ts +427 -0
- package/project-transform/src/compiler/lower_views.js +171 -0
- package/project-transform/src/compiler/lower_views.ts +251 -0
- package/project-transform/src/compiler/object_keys.js +25 -0
- package/project-transform/src/compiler/object_keys.ts +35 -0
- package/project-transform/src/compiler/runtime_ir.js +30 -0
- package/project-transform/src/compiler/runtime_ir.ts +727 -0
- package/project-transform/src/compiler/tagged_boundary.js +18 -0
- package/project-transform/src/compiler/tagged_boundary.ts +37 -0
- package/project-transform/src/compiler/toolchain.js +170 -0
- package/project-transform/src/compiler/toolchain.ts +229 -0
- package/project-transform/src/compiler/unicode_case_data.js +2102 -0
- package/project-transform/src/compiler/unicode_case_data.ts +2112 -0
- package/project-transform/src/compiler/wasm_js_host_runtime.js +656 -0
- package/project-transform/src/compiler/wasm_js_host_runtime.ts +762 -0
- package/project-transform/src/compiler/wat_arrays.js +3132 -0
- package/project-transform/src/compiler/wat_arrays.ts +3768 -0
- package/project-transform/src/compiler/wat_emitter.js +17952 -0
- package/project-transform/src/compiler/wat_emitter.ts +22812 -0
- package/project-transform/src/compiler/wat_strings.js +129 -0
- package/project-transform/src/compiler/wat_strings.ts +187 -0
- package/project-transform/src/compiler/wat_tagged.js +548 -0
- package/project-transform/src/compiler/wat_tagged.ts +674 -0
- package/project-transform/src/compiler_generator_runner.js +153 -0
- package/project-transform/src/compiler_generator_runner.ts +171 -0
- package/project-transform/src/compiler_object_test_helpers.js +69 -0
- package/project-transform/src/compiler_object_test_helpers.ts +96 -0
- package/project-transform/src/compiler_promise_runner.js +2116 -0
- package/project-transform/src/compiler_promise_runner.ts +2184 -0
- package/project-transform/src/compiler_test_helpers.js +854 -0
- package/project-transform/src/compiler_test_helpers.ts +1087 -0
- package/project-transform/src/config.js +568 -0
- package/project-transform/src/config.ts +892 -0
- package/project-transform/src/diagnostic_metadata.js +67 -0
- package/project-transform/src/diagnostic_metadata.ts +99 -0
- package/project-transform/src/diagnostic_reference.js +1368 -0
- package/project-transform/src/diagnostic_reference.ts +1523 -0
- package/project-transform/src/editor_diagnostics_worker.js +176 -0
- package/project-transform/src/editor_diagnostics_worker.ts +250 -0
- package/project-transform/src/editor_projection.js +224 -0
- package/project-transform/src/editor_projection.ts +421 -0
- package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.js +47 -0
- package/project-transform/src/frontend/builtin_expanded_program_test_cleanup.ts +72 -0
- package/project-transform/src/frontend/builtin_macro_support.js +842 -0
- package/project-transform/src/frontend/builtin_macro_support.ts +1386 -0
- package/project-transform/src/frontend/builtin_macros.js +409 -0
- package/project-transform/src/frontend/builtin_macros.ts +542 -0
- package/project-transform/src/frontend/component_poc_runtime.js +279 -0
- package/project-transform/src/frontend/component_poc_runtime.ts +372 -0
- package/project-transform/src/frontend/css_macro.js +148 -0
- package/project-transform/src/frontend/css_macro.ts +222 -0
- package/project-transform/src/frontend/derive_macros.js +2072 -0
- package/project-transform/src/frontend/derive_macros.ts +3188 -0
- package/project-transform/src/frontend/embedded_fragment_support.js +106 -0
- package/project-transform/src/frontend/embedded_fragment_support.ts +172 -0
- package/project-transform/src/frontend/error_normalization.js +403 -0
- package/project-transform/src/frontend/error_normalization.ts +832 -0
- package/project-transform/src/frontend/error_stdlib_support.js +1 -0
- package/project-transform/src/frontend/error_stdlib_support.ts +6 -0
- package/project-transform/src/frontend/expand_project.js +169 -0
- package/project-transform/src/frontend/expand_project.ts +248 -0
- package/project-transform/src/frontend/format_soundscript.js +297 -0
- package/project-transform/src/frontend/format_soundscript.ts +582 -0
- package/project-transform/src/frontend/graphql_macro.js +174 -0
- package/project-transform/src/frontend/graphql_macro.ts +253 -0
- package/project-transform/src/frontend/hash_context.js +83 -0
- package/project-transform/src/frontend/hash_context.ts +113 -0
- package/project-transform/src/frontend/hkt_macro.js +448 -0
- package/project-transform/src/frontend/hkt_macro.ts +897 -0
- package/project-transform/src/frontend/import_binding_usage.js +190 -0
- package/project-transform/src/frontend/import_binding_usage.ts +277 -0
- package/project-transform/src/frontend/macro_advanced_backend_adapter.js +58 -0
- package/project-transform/src/frontend/macro_advanced_backend_adapter.ts +123 -0
- package/project-transform/src/frontend/macro_advanced_context.js +826 -0
- package/project-transform/src/frontend/macro_advanced_context.ts +1102 -0
- package/project-transform/src/frontend/macro_advanced_output.js +21 -0
- package/project-transform/src/frontend/macro_advanced_output.ts +41 -0
- package/project-transform/src/frontend/macro_api.js +353 -0
- package/project-transform/src/frontend/macro_api.ts +1722 -0
- package/project-transform/src/frontend/macro_api_internal.js +35 -0
- package/project-transform/src/frontend/macro_api_internal.ts +80 -0
- package/project-transform/src/frontend/macro_api_module_support.js +39 -0
- package/project-transform/src/frontend/macro_api_module_support.ts +65 -0
- package/project-transform/src/frontend/macro_backend_adapter.js +272 -0
- package/project-transform/src/frontend/macro_backend_adapter.ts +420 -0
- package/project-transform/src/frontend/macro_context.js +816 -0
- package/project-transform/src/frontend/macro_context.ts +1105 -0
- package/project-transform/src/frontend/macro_debug.js +99 -0
- package/project-transform/src/frontend/macro_debug.ts +157 -0
- package/project-transform/src/frontend/macro_definition_support.js +28 -0
- package/project-transform/src/frontend/macro_definition_support.ts +73 -0
- package/project-transform/src/frontend/macro_errors.js +40 -0
- package/project-transform/src/frontend/macro_errors.ts +70 -0
- package/project-transform/src/frontend/macro_expander.js +919 -0
- package/project-transform/src/frontend/macro_expander.ts +1611 -0
- package/project-transform/src/frontend/macro_factory_support.js +176 -0
- package/project-transform/src/frontend/macro_factory_support.ts +263 -0
- package/project-transform/src/frontend/macro_host_ast_internal.js +64 -0
- package/project-transform/src/frontend/macro_host_ast_internal.ts +109 -0
- package/project-transform/src/frontend/macro_index.js +27 -0
- package/project-transform/src/frontend/macro_index.ts +50 -0
- package/project-transform/src/frontend/macro_loader.js +281 -0
- package/project-transform/src/frontend/macro_loader.ts +506 -0
- package/project-transform/src/frontend/macro_operand_semantics.js +838 -0
- package/project-transform/src/frontend/macro_operand_semantics.ts +1489 -0
- package/project-transform/src/frontend/macro_output.js +54 -0
- package/project-transform/src/frontend/macro_output.ts +123 -0
- package/project-transform/src/frontend/macro_parser.js +611 -0
- package/project-transform/src/frontend/macro_parser.ts +832 -0
- package/project-transform/src/frontend/macro_resolver.js +69 -0
- package/project-transform/src/frontend/macro_resolver.ts +125 -0
- package/project-transform/src/frontend/macro_rewrite.js +285 -0
- package/project-transform/src/frontend/macro_rewrite.ts +442 -0
- package/project-transform/src/frontend/macro_runtime_support.js +232 -0
- package/project-transform/src/frontend/macro_runtime_support.ts +324 -0
- package/project-transform/src/frontend/macro_scanner.js +393 -0
- package/project-transform/src/frontend/macro_scanner.ts +455 -0
- package/project-transform/src/frontend/macro_semantic_backend_adapter.js +87 -0
- package/project-transform/src/frontend/macro_semantic_backend_adapter.ts +166 -0
- package/project-transform/src/frontend/macro_semantic_context.js +5 -0
- package/project-transform/src/frontend/macro_semantic_context.ts +12 -0
- package/project-transform/src/frontend/macro_semantic_output.js +24 -0
- package/project-transform/src/frontend/macro_semantic_output.ts +47 -0
- package/project-transform/src/frontend/macro_semantic_types.js +1 -0
- package/project-transform/src/frontend/macro_semantic_types.ts +98 -0
- package/project-transform/src/frontend/macro_semantics.js +1172 -0
- package/project-transform/src/frontend/macro_semantics.ts +1502 -0
- package/project-transform/src/frontend/macro_site_kind_support.js +164 -0
- package/project-transform/src/frontend/macro_site_kind_support.ts +255 -0
- package/project-transform/src/frontend/macro_syntax_internal.js +1950 -0
- package/project-transform/src/frontend/macro_syntax_internal.ts +3338 -0
- package/project-transform/src/frontend/macro_templates.js +57 -0
- package/project-transform/src/frontend/macro_templates.ts +143 -0
- package/project-transform/src/frontend/macro_test_helpers.js +82 -0
- package/project-transform/src/frontend/macro_test_helpers.ts +136 -0
- package/project-transform/src/frontend/macro_types.js +1 -0
- package/project-transform/src/frontend/macro_types.ts +103 -0
- package/project-transform/src/frontend/macro_vm.js +39 -0
- package/project-transform/src/frontend/macro_vm.ts +113 -0
- package/project-transform/src/frontend/match_macro.js +885 -0
- package/project-transform/src/frontend/match_macro.ts +1220 -0
- package/project-transform/src/frontend/numeric_normalization.js +824 -0
- package/project-transform/src/frontend/numeric_normalization.ts +1380 -0
- package/project-transform/src/frontend/numeric_prelude.js +278 -0
- package/project-transform/src/frontend/numeric_prelude.ts +370 -0
- package/project-transform/src/frontend/project_frontend.js +2396 -0
- package/project-transform/src/frontend/project_frontend.ts +3776 -0
- package/project-transform/src/frontend/project_macro_support.js +1401 -0
- package/project-transform/src/frontend/project_macro_support.ts +2137 -0
- package/project-transform/src/frontend/sql_macro.js +175 -0
- package/project-transform/src/frontend/sql_macro.ts +254 -0
- package/project-transform/src/frontend/sql_stdlib_support.js +1 -0
- package/project-transform/src/frontend/sql_stdlib_support.ts +6 -0
- package/project-transform/src/frontend/std_package_support.js +228 -0
- package/project-transform/src/frontend/std_package_support.ts +400 -0
- package/project-transform/src/frontend/value_normalization.js +306 -0
- package/project-transform/src/frontend/value_normalization.ts +599 -0
- package/project-transform/src/lsp/project_service.js +4771 -0
- package/project-transform/src/lsp/project_service.ts +7580 -0
- package/project-transform/src/lsp/protocol.js +9 -0
- package/project-transform/src/lsp/protocol.ts +38 -0
- package/project-transform/src/lsp/server.js +355 -0
- package/project-transform/src/lsp/server.ts +671 -0
- package/project-transform/src/lsp/session.js +49 -0
- package/project-transform/src/lsp/session.ts +48 -0
- package/project-transform/src/lsp/timing.js +43 -0
- package/project-transform/src/lsp/timing.ts +76 -0
- package/project-transform/src/lsp/transport.js +205 -0
- package/project-transform/src/lsp/transport.ts +253 -0
- package/project-transform/src/lsp_main.js +5 -0
- package/project-transform/src/lsp_main.ts +7 -0
- package/project-transform/src/macros.d.ts +1 -0
- package/project-transform/src/macros.js +1 -0
- package/project-transform/src/macros.ts +1 -0
- package/project-transform/src/main.js +24 -0
- package/project-transform/src/main.ts +28 -0
- package/project-transform/src/platform/host.js +264 -0
- package/project-transform/src/platform/host.ts +343 -0
- package/project-transform/src/platform/path.js +8 -0
- package/project-transform/src/platform/path.ts +20 -0
- package/project-transform/src/public_macro_api/macro_api.d.ts +1054 -0
- package/project-transform/src/public_macro_api/macro_semantic_types.d.ts +66 -0
- package/project-transform/src/public_macro_api/macro_types.d.ts +70 -0
- package/project-transform/src/run_program.js +14 -0
- package/project-transform/src/run_program.ts +33 -0
- package/project-transform/src/runtime/materialize.js +371 -0
- package/project-transform/src/runtime/materialize.ts +502 -0
- package/project-transform/src/runtime/on_demand.js +203 -0
- package/project-transform/src/runtime/on_demand.ts +305 -0
- package/project-transform/src/runtime/source_maps.js +205 -0
- package/project-transform/src/runtime/source_maps.ts +297 -0
- package/project-transform/src/runtime/transform.js +148 -0
- package/project-transform/src/runtime/transform.ts +295 -0
- package/project-transform/src/service/types.js +1 -0
- package/project-transform/src/service/types.ts +22 -0
- package/project-transform/src/soundscript_packages.js +477 -0
- package/project-transform/src/soundscript_packages.ts +754 -0
- package/project-transform/src/soundscript_runtime_specifiers.js +88 -0
- package/project-transform/src/soundscript_runtime_specifiers.ts +96 -0
- package/project-transform/src/stdlib/async.d.ts +81 -0
- package/project-transform/src/stdlib/async.js +213 -0
- package/project-transform/src/stdlib/async.ts +315 -0
- package/project-transform/src/stdlib/codec.d.ts +32 -0
- package/project-transform/src/stdlib/codec.js +30 -0
- package/project-transform/src/stdlib/codec.ts +76 -0
- package/project-transform/src/stdlib/compare.d.ts +28 -0
- package/project-transform/src/stdlib/compare.js +115 -0
- package/project-transform/src/stdlib/compare.ts +151 -0
- package/project-transform/src/stdlib/css.d.ts +16 -0
- package/project-transform/src/stdlib/css.js +9 -0
- package/project-transform/src/stdlib/css.ts +28 -0
- package/project-transform/src/stdlib/debug.d.ts +2 -0
- package/project-transform/src/stdlib/debug.js +9 -0
- package/project-transform/src/stdlib/debug.ts +10 -0
- package/project-transform/src/stdlib/decode.d.ts +86 -0
- package/project-transform/src/stdlib/decode.js +254 -0
- package/project-transform/src/stdlib/decode.ts +390 -0
- package/project-transform/src/stdlib/derive.d.ts +6 -0
- package/project-transform/src/stdlib/derive.js +7 -0
- package/project-transform/src/stdlib/derive.ts +7 -0
- package/project-transform/src/stdlib/encode.d.ts +100 -0
- package/project-transform/src/stdlib/encode.js +130 -0
- package/project-transform/src/stdlib/encode.ts +259 -0
- package/project-transform/src/stdlib/failures.d.ts +23 -0
- package/project-transform/src/stdlib/failures.js +41 -0
- package/project-transform/src/stdlib/failures.ts +64 -0
- package/project-transform/src/stdlib/fetch.d.ts +67 -0
- package/project-transform/src/stdlib/fetch.js +5 -0
- package/project-transform/src/stdlib/fetch.ts +11 -0
- package/project-transform/src/stdlib/graphql.d.ts +16 -0
- package/project-transform/src/stdlib/graphql.js +9 -0
- package/project-transform/src/stdlib/graphql.ts +28 -0
- package/project-transform/src/stdlib/hash.d.ts +34 -0
- package/project-transform/src/stdlib/hash.js +110 -0
- package/project-transform/src/stdlib/hash.ts +188 -0
- package/project-transform/src/stdlib/hkt.d.ts +40 -0
- package/project-transform/src/stdlib/hkt.js +3 -0
- package/project-transform/src/stdlib/hkt.ts +41 -0
- package/project-transform/src/stdlib/index.d.ts +9 -0
- package/project-transform/src/stdlib/index.js +15 -0
- package/project-transform/src/stdlib/index.ts +23 -0
- package/project-transform/src/stdlib/json.d.ts +125 -0
- package/project-transform/src/stdlib/json.js +764 -0
- package/project-transform/src/stdlib/json.ts +1034 -0
- package/project-transform/src/stdlib/match.d.ts +11 -0
- package/project-transform/src/stdlib/match.js +13 -0
- package/project-transform/src/stdlib/match.ts +26 -0
- package/project-transform/src/stdlib/numerics.d.ts +523 -0
- package/project-transform/src/stdlib/numerics.js +1356 -0
- package/project-transform/src/stdlib/numerics.ts +1937 -0
- package/project-transform/src/stdlib/random.d.ts +19 -0
- package/project-transform/src/stdlib/random.js +3 -0
- package/project-transform/src/stdlib/random.ts +5 -0
- package/project-transform/src/stdlib/result.d.ts +68 -0
- package/project-transform/src/stdlib/result.js +139 -0
- package/project-transform/src/stdlib/result.ts +248 -0
- package/project-transform/src/stdlib/sql.d.ts +22 -0
- package/project-transform/src/stdlib/sql.js +23 -0
- package/project-transform/src/stdlib/sql.ts +53 -0
- package/project-transform/src/stdlib/text.d.ts +24 -0
- package/project-transform/src/stdlib/text.js +3 -0
- package/project-transform/src/stdlib/text.ts +4 -0
- package/project-transform/src/stdlib/thunk.d.ts +2 -0
- package/project-transform/src/stdlib/thunk.js +9 -0
- package/project-transform/src/stdlib/thunk.ts +15 -0
- package/project-transform/src/stdlib/typeclasses.d.ts +57 -0
- package/project-transform/src/stdlib/typeclasses.js +78 -0
- package/project-transform/src/stdlib/typeclasses.ts +173 -0
- package/project-transform/src/stdlib/url.d.ts +37 -0
- package/project-transform/src/stdlib/url.js +3 -0
- package/project-transform/src/stdlib/url.ts +4 -0
- package/project-transform/src/stdlib/value.d.ts +9 -0
- package/project-transform/src/stdlib/value.js +104 -0
- package/project-transform/src/stdlib/value.ts +133 -0
- package/project-transform/src/test_installed_stdlib.js +147 -0
- package/project-transform/src/test_installed_stdlib.ts +245 -0
- package/project-transform/src/test_macro_package_fixture.js +50 -0
- package/project-transform/src/test_macro_package_fixture.ts +68 -0
- package/project-transform/src/value_deep_safe.js +191 -0
- package/project-transform/src/value_deep_safe.ts +273 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export interface OpenDocument {
|
|
2
|
+
languageId: string;
|
|
3
|
+
text: string;
|
|
4
|
+
uri: string;
|
|
5
|
+
version: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export class SessionState {
|
|
9
|
+
readonly #documents = new Map<string, OpenDocument>();
|
|
10
|
+
#revision = 0;
|
|
11
|
+
|
|
12
|
+
get(uri: string): OpenDocument | undefined {
|
|
13
|
+
return this.#documents.get(uri);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
getAll(): readonly OpenDocument[] {
|
|
17
|
+
return [...this.#documents.values()];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
revision(): number {
|
|
21
|
+
return this.#revision;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
open(document: OpenDocument): void {
|
|
25
|
+
this.#documents.set(document.uri, document);
|
|
26
|
+
this.#revision += 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
close(uri: string): void {
|
|
30
|
+
if (this.#documents.delete(uri)) {
|
|
31
|
+
this.#revision += 1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
update(uri: string, version: number, text: string): void {
|
|
36
|
+
const existing = this.#documents.get(uri);
|
|
37
|
+
if (!existing) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
this.#documents.set(uri, {
|
|
42
|
+
...existing,
|
|
43
|
+
text,
|
|
44
|
+
version,
|
|
45
|
+
});
|
|
46
|
+
this.#revision += 1;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { runtimeEnv } from '../platform/host.js';
|
|
2
|
+
const LSP_TIMING_ENV_VAR = 'SOUNDSCRIPT_LSP_TIMING';
|
|
3
|
+
const DEFAULT_LSP_TIMING_THRESHOLD_MS = 25;
|
|
4
|
+
export function isLspTimingEnabled(rawValue = runtimeEnv(LSP_TIMING_ENV_VAR)) {
|
|
5
|
+
return rawValue === '1' || rawValue === 'true';
|
|
6
|
+
}
|
|
7
|
+
function formatMetadata(metadata) {
|
|
8
|
+
return Object.entries(metadata)
|
|
9
|
+
.filter(([, value]) => value !== undefined)
|
|
10
|
+
.map(([key, value]) => `${key}=${String(value)}`)
|
|
11
|
+
.join(' ');
|
|
12
|
+
}
|
|
13
|
+
export function logLspTiming(operation, durationMs, metadata = {}, options = {}) {
|
|
14
|
+
const enabled = options.enabled ?? isLspTimingEnabled();
|
|
15
|
+
if (!enabled) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
const thresholdMs = options.thresholdMs ?? DEFAULT_LSP_TIMING_THRESHOLD_MS;
|
|
19
|
+
if (!options.always && durationMs < thresholdMs) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const metadataText = formatMetadata(metadata);
|
|
23
|
+
const prefix = `[soundscript:lsp] ${operation} ${durationMs.toFixed(1)}ms`;
|
|
24
|
+
console.error(metadataText.length > 0 ? `${prefix} ${metadataText}` : prefix);
|
|
25
|
+
}
|
|
26
|
+
export function measureLspTiming(operation, metadata, fn, options = {}) {
|
|
27
|
+
const start = performance.now();
|
|
28
|
+
try {
|
|
29
|
+
return fn();
|
|
30
|
+
}
|
|
31
|
+
finally {
|
|
32
|
+
logLspTiming(operation, performance.now() - start, metadata, options);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function measureLspTimingAsync(operation, metadata, fn, options = {}) {
|
|
36
|
+
const start = performance.now();
|
|
37
|
+
try {
|
|
38
|
+
return await fn();
|
|
39
|
+
}
|
|
40
|
+
finally {
|
|
41
|
+
logLspTiming(operation, performance.now() - start, metadata, options);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { runtimeEnv } from '../platform/host.ts';
|
|
2
|
+
|
|
3
|
+
const LSP_TIMING_ENV_VAR = 'SOUNDSCRIPT_LSP_TIMING';
|
|
4
|
+
const DEFAULT_LSP_TIMING_THRESHOLD_MS = 25;
|
|
5
|
+
|
|
6
|
+
export interface LspTimingMetadata {
|
|
7
|
+
[key: string]: boolean | number | string | undefined;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface LspTimingOptions {
|
|
11
|
+
always?: boolean;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
thresholdMs?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function isLspTimingEnabled(
|
|
17
|
+
rawValue = runtimeEnv(LSP_TIMING_ENV_VAR),
|
|
18
|
+
): boolean {
|
|
19
|
+
return rawValue === '1' || rawValue === 'true';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function formatMetadata(metadata: LspTimingMetadata): string {
|
|
23
|
+
return Object.entries(metadata)
|
|
24
|
+
.filter(([, value]) => value !== undefined)
|
|
25
|
+
.map(([key, value]) => `${key}=${String(value)}`)
|
|
26
|
+
.join(' ');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function logLspTiming(
|
|
30
|
+
operation: string,
|
|
31
|
+
durationMs: number,
|
|
32
|
+
metadata: LspTimingMetadata = {},
|
|
33
|
+
options: LspTimingOptions = {},
|
|
34
|
+
): void {
|
|
35
|
+
const enabled = options.enabled ?? isLspTimingEnabled();
|
|
36
|
+
if (!enabled) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const thresholdMs = options.thresholdMs ?? DEFAULT_LSP_TIMING_THRESHOLD_MS;
|
|
41
|
+
if (!options.always && durationMs < thresholdMs) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const metadataText = formatMetadata(metadata);
|
|
46
|
+
const prefix = `[soundscript:lsp] ${operation} ${durationMs.toFixed(1)}ms`;
|
|
47
|
+
console.error(metadataText.length > 0 ? `${prefix} ${metadataText}` : prefix);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function measureLspTiming<T>(
|
|
51
|
+
operation: string,
|
|
52
|
+
metadata: LspTimingMetadata,
|
|
53
|
+
fn: () => T,
|
|
54
|
+
options: LspTimingOptions = {},
|
|
55
|
+
): T {
|
|
56
|
+
const start = performance.now();
|
|
57
|
+
try {
|
|
58
|
+
return fn();
|
|
59
|
+
} finally {
|
|
60
|
+
logLspTiming(operation, performance.now() - start, metadata, options);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export async function measureLspTimingAsync<T>(
|
|
65
|
+
operation: string,
|
|
66
|
+
metadata: LspTimingMetadata,
|
|
67
|
+
fn: () => Promise<T>,
|
|
68
|
+
options: LspTimingOptions = {},
|
|
69
|
+
): Promise<T> {
|
|
70
|
+
const start = performance.now();
|
|
71
|
+
try {
|
|
72
|
+
return await fn();
|
|
73
|
+
} finally {
|
|
74
|
+
logLspTiming(operation, performance.now() - start, metadata, options);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
6
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
7
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
|
+
};
|
|
12
|
+
var _AsyncMessageQueue_items, _AsyncMessageQueue_waiters, _MemoryClient_nextRequestId;
|
|
13
|
+
import { runtimeStdinReadable, runtimeStdoutWritable } from '../platform/host.js';
|
|
14
|
+
import { isJsonRpcNotification, isJsonRpcResponse } from './protocol.js';
|
|
15
|
+
class AsyncMessageQueue {
|
|
16
|
+
constructor() {
|
|
17
|
+
_AsyncMessageQueue_items.set(this, []);
|
|
18
|
+
_AsyncMessageQueue_waiters.set(this, []);
|
|
19
|
+
}
|
|
20
|
+
push(message) {
|
|
21
|
+
const waiter = __classPrivateFieldGet(this, _AsyncMessageQueue_waiters, "f").shift();
|
|
22
|
+
if (waiter) {
|
|
23
|
+
waiter(message);
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
__classPrivateFieldGet(this, _AsyncMessageQueue_items, "f").push(message);
|
|
27
|
+
}
|
|
28
|
+
shift() {
|
|
29
|
+
const message = __classPrivateFieldGet(this, _AsyncMessageQueue_items, "f").shift();
|
|
30
|
+
if (message !== undefined) {
|
|
31
|
+
return Promise.resolve(message);
|
|
32
|
+
}
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
__classPrivateFieldGet(this, _AsyncMessageQueue_waiters, "f").push(resolve);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
_AsyncMessageQueue_items = new WeakMap(), _AsyncMessageQueue_waiters = new WeakMap();
|
|
39
|
+
class QueueTransport {
|
|
40
|
+
constructor(inbound, outbound) {
|
|
41
|
+
this.inbound = inbound;
|
|
42
|
+
this.outbound = outbound;
|
|
43
|
+
}
|
|
44
|
+
read() {
|
|
45
|
+
return this.inbound.shift();
|
|
46
|
+
}
|
|
47
|
+
write(message) {
|
|
48
|
+
this.outbound.push(message);
|
|
49
|
+
return Promise.resolve();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
class MemoryClient {
|
|
53
|
+
constructor(requests, responses) {
|
|
54
|
+
this.requests = requests;
|
|
55
|
+
this.responses = responses;
|
|
56
|
+
_MemoryClient_nextRequestId.set(this, 1);
|
|
57
|
+
}
|
|
58
|
+
async readNotification(method) {
|
|
59
|
+
while (true) {
|
|
60
|
+
const message = await this.responses.shift();
|
|
61
|
+
if (message === null) {
|
|
62
|
+
throw new Error('Transport closed before notification was received.');
|
|
63
|
+
}
|
|
64
|
+
if (isJsonRpcNotification(message) && message.method === method) {
|
|
65
|
+
return message;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
async readResponse(expectedId) {
|
|
70
|
+
while (true) {
|
|
71
|
+
const message = await this.responses.shift();
|
|
72
|
+
if (message === null) {
|
|
73
|
+
throw new Error('Transport closed before response was received.');
|
|
74
|
+
}
|
|
75
|
+
if (isJsonRpcResponse(message) && message.id === expectedId) {
|
|
76
|
+
return message;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
sendNotification(method, params) {
|
|
81
|
+
this.requests.push({
|
|
82
|
+
jsonrpc: '2.0',
|
|
83
|
+
method,
|
|
84
|
+
params,
|
|
85
|
+
});
|
|
86
|
+
return Promise.resolve();
|
|
87
|
+
}
|
|
88
|
+
sendRequest(method, params) {
|
|
89
|
+
const id = __classPrivateFieldGet(this, _MemoryClient_nextRequestId, "f");
|
|
90
|
+
__classPrivateFieldSet(this, _MemoryClient_nextRequestId, __classPrivateFieldGet(this, _MemoryClient_nextRequestId, "f") + 1, "f");
|
|
91
|
+
this.requests.push({
|
|
92
|
+
jsonrpc: '2.0',
|
|
93
|
+
id,
|
|
94
|
+
method,
|
|
95
|
+
params,
|
|
96
|
+
});
|
|
97
|
+
return Promise.resolve(id);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
_MemoryClient_nextRequestId = new WeakMap();
|
|
101
|
+
async function readExactly(reader, length) {
|
|
102
|
+
const buffer = new Uint8Array(length);
|
|
103
|
+
let offset = 0;
|
|
104
|
+
while (offset < length) {
|
|
105
|
+
const bytesRead = await reader.read(buffer.subarray(offset));
|
|
106
|
+
if (bytesRead === null) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
offset += bytesRead;
|
|
110
|
+
}
|
|
111
|
+
return buffer;
|
|
112
|
+
}
|
|
113
|
+
async function readHeaders(reader) {
|
|
114
|
+
const bytes = [];
|
|
115
|
+
const singleByte = new Uint8Array(1);
|
|
116
|
+
while (true) {
|
|
117
|
+
const bytesRead = await reader.read(singleByte);
|
|
118
|
+
if (bytesRead === null) {
|
|
119
|
+
return bytes.length === 0 ? null : new TextDecoder().decode(new Uint8Array(bytes));
|
|
120
|
+
}
|
|
121
|
+
bytes.push(singleByte[0]);
|
|
122
|
+
const byteCount = bytes.length;
|
|
123
|
+
if (byteCount >= 4 &&
|
|
124
|
+
bytes[byteCount - 4] === 13 &&
|
|
125
|
+
bytes[byteCount - 3] === 10 &&
|
|
126
|
+
bytes[byteCount - 2] === 13 &&
|
|
127
|
+
bytes[byteCount - 1] === 10) {
|
|
128
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function createByteReader(readable) {
|
|
133
|
+
const reader = readable.getReader();
|
|
134
|
+
let buffered = new Uint8Array(0);
|
|
135
|
+
return {
|
|
136
|
+
async read(target) {
|
|
137
|
+
while (buffered.byteLength === 0) {
|
|
138
|
+
const { done, value } = await reader.read();
|
|
139
|
+
if (done) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
buffered = value ?? new Uint8Array(0);
|
|
143
|
+
}
|
|
144
|
+
const byteLength = Math.min(target.byteLength, buffered.byteLength);
|
|
145
|
+
target.set(buffered.subarray(0, byteLength));
|
|
146
|
+
buffered = buffered.subarray(byteLength);
|
|
147
|
+
return byteLength;
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
function createByteWriter(writable) {
|
|
152
|
+
const writer = writable.getWriter();
|
|
153
|
+
return {
|
|
154
|
+
async write(buffer) {
|
|
155
|
+
await writer.write(buffer);
|
|
156
|
+
return buffer.byteLength;
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
export function createMemoryTransportPair() {
|
|
161
|
+
const requests = new AsyncMessageQueue();
|
|
162
|
+
const responses = new AsyncMessageQueue();
|
|
163
|
+
return {
|
|
164
|
+
client: new MemoryClient(requests, responses),
|
|
165
|
+
server: new QueueTransport(requests, responses),
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
export function createStdioTransport(reader = createByteReader(runtimeStdinReadable()), writer = createByteWriter(runtimeStdoutWritable())) {
|
|
169
|
+
const encoder = new TextEncoder();
|
|
170
|
+
const decoder = new TextDecoder();
|
|
171
|
+
let pendingWrite = Promise.resolve();
|
|
172
|
+
return {
|
|
173
|
+
async read() {
|
|
174
|
+
const headerText = await readHeaders(reader);
|
|
175
|
+
if (headerText === null) {
|
|
176
|
+
return null;
|
|
177
|
+
}
|
|
178
|
+
const contentLengthHeader = headerText
|
|
179
|
+
.split('\r\n')
|
|
180
|
+
.find((header) => header.toLowerCase().startsWith('content-length:'));
|
|
181
|
+
if (!contentLengthHeader) {
|
|
182
|
+
throw new Error('Missing Content-Length header.');
|
|
183
|
+
}
|
|
184
|
+
const contentLength = Number.parseInt(contentLengthHeader.split(':')[1]?.trim() ?? '', 10);
|
|
185
|
+
if (!Number.isFinite(contentLength) || contentLength < 0) {
|
|
186
|
+
throw new Error('Invalid Content-Length header.');
|
|
187
|
+
}
|
|
188
|
+
const payloadBytes = await readExactly(reader, contentLength);
|
|
189
|
+
if (payloadBytes === null) {
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
return JSON.parse(decoder.decode(payloadBytes));
|
|
193
|
+
},
|
|
194
|
+
async write(message) {
|
|
195
|
+
const writeOperation = pendingWrite.then(async () => {
|
|
196
|
+
const payload = encoder.encode(JSON.stringify(message));
|
|
197
|
+
const header = encoder.encode(`Content-Length: ${payload.byteLength}\r\n\r\n`);
|
|
198
|
+
await writer.write(header);
|
|
199
|
+
await writer.write(payload);
|
|
200
|
+
});
|
|
201
|
+
pendingWrite = writeOperation.catch(() => { });
|
|
202
|
+
await writeOperation;
|
|
203
|
+
},
|
|
204
|
+
};
|
|
205
|
+
}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import { runtimeStdinReadable, runtimeStdoutWritable } from '../platform/host.ts';
|
|
2
|
+
import { isJsonRpcNotification, isJsonRpcResponse, type JsonRpcMessage } from './protocol.ts';
|
|
3
|
+
|
|
4
|
+
export interface MessageTransport {
|
|
5
|
+
read(): Promise<JsonRpcMessage | null>;
|
|
6
|
+
write(message: JsonRpcMessage): Promise<void>;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface ByteReader {
|
|
10
|
+
read(buffer: Uint8Array): Promise<number | null>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
interface ByteWriter {
|
|
14
|
+
write(buffer: Uint8Array): Promise<number>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
class AsyncMessageQueue {
|
|
18
|
+
readonly #items: (JsonRpcMessage | null)[] = [];
|
|
19
|
+
readonly #waiters: ((message: JsonRpcMessage | null) => void)[] = [];
|
|
20
|
+
|
|
21
|
+
push(message: JsonRpcMessage | null): void {
|
|
22
|
+
const waiter = this.#waiters.shift();
|
|
23
|
+
if (waiter) {
|
|
24
|
+
waiter(message);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
this.#items.push(message);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
shift(): Promise<JsonRpcMessage | null> {
|
|
32
|
+
const message = this.#items.shift();
|
|
33
|
+
if (message !== undefined) {
|
|
34
|
+
return Promise.resolve(message);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return new Promise((resolve) => {
|
|
38
|
+
this.#waiters.push(resolve);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
class QueueTransport implements MessageTransport {
|
|
44
|
+
constructor(
|
|
45
|
+
private readonly inbound: AsyncMessageQueue,
|
|
46
|
+
private readonly outbound: AsyncMessageQueue,
|
|
47
|
+
) {}
|
|
48
|
+
|
|
49
|
+
read(): Promise<JsonRpcMessage | null> {
|
|
50
|
+
return this.inbound.shift();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
write(message: JsonRpcMessage): Promise<void> {
|
|
54
|
+
this.outbound.push(message);
|
|
55
|
+
return Promise.resolve();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
class MemoryClient {
|
|
60
|
+
#nextRequestId = 1;
|
|
61
|
+
|
|
62
|
+
constructor(
|
|
63
|
+
private readonly requests: AsyncMessageQueue,
|
|
64
|
+
private readonly responses: AsyncMessageQueue,
|
|
65
|
+
) {}
|
|
66
|
+
|
|
67
|
+
async readNotification(
|
|
68
|
+
method: string,
|
|
69
|
+
): Promise<JsonRpcMessage & { method: string; params?: unknown }> {
|
|
70
|
+
while (true) {
|
|
71
|
+
const message = await this.responses.shift();
|
|
72
|
+
if (message === null) {
|
|
73
|
+
throw new Error('Transport closed before notification was received.');
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isJsonRpcNotification(message) && message.method === method) {
|
|
77
|
+
return message;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async readResponse(
|
|
83
|
+
expectedId: number,
|
|
84
|
+
): Promise<{ error?: unknown; id: number; result?: unknown }> {
|
|
85
|
+
while (true) {
|
|
86
|
+
const message = await this.responses.shift();
|
|
87
|
+
if (message === null) {
|
|
88
|
+
throw new Error('Transport closed before response was received.');
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
if (isJsonRpcResponse(message) && message.id === expectedId) {
|
|
92
|
+
return message;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
sendNotification(method: string, params?: unknown): Promise<void> {
|
|
98
|
+
this.requests.push({
|
|
99
|
+
jsonrpc: '2.0',
|
|
100
|
+
method,
|
|
101
|
+
params,
|
|
102
|
+
});
|
|
103
|
+
return Promise.resolve();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
sendRequest(method: string, params?: unknown): Promise<number> {
|
|
107
|
+
const id = this.#nextRequestId;
|
|
108
|
+
this.#nextRequestId += 1;
|
|
109
|
+
|
|
110
|
+
this.requests.push({
|
|
111
|
+
jsonrpc: '2.0',
|
|
112
|
+
id,
|
|
113
|
+
method,
|
|
114
|
+
params,
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
return Promise.resolve(id);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function readExactly(reader: ByteReader, length: number): Promise<Uint8Array | null> {
|
|
122
|
+
const buffer = new Uint8Array(length);
|
|
123
|
+
let offset = 0;
|
|
124
|
+
|
|
125
|
+
while (offset < length) {
|
|
126
|
+
const bytesRead = await reader.read(buffer.subarray(offset));
|
|
127
|
+
if (bytesRead === null) {
|
|
128
|
+
return null;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
offset += bytesRead;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return buffer;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async function readHeaders(reader: ByteReader): Promise<string | null> {
|
|
138
|
+
const bytes: number[] = [];
|
|
139
|
+
const singleByte = new Uint8Array(1);
|
|
140
|
+
|
|
141
|
+
while (true) {
|
|
142
|
+
const bytesRead = await reader.read(singleByte);
|
|
143
|
+
if (bytesRead === null) {
|
|
144
|
+
return bytes.length === 0 ? null : new TextDecoder().decode(new Uint8Array(bytes));
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
bytes.push(singleByte[0]);
|
|
148
|
+
const byteCount = bytes.length;
|
|
149
|
+
if (
|
|
150
|
+
byteCount >= 4 &&
|
|
151
|
+
bytes[byteCount - 4] === 13 &&
|
|
152
|
+
bytes[byteCount - 3] === 10 &&
|
|
153
|
+
bytes[byteCount - 2] === 13 &&
|
|
154
|
+
bytes[byteCount - 1] === 10
|
|
155
|
+
) {
|
|
156
|
+
return new TextDecoder().decode(new Uint8Array(bytes));
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function createByteReader(readable: ReadableStream<Uint8Array>): ByteReader {
|
|
162
|
+
const reader = readable.getReader();
|
|
163
|
+
let buffered: Uint8Array<ArrayBufferLike> = new Uint8Array(0);
|
|
164
|
+
|
|
165
|
+
return {
|
|
166
|
+
async read(target: Uint8Array): Promise<number | null> {
|
|
167
|
+
while (buffered.byteLength === 0) {
|
|
168
|
+
const { done, value } = await reader.read();
|
|
169
|
+
if (done) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
buffered = value ?? new Uint8Array(0);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const byteLength = Math.min(target.byteLength, buffered.byteLength);
|
|
176
|
+
target.set(buffered.subarray(0, byteLength));
|
|
177
|
+
buffered = buffered.subarray(byteLength);
|
|
178
|
+
return byteLength;
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function createByteWriter(writable: WritableStream<Uint8Array>): ByteWriter {
|
|
184
|
+
const writer = writable.getWriter();
|
|
185
|
+
|
|
186
|
+
return {
|
|
187
|
+
async write(buffer: Uint8Array): Promise<number> {
|
|
188
|
+
await writer.write(buffer);
|
|
189
|
+
return buffer.byteLength;
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function createMemoryTransportPair(): {
|
|
195
|
+
client: MemoryClient;
|
|
196
|
+
server: MessageTransport;
|
|
197
|
+
} {
|
|
198
|
+
const requests = new AsyncMessageQueue();
|
|
199
|
+
const responses = new AsyncMessageQueue();
|
|
200
|
+
|
|
201
|
+
return {
|
|
202
|
+
client: new MemoryClient(requests, responses),
|
|
203
|
+
server: new QueueTransport(requests, responses),
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function createStdioTransport(
|
|
208
|
+
reader: ByteReader = createByteReader(runtimeStdinReadable()),
|
|
209
|
+
writer: ByteWriter = createByteWriter(runtimeStdoutWritable()),
|
|
210
|
+
): MessageTransport {
|
|
211
|
+
const encoder = new TextEncoder();
|
|
212
|
+
const decoder = new TextDecoder();
|
|
213
|
+
let pendingWrite: Promise<void> = Promise.resolve();
|
|
214
|
+
|
|
215
|
+
return {
|
|
216
|
+
async read(): Promise<JsonRpcMessage | null> {
|
|
217
|
+
const headerText = await readHeaders(reader);
|
|
218
|
+
if (headerText === null) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const contentLengthHeader = headerText
|
|
223
|
+
.split('\r\n')
|
|
224
|
+
.find((header) => header.toLowerCase().startsWith('content-length:'));
|
|
225
|
+
if (!contentLengthHeader) {
|
|
226
|
+
throw new Error('Missing Content-Length header.');
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const contentLength = Number.parseInt(contentLengthHeader.split(':')[1]?.trim() ?? '', 10);
|
|
230
|
+
if (!Number.isFinite(contentLength) || contentLength < 0) {
|
|
231
|
+
throw new Error('Invalid Content-Length header.');
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const payloadBytes = await readExactly(reader, contentLength);
|
|
235
|
+
if (payloadBytes === null) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return JSON.parse(decoder.decode(payloadBytes)) as JsonRpcMessage;
|
|
240
|
+
},
|
|
241
|
+
|
|
242
|
+
async write(message: JsonRpcMessage): Promise<void> {
|
|
243
|
+
const writeOperation = pendingWrite.then(async () => {
|
|
244
|
+
const payload = encoder.encode(JSON.stringify(message));
|
|
245
|
+
const header = encoder.encode(`Content-Length: ${payload.byteLength}\r\n\r\n`);
|
|
246
|
+
await writer.write(header);
|
|
247
|
+
await writer.write(payload);
|
|
248
|
+
});
|
|
249
|
+
pendingWrite = writeOperation.catch(() => {});
|
|
250
|
+
await writeOperation;
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './public_macro_api/macro_api';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './frontend/macro_api.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './frontend/macro_api.ts';
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { runCli } from './cli.js';
|
|
2
|
+
import { parseCommand } from './config.js';
|
|
3
|
+
import { runEditorDiagnosticsWorker } from './editor_diagnostics_worker.js';
|
|
4
|
+
import { createServer } from './lsp/server.js';
|
|
5
|
+
import { createStdioTransport } from './lsp/transport.js';
|
|
6
|
+
import { runtimeArgs, runtimeCwd, runtimeExit, writeStdout } from './platform/host.js';
|
|
7
|
+
async function main() {
|
|
8
|
+
const args = runtimeArgs();
|
|
9
|
+
const command = parseCommand(args, runtimeCwd());
|
|
10
|
+
if (command.kind === 'lsp') {
|
|
11
|
+
const transport = createStdioTransport();
|
|
12
|
+
const server = createServer(transport);
|
|
13
|
+
await server.start();
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
if (command.kind === 'editor-worker') {
|
|
17
|
+
await runEditorDiagnosticsWorker();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
const result = await runCli(args);
|
|
21
|
+
writeStdout(result.output);
|
|
22
|
+
runtimeExit(result.exitCode);
|
|
23
|
+
}
|
|
24
|
+
await main();
|