@greenpandastudios/aug-cli 0.19.0
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 +13 -0
- package/THIRD_PARTY_NOTICES.md +18 -0
- package/bin/aug.mjs +3 -0
- package/docs/api/crypto.md +351 -0
- package/docs/api/io.md +207 -0
- package/docs/api/json.md +21 -0
- package/docs/api/memory.md +109 -0
- package/docs/api/time.md +54 -0
- package/docs/api/web.md +184 -0
- package/docs/assets/benchmarks/execution.svg +2978 -0
- package/docs/assets/benchmarks/http.svg +1674 -0
- package/docs/assets/benchmarks/improvements.svg +2315 -0
- package/docs/assets/benchmarks/memory.svg +1891 -0
- package/docs/benchmark-baseline.json +1087 -0
- package/docs/benchmark-results.json +91123 -0
- package/docs/benchmarks.json +38 -0
- package/docs/compatibility.md +42 -0
- package/docs/concurrency-implementation.md +18 -0
- package/docs/diagnostics.md +97 -0
- package/docs/docker.md +35 -0
- package/docs/example-projects.json +26 -0
- package/docs/examples/approved-design/counters.md +253 -0
- package/docs/examples/approved-design/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/approved-design/domain/app.md +165 -0
- package/docs/examples/approved-design/domain/export.md +83 -0
- package/docs/examples/approved-design/domain/models.md +80 -0
- package/docs/examples/approved-design/domain/numbers.md +248 -0
- package/docs/examples/approved-design/index.md +39 -0
- package/docs/examples/approved-design/main-yaml.md +24 -0
- package/docs/examples/approved-design/main.md +215 -0
- package/docs/examples/benchmark/index.md +33 -0
- package/docs/examples/benchmark/main-yaml.md +17 -0
- package/docs/examples/benchmark/main.md +117 -0
- package/docs/examples/cli-args/index.md +32 -0
- package/docs/examples/cli-args/main.md +107 -0
- package/docs/examples/collections/index.md +32 -0
- package/docs/examples/collections/main.md +118 -0
- package/docs/examples/collections-benchmark/index.md +34 -0
- package/docs/examples/collections-benchmark/main.md +115 -0
- package/docs/examples/cpu-benchmark/index.md +34 -0
- package/docs/examples/cpu-benchmark/main.md +90 -0
- package/docs/examples/developer-workflow/calculator.md +357 -0
- package/docs/examples/developer-workflow/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/developer-workflow/index.md +37 -0
- package/docs/examples/developer-workflow/logging/console.md +124 -0
- package/docs/examples/developer-workflow/logging/export.md +70 -0
- package/docs/examples/developer-workflow/logging/logger.md +111 -0
- package/docs/examples/developer-workflow/main.md +172 -0
- package/docs/examples/drop/index.md +33 -0
- package/docs/examples/drop/main.md +85 -0
- package/docs/examples/drop/resource.md +95 -0
- package/docs/examples/errors/errors.md +85 -0
- package/docs/examples/errors/index.md +33 -0
- package/docs/examples/errors/main.md +92 -0
- package/docs/examples/ffi/index.md +33 -0
- package/docs/examples/ffi/main.md +75 -0
- package/docs/examples/ffi/native.md +93 -0
- package/docs/examples/generic-di/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/generic-di/index.md +33 -0
- package/docs/examples/generic-di/main.md +111 -0
- package/docs/examples/generic-di/types.md +180 -0
- package/docs/examples/generics/index.md +33 -0
- package/docs/examples/generics/main.md +120 -0
- package/docs/examples/generics/types.md +189 -0
- package/docs/examples/hello/app/export.md +67 -0
- package/docs/examples/hello/app/greeter.md +190 -0
- package/docs/examples/hello/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/hello/index.md +37 -0
- package/docs/examples/hello/logging/console.md +121 -0
- package/docs/examples/hello/logging/export.md +71 -0
- package/docs/examples/hello/logging/logger.md +120 -0
- package/docs/examples/hello/main.md +115 -0
- package/docs/examples/http-benchmark/index.md +35 -0
- package/docs/examples/http-benchmark/main.md +79 -0
- package/docs/examples/http-benchmark/routes.md +88 -0
- package/docs/examples/index.md +60 -0
- package/docs/examples/interceptors/app.md +250 -0
- package/docs/examples/interceptors/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/interceptors/index.md +35 -0
- package/docs/examples/interceptors/interceptors.md +284 -0
- package/docs/examples/interceptors/logging.md +155 -0
- package/docs/examples/interceptors/main.md +162 -0
- package/docs/examples/json-benchmark/data.md +71 -0
- package/docs/examples/json-benchmark/dependencies/august/0.19.0/json/contracts.md +103 -0
- package/docs/examples/json-benchmark/index.md +35 -0
- package/docs/examples/json-benchmark/main.md +131 -0
- package/docs/examples/new-syntax/console.md +118 -0
- package/docs/examples/new-syntax/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/new-syntax/greeter.md +145 -0
- package/docs/examples/new-syntax/index.md +36 -0
- package/docs/examples/new-syntax/logger.md +111 -0
- package/docs/examples/new-syntax/main.md +135 -0
- package/docs/examples/new-syntax/math.md +79 -0
- package/docs/examples/oidc-login/client/contracts.md +151 -0
- package/docs/examples/oidc-login/client/endpoints.md +263 -0
- package/docs/examples/oidc-login/client/export.md +107 -0
- package/docs/examples/oidc-login/client/login.md +515 -0
- package/docs/examples/oidc-login/client/logout.md +249 -0
- package/docs/examples/oidc-login/client/protocol.md +595 -0
- package/docs/examples/oidc-login/client/session.md +297 -0
- package/docs/examples/oidc-login/client/views.md +144 -0
- package/docs/examples/oidc-login/common/export.md +115 -0
- package/docs/examples/oidc-login/common/headers.md +162 -0
- package/docs/examples/oidc-login/common/keys.md +336 -0
- package/docs/examples/oidc-login/common/settings.md +116 -0
- package/docs/examples/oidc-login/common/views.md +103 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/crypto/contracts.md +925 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/crypto/jose.md +434 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/json/contracts.md +103 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/memory/store.md +374 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/time/contracts.md +150 -0
- package/docs/examples/oidc-login/dependencies/august/0.19.0/web/contracts.md +532 -0
- package/docs/examples/oidc-login/index.md +57 -0
- package/docs/examples/oidc-login/main-yaml.md +28 -0
- package/docs/examples/oidc-login/main.md +283 -0
- package/docs/examples/oidc-login/provider/authorization.md +457 -0
- package/docs/examples/oidc-login/provider/contracts.md +267 -0
- package/docs/examples/oidc-login/provider/credentials.md +148 -0
- package/docs/examples/oidc-login/provider/discovery.md +215 -0
- package/docs/examples/oidc-login/provider/export.md +131 -0
- package/docs/examples/oidc-login/provider/token.md +364 -0
- package/docs/examples/oidc-login/provider/userinfo.md +228 -0
- package/docs/examples/oidc-login/provider/views.md +137 -0
- package/docs/examples/ownership/counter.md +140 -0
- package/docs/examples/ownership/index.md +33 -0
- package/docs/examples/ownership/main.md +90 -0
- package/docs/examples/ownership-transfer/dependencies/august/0.19.0/io/contracts.md +395 -0
- package/docs/examples/ownership-transfer/index.md +33 -0
- package/docs/examples/ownership-transfer/main.md +125 -0
- package/docs/examples/ownership-transfer/resource.md +150 -0
- package/docs/examples/packages-app/dependencies/packages/@example/aug-math/0.1.0/arithmetic.md +117 -0
- package/docs/examples/packages-app/index.md +34 -0
- package/docs/examples/packages-app/main-yaml.md +18 -0
- package/docs/examples/packages-app/main.md +80 -0
- package/docs/examples/packages-math/aug-package-json.md +24 -0
- package/docs/examples/packages-math/index.md +36 -0
- package/docs/examples/packages-math/package-json.md +25 -0
- package/docs/examples/packages-math/src/arithmetic.md +121 -0
- package/docs/examples/packages-math/src/export.md +63 -0
- package/docs/examples/startup-benchmark/index.md +34 -0
- package/docs/examples/startup-benchmark/main.md +68 -0
- package/docs/examples/visibility/counter.md +142 -0
- package/docs/examples/visibility/index.md +33 -0
- package/docs/examples/visibility/main.md +96 -0
- package/docs/examples.json +47 -0
- package/docs/getting-started.md +5 -0
- package/docs/grammar.md +136 -0
- package/docs/implementation-map.md +106 -0
- package/docs/index.md +46 -0
- package/docs/language-conformance.md +30 -0
- package/docs/language-constructs.md +1461 -0
- package/docs/language-design-audit.md +147 -0
- package/docs/maintaining-docs.md +43 -0
- package/docs/packages.md +184 -0
- package/docs/performance.md +535 -0
- package/docs/production-readiness.md +39 -0
- package/docs/reference.md +361 -0
- package/docs/release-review.md +23 -0
- package/docs/releasing.md +79 -0
- package/docs/roadmap.md +13 -0
- package/docs/specifications.md +86 -0
- package/docs/testing.md +120 -0
- package/docs/tooling.md +197 -0
- package/docs/web-implementation-plan.md +39 -0
- package/docs/web-library-gaps.md +27 -0
- package/docs/web.md +197 -0
- package/examples/approved-design/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/approved-design/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/approved-design/.aug-spec/manifest.json +14 -0
- package/examples/approved-design/counters.aug +22 -0
- package/examples/approved-design/counters.aug.md +177 -0
- package/examples/approved-design/domain/app.aug +12 -0
- package/examples/approved-design/domain/app.aug.md +97 -0
- package/examples/approved-design/domain/export.aug +5 -0
- package/examples/approved-design/domain/export.aug.md +25 -0
- package/examples/approved-design/domain/models.aug +2 -0
- package/examples/approved-design/domain/models.aug.md +30 -0
- package/examples/approved-design/domain/numbers.aug +29 -0
- package/examples/approved-design/domain/numbers.aug.md +141 -0
- package/examples/approved-design/main.aug +26 -0
- package/examples/approved-design/main.aug.md +108 -0
- package/examples/approved-design/main.yaml +8 -0
- package/examples/benchmark/.aug-spec/manifest.json +7 -0
- package/examples/benchmark/main.aug +17 -0
- package/examples/benchmark/main.aug.md +43 -0
- package/examples/benchmark/main.yaml +1 -0
- package/examples/cli-args/.aug-spec/manifest.json +7 -0
- package/examples/cli-args/main.aug +15 -0
- package/examples/cli-args/main.aug.md +38 -0
- package/examples/collections/.aug-spec/manifest.json +7 -0
- package/examples/collections/main.aug +18 -0
- package/examples/collections/main.aug.md +43 -0
- package/examples/developer-workflow/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/developer-workflow/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/developer-workflow/.aug-spec/manifest.json +13 -0
- package/examples/developer-workflow/calculator.aug +55 -0
- package/examples/developer-workflow/calculator.aug.md +228 -0
- package/examples/developer-workflow/logging/console.aug +8 -0
- package/examples/developer-workflow/logging/console.aug.md +67 -0
- package/examples/developer-workflow/logging/export.aug +2 -0
- package/examples/developer-workflow/logging/export.aug.md +19 -0
- package/examples/developer-workflow/logging/logger.aug +6 -0
- package/examples/developer-workflow/logging/logger.aug.md +57 -0
- package/examples/developer-workflow/main.aug +25 -0
- package/examples/developer-workflow/main.aug.md +79 -0
- package/examples/drop/.aug-spec/manifest.json +8 -0
- package/examples/drop/main.aug +3 -0
- package/examples/drop/main.aug.md +35 -0
- package/examples/drop/resource.aug +8 -0
- package/examples/drop/resource.aug.md +44 -0
- package/examples/errors/.aug-spec/manifest.json +8 -0
- package/examples/errors/errors.aug +6 -0
- package/examples/errors/errors.aug.md +33 -0
- package/examples/errors/main.aug +7 -0
- package/examples/errors/main.aug.md +36 -0
- package/examples/ffi/.aug-spec/manifest.json +8 -0
- package/examples/ffi/main.aug +2 -0
- package/examples/ffi/main.aug.md +27 -0
- package/examples/ffi/native.aug +6 -0
- package/examples/ffi/native.aug.md +43 -0
- package/examples/generic-di/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/generic-di/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/generic-di/.aug-spec/manifest.json +10 -0
- package/examples/generic-di/main.aug +9 -0
- package/examples/generic-di/main.aug.md +49 -0
- package/examples/generic-di/types.aug +17 -0
- package/examples/generic-di/types.aug.md +124 -0
- package/examples/generics/.aug-spec/manifest.json +8 -0
- package/examples/generics/main.aug +9 -0
- package/examples/generics/main.aug.md +58 -0
- package/examples/generics/types.aug +19 -0
- package/examples/generics/types.aug.md +132 -0
- package/examples/hello/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/hello/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/hello/.aug-spec/manifest.json +14 -0
- package/examples/hello/app/export.aug +1 -0
- package/examples/hello/app/export.aug.md +17 -0
- package/examples/hello/app/greeter.aug +22 -0
- package/examples/hello/app/greeter.aug.md +109 -0
- package/examples/hello/logging/console.aug +7 -0
- package/examples/hello/logging/console.aug.md +65 -0
- package/examples/hello/logging/export.aug +2 -0
- package/examples/hello/logging/export.aug.md +19 -0
- package/examples/hello/logging/logger.aug +9 -0
- package/examples/hello/logging/logger.aug.md +59 -0
- package/examples/hello/main.aug +9 -0
- package/examples/hello/main.aug.md +49 -0
- package/examples/interceptors/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/interceptors/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/interceptors/.aug-spec/manifest.json +12 -0
- package/examples/interceptors/app.aug +28 -0
- package/examples/interceptors/app.aug.md +162 -0
- package/examples/interceptors/interceptors.aug +40 -0
- package/examples/interceptors/interceptors.aug.md +180 -0
- package/examples/interceptors/logging.aug +12 -0
- package/examples/interceptors/logging.aug.md +96 -0
- package/examples/interceptors/main.aug +22 -0
- package/examples/interceptors/main.aug.md +76 -0
- package/examples/new-syntax/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/new-syntax/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/new-syntax/.aug-spec/manifest.json +13 -0
- package/examples/new-syntax/console.aug +7 -0
- package/examples/new-syntax/console.aug.md +63 -0
- package/examples/new-syntax/greeter.aug +10 -0
- package/examples/new-syntax/greeter.aug.md +89 -0
- package/examples/new-syntax/logger.aug +6 -0
- package/examples/new-syntax/logger.aug.md +57 -0
- package/examples/new-syntax/main.aug +12 -0
- package/examples/new-syntax/main.aug.md +64 -0
- package/examples/new-syntax/math.aug +3 -0
- package/examples/new-syntax/math.aug.md +29 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/contracts.aug +73 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/contracts.aug.md +791 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/jose.aug +68 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/crypto/jose.aug.md +266 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/json/contracts.aug +6 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/json/contracts.aug.md +55 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/memory/store.aug +45 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/memory/store.aug.md +250 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/time/contracts.aug +11 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/time/contracts.aug.md +96 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/web/contracts.aug +58 -0
- package/examples/oidc-login/.aug-spec/august/0.19.0/web/contracts.aug.md +420 -0
- package/examples/oidc-login/.aug-spec/manifest.json +40 -0
- package/examples/oidc-login/README.md +29 -0
- package/examples/oidc-login/client/contracts.aug +7 -0
- package/examples/oidc-login/client/contracts.aug.md +80 -0
- package/examples/oidc-login/client/endpoints.aug +21 -0
- package/examples/oidc-login/client/endpoints.aug.md +161 -0
- package/examples/oidc-login/client/export.aug +7 -0
- package/examples/oidc-login/client/export.aug.md +29 -0
- package/examples/oidc-login/client/login.aug +58 -0
- package/examples/oidc-login/client/login.aug.md +331 -0
- package/examples/oidc-login/client/logout.aug +18 -0
- package/examples/oidc-login/client/logout.aug.md +150 -0
- package/examples/oidc-login/client/protocol.aug +106 -0
- package/examples/oidc-login/client/protocol.aug.md +326 -0
- package/examples/oidc-login/client/session.aug +34 -0
- package/examples/oidc-login/client/session.aug.md +155 -0
- package/examples/oidc-login/client/views.aug +21 -0
- package/examples/oidc-login/client/views.aug.md +68 -0
- package/examples/oidc-login/common/export.aug +9 -0
- package/examples/oidc-login/common/export.aug.md +33 -0
- package/examples/oidc-login/common/headers.aug +11 -0
- package/examples/oidc-login/common/headers.aug.md +79 -0
- package/examples/oidc-login/common/keys.aug +37 -0
- package/examples/oidc-login/common/keys.aug.md +207 -0
- package/examples/oidc-login/common/settings.aug +4 -0
- package/examples/oidc-login/common/settings.aug.md +47 -0
- package/examples/oidc-login/common/views.aug +16 -0
- package/examples/oidc-login/common/views.aug.md +34 -0
- package/examples/oidc-login/main.aug +39 -0
- package/examples/oidc-login/main.aug.md +166 -0
- package/examples/oidc-login/main.yaml +12 -0
- package/examples/oidc-login/provider/authorization.aug +59 -0
- package/examples/oidc-login/provider/authorization.aug.md +264 -0
- package/examples/oidc-login/provider/contracts.aug +15 -0
- package/examples/oidc-login/provider/contracts.aug.md +193 -0
- package/examples/oidc-login/provider/credentials.aug +10 -0
- package/examples/oidc-login/provider/credentials.aug.md +64 -0
- package/examples/oidc-login/provider/discovery.aug +13 -0
- package/examples/oidc-login/provider/discovery.aug.md +133 -0
- package/examples/oidc-login/provider/export.aug +13 -0
- package/examples/oidc-login/provider/export.aug.md +41 -0
- package/examples/oidc-login/provider/token.aug +37 -0
- package/examples/oidc-login/provider/token.aug.md +223 -0
- package/examples/oidc-login/provider/userinfo.aug +26 -0
- package/examples/oidc-login/provider/userinfo.aug.md +104 -0
- package/examples/oidc-login/provider/views.aug +18 -0
- package/examples/oidc-login/provider/views.aug.md +63 -0
- package/examples/ownership/.aug-spec/manifest.json +8 -0
- package/examples/ownership/counter.aug +14 -0
- package/examples/ownership/counter.aug.md +85 -0
- package/examples/ownership/main.aug +4 -0
- package/examples/ownership/main.aug.md +38 -0
- package/examples/ownership-transfer/.aug-spec/august/0.19.0/io/contracts.aug +36 -0
- package/examples/ownership-transfer/.aug-spec/august/0.19.0/io/contracts.aug.md +316 -0
- package/examples/ownership-transfer/.aug-spec/manifest.json +10 -0
- package/examples/ownership-transfer/main.aug +9 -0
- package/examples/ownership-transfer/main.aug.md +63 -0
- package/examples/ownership-transfer/resource.aug +16 -0
- package/examples/ownership-transfer/resource.aug.md +89 -0
- package/examples/packages/README.md +15 -0
- package/examples/packages/app/.aug-spec/manifest.json +9 -0
- package/examples/packages/app/.aug-spec/packages/@example/aug-math/0.1.0/arithmetic.aug +9 -0
- package/examples/packages/app/.aug-spec/packages/@example/aug-math/0.1.0/arithmetic.aug.md +63 -0
- package/examples/packages/app/main.aug +2 -0
- package/examples/packages/app/main.aug.md +33 -0
- package/examples/packages/app/main.yaml +2 -0
- package/examples/packages/math/.aug-spec/manifest.json +8 -0
- package/examples/packages/math/README.md +3 -0
- package/examples/packages/math/aug-package.json +8 -0
- package/examples/packages/math/package.json +9 -0
- package/examples/packages/math/src/arithmetic.aug +8 -0
- package/examples/packages/math/src/arithmetic.aug.md +63 -0
- package/examples/packages/math/src/export.aug +1 -0
- package/examples/packages/math/src/export.aug.md +17 -0
- package/examples/visibility/.aug-spec/manifest.json +8 -0
- package/examples/visibility/counter.aug +14 -0
- package/examples/visibility/counter.aug.md +87 -0
- package/examples/visibility/main.aug +7 -0
- package/examples/visibility/main.aug.md +39 -0
- package/package.json +50 -0
- package/runtime/aug_crypto.c +121 -0
- package/runtime/aug_html.c +93 -0
- package/runtime/aug_http.c +829 -0
- package/runtime/aug_json.c +165 -0
- package/runtime/aug_runtime.c +792 -0
- package/runtime/aug_runtime.h +245 -0
- package/runtime/aug_tasks.c +172 -0
- package/runtime/aug_time.c +5 -0
- package/runtime/aug_values.c +80 -0
- package/scripts/bootstrap-native.mjs +121 -0
- package/scripts/native-dependencies.lock.json +65 -0
- package/scripts/native-home.mjs +11 -0
- package/src/actions.js +109 -0
- package/src/ast.js +19 -0
- package/src/builtins.js +93 -0
- package/src/checker.js +2896 -0
- package/src/cli.js +344 -0
- package/src/codegen.js +1159 -0
- package/src/config.js +149 -0
- package/src/continuation.js +110 -0
- package/src/di.js +24 -0
- package/src/documentation.js +27 -0
- package/src/editor.js +782 -0
- package/src/effects.js +29 -0
- package/src/fixes.js +222 -0
- package/src/formatter.js +296 -0
- package/src/freshness.js +154 -0
- package/src/help.js +212 -0
- package/src/html.js +27 -0
- package/src/http-policies.js +90 -0
- package/src/inference.js +16 -0
- package/src/interceptors.js +70 -0
- package/src/javadoc.js +67 -0
- package/src/lexer.js +199 -0
- package/src/libraries.js +31 -0
- package/src/lsp.js +180 -0
- package/src/native.js +144 -0
- package/src/navigation.js +162 -0
- package/src/openapi.js +220 -0
- package/src/ownership.js +232 -0
- package/src/package-manager.js +299 -0
- package/src/parser.js +1155 -0
- package/src/policies.js +130 -0
- package/src/project-init.js +19 -0
- package/src/project.js +292 -0
- package/src/schemas.js +62 -0
- package/src/semantic.js +255 -0
- package/src/spec.js +738 -0
- package/src/testing.js +186 -0
- package/src/types.js +10 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/** Lower the checked written order to named entry points. */
|
|
2
|
+
export function interceptorChain(name, layers) {
|
|
3
|
+
return { body: layers.length ? name + '_body' : name,
|
|
4
|
+
entries: layers.map((layer, index) => ({ layer, name: index ? name + '_layer_' + index : name,
|
|
5
|
+
next: index + 1 === layers.length ? name + '_body' : name + '_layer_' + (index + 1) })) };
|
|
6
|
+
}
|
|
7
|
+
/** Conservative delegation facts from syntax, never from comments or text matching. */
|
|
8
|
+
export function interceptorBehavior(body) {
|
|
9
|
+
const contains = (value, predicate) => {
|
|
10
|
+
if (!value || typeof value !== 'object')
|
|
11
|
+
return false;
|
|
12
|
+
if (Array.isArray(value))
|
|
13
|
+
return value.some(child => contains(child, predicate));
|
|
14
|
+
const node = value;
|
|
15
|
+
return predicate(node) || Object.entries(node).some(([key, child]) => key !== 'span' && contains(child, predicate));
|
|
16
|
+
};
|
|
17
|
+
const isNext = (value) => {
|
|
18
|
+
const node = value;
|
|
19
|
+
return node?.kind === 'call' && node.callee.kind === 'name' && node.callee.name === 'next';
|
|
20
|
+
};
|
|
21
|
+
const mayFail = (value) => contains(value, node => node.kind === 'call' || node.kind === 'binary' && node.op === '/');
|
|
22
|
+
const expression = (stmt) => stmt.kind === 'return' ? stmt.value : stmt.kind === 'expr' ? stmt.expr : stmt.kind === 'assign' ? stmt.value : undefined;
|
|
23
|
+
const direct = body.findIndex(stmt => isNext(expression(stmt)));
|
|
24
|
+
const priorMayExit = direct < 0 || body.slice(0, direct).some(stmt => !(stmt.kind === 'assign' && stmt.target.kind === 'name' && !mayFail(stmt.value) ||
|
|
25
|
+
stmt.kind === 'expr' && stmt.expr.kind === 'literal'));
|
|
26
|
+
const call = direct < 0 ? undefined : expression(body[direct]);
|
|
27
|
+
return { delegates: contains(body, isNext), mayShortCircuit: priorMayExit ||
|
|
28
|
+
call?.kind === 'call' && call.args.some(mayFail) || direct < 0 };
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Owns target-to-around mapping, hidden dependency forwarding, and next transfer
|
|
32
|
+
* layout. The native emitter only allocates slots and emits runtime operations.
|
|
33
|
+
*/
|
|
34
|
+
export class InterceptorInvocation {
|
|
35
|
+
layer;
|
|
36
|
+
params;
|
|
37
|
+
original;
|
|
38
|
+
target;
|
|
39
|
+
receiver;
|
|
40
|
+
constructor(layer, params, original, target, receiver) {
|
|
41
|
+
this.layer = layer;
|
|
42
|
+
this.params = params;
|
|
43
|
+
this.original = original;
|
|
44
|
+
this.target = target;
|
|
45
|
+
this.receiver = receiver;
|
|
46
|
+
}
|
|
47
|
+
dependencies() {
|
|
48
|
+
return this.layer.constructorInputIndices.map(index => index >= 0 ? this.original[index] : undefined);
|
|
49
|
+
}
|
|
50
|
+
inputs() {
|
|
51
|
+
return this.layer.around.params.map((param, index) => {
|
|
52
|
+
const target = this.layer.argumentIndices[index];
|
|
53
|
+
const source = target ?? this.layer.argumentInjectionIndices[index];
|
|
54
|
+
return { name: param.name, slot: source !== undefined && source >= 0 ? this.original[source] : undefined,
|
|
55
|
+
reuseOwnedSlot: param.ownership === 'own' && target !== undefined };
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
forward(sourceIndices, values) {
|
|
59
|
+
const args = [...this.original];
|
|
60
|
+
sourceIndices.forEach((source, index) => {
|
|
61
|
+
const target = this.layer.argumentIndices[index];
|
|
62
|
+
if (source !== undefined && target !== undefined)
|
|
63
|
+
args[target] = values[source];
|
|
64
|
+
});
|
|
65
|
+
const transfers = this.params.flatMap((param, index) => param.ownership === 'own' ?
|
|
66
|
+
[{ original: this.original[index], replacement: args[index] }] : []);
|
|
67
|
+
return { args, transfers };
|
|
68
|
+
}
|
|
69
|
+
get around() { return this.layer.around; }
|
|
70
|
+
}
|
package/src/javadoc.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
function inline(text) {
|
|
2
|
+
return text
|
|
3
|
+
.replace(/\{@code\s+([^}]+)\}/g, (_, value) => `\`${value.trim()}\``)
|
|
4
|
+
.replace(/\{@link\s+([^}\s]+)(?:\s+([^}]+))?\}/g, (_, target, label) => `\`${(label ?? target).trim()}\``);
|
|
5
|
+
}
|
|
6
|
+
function format(lines) {
|
|
7
|
+
return inline(lines.join('\n').trim()).replace(/\n{3,}/g, '\n\n');
|
|
8
|
+
}
|
|
9
|
+
/** Read the closest immediately preceding Javadoc block, if there is one. */
|
|
10
|
+
export function javadocBefore(source, offset) {
|
|
11
|
+
let before = source.slice(0, offset);
|
|
12
|
+
// Extern C declarations start their recorded span at the name after the prefix.
|
|
13
|
+
before = before.replace(/\b(?:extern\s+C(?:\s+value)?(?:\s+pure)?|fixture)\s*$/, '');
|
|
14
|
+
const end = before.lastIndexOf('*/');
|
|
15
|
+
if (end < 0 || before.slice(end + 2).trim())
|
|
16
|
+
return undefined;
|
|
17
|
+
const start = before.lastIndexOf('/**', end);
|
|
18
|
+
if (start < 0 || before.slice(start + 3, end).includes('*/'))
|
|
19
|
+
return undefined;
|
|
20
|
+
const raw = before.slice(start + 3, end);
|
|
21
|
+
const lines = raw.split(/\r?\n/).map(line => line.replace(/^\s*\* ?/, '').trimEnd())
|
|
22
|
+
.flatMap(line => line.split(/\s+(?=@(?:param|returns?|throws|exception|deprecated|see)\b)/));
|
|
23
|
+
const description = [];
|
|
24
|
+
const tags = [];
|
|
25
|
+
let current;
|
|
26
|
+
for (const line of lines) {
|
|
27
|
+
const tag = /^@([A-Za-z]+)\b\s*(.*)$/.exec(line);
|
|
28
|
+
if (tag) {
|
|
29
|
+
current = { name: tag[1], value: [tag[2]] };
|
|
30
|
+
tags.push(current);
|
|
31
|
+
}
|
|
32
|
+
else if (current)
|
|
33
|
+
current.value.push(line);
|
|
34
|
+
else
|
|
35
|
+
description.push(line);
|
|
36
|
+
}
|
|
37
|
+
const sections = [format(description)];
|
|
38
|
+
const parameters = new Map();
|
|
39
|
+
const throws = [];
|
|
40
|
+
for (const tag of tags) {
|
|
41
|
+
const value = format(tag.value);
|
|
42
|
+
if (tag.name === 'param') {
|
|
43
|
+
const match = /^([A-Za-z_][A-Za-z0-9_]*)\s*([\s\S]*)$/.exec(value);
|
|
44
|
+
if (match)
|
|
45
|
+
parameters.set(match[1], match[2].trim());
|
|
46
|
+
}
|
|
47
|
+
else if (tag.name === 'return' || tag.name === 'returns') {
|
|
48
|
+
sections.push(`**Returns** ${value}`);
|
|
49
|
+
}
|
|
50
|
+
else if (tag.name === 'throws' || tag.name === 'exception') {
|
|
51
|
+
const match = /^(\S+)\s*([\s\S]*)$/.exec(value);
|
|
52
|
+
if (match)
|
|
53
|
+
throws.push(`- \`${match[1]}\`${match[2] ? `: ${match[2].trim()}` : ''}`);
|
|
54
|
+
}
|
|
55
|
+
else if (tag.name === 'deprecated')
|
|
56
|
+
sections.push(`**Deprecated:** ${value}`);
|
|
57
|
+
else if (tag.name === 'see')
|
|
58
|
+
sections.push(`**See also:** ${value}`);
|
|
59
|
+
}
|
|
60
|
+
if (parameters.size)
|
|
61
|
+
sections.push('**Parameters**\n' +
|
|
62
|
+
[...parameters].map(([name, value]) => `- \`${name}\`${value ? `: ${value}` : ''}`).join('\n'));
|
|
63
|
+
if (throws.length)
|
|
64
|
+
sections.push('**Throws**\n' + throws.join('\n'));
|
|
65
|
+
const markdown = sections.filter(Boolean).join('\n\n');
|
|
66
|
+
return markdown ? { markdown, parameters, tags: tags.map(tag => ({ name: tag.name, value: format(tag.value) })) } : undefined;
|
|
67
|
+
}
|
package/src/lexer.js
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
export const reservedKeywords = [
|
|
2
|
+
'import', 'from', 'export', 'folder', 'bind', 'implement', 'with', 'to', 'class', 'interface',
|
|
3
|
+
'implements', 'extends', 'function', 'returns', 'throws', 'unless', 'return',
|
|
4
|
+
'throw', 'if', 'else', 'while', 'try', 'catch', 'unsafe', 'extern', 'C',
|
|
5
|
+
'resolve', 'own', 'borrow', 'true', 'false', 'null', 'interceptor',
|
|
6
|
+
'and', 'or', 'not', 'initialize', 'everything', 'test', 'when', 'it', 'pass', 'in', 'out', 'changes', 'uses', 'mutable', 'capability',
|
|
7
|
+
'record', 'for', 'match', 'some', 'shared', 'fresh', 'scoped', 'scope', 'composition', 'include', 'fixture',
|
|
8
|
+
'pure',
|
|
9
|
+
'optional', 'missing',
|
|
10
|
+
'freeze', 'as',
|
|
11
|
+
'endpoint', 'serve', 'streams', 'yield', 'handle',
|
|
12
|
+
'start', 'wait',
|
|
13
|
+
'always',
|
|
14
|
+
'lock',
|
|
15
|
+
];
|
|
16
|
+
const keywords = new Set(reservedKeywords);
|
|
17
|
+
export function lex(file, source, comments = false) {
|
|
18
|
+
const tokens = [];
|
|
19
|
+
const diagnostics = [];
|
|
20
|
+
let index = 0;
|
|
21
|
+
let line = 1;
|
|
22
|
+
let column = 1;
|
|
23
|
+
const peek = (offset = 0) => source[index + offset] ?? '';
|
|
24
|
+
const advance = () => {
|
|
25
|
+
const char = source[index++] ?? '';
|
|
26
|
+
if (char === '\n') {
|
|
27
|
+
line++;
|
|
28
|
+
column = 1;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
column++;
|
|
32
|
+
}
|
|
33
|
+
return char;
|
|
34
|
+
};
|
|
35
|
+
const spanAt = (start, startLine, startColumn) => ({ file, start, end: index, line: startLine, column: startColumn });
|
|
36
|
+
const emit = (kind, value, start, startLine, startColumn) => tokens.push({ kind, value, span: spanAt(start, startLine, startColumn), endLine: line });
|
|
37
|
+
const error = (message, startLine, startColumn) => diagnostics.push({ file, line: startLine, column: startColumn, message, code: 'LEX' });
|
|
38
|
+
const markup = [];
|
|
39
|
+
while (index < source.length) {
|
|
40
|
+
const char = peek();
|
|
41
|
+
const mode = markup.at(-1);
|
|
42
|
+
if (mode?.mode === 'text' && char !== '<' && char !== '{') {
|
|
43
|
+
const start = index, startLine = line, startColumn = column;
|
|
44
|
+
while (peek() && peek() !== '<' && peek() !== '{')
|
|
45
|
+
advance();
|
|
46
|
+
emit('jsx_text', source.slice(start, index), start, startLine, startColumn);
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (/\s/.test(char)) {
|
|
50
|
+
advance();
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const start = index;
|
|
54
|
+
const startLine = line;
|
|
55
|
+
const startColumn = column;
|
|
56
|
+
if (mode?.mode === 'text' && char === '<') {
|
|
57
|
+
advance();
|
|
58
|
+
mode.closing = peek() === '/';
|
|
59
|
+
if (mode.closing)
|
|
60
|
+
advance();
|
|
61
|
+
else
|
|
62
|
+
mode.depth++;
|
|
63
|
+
mode.mode = 'tag';
|
|
64
|
+
emit(mode.closing ? 'jsx_close' : 'jsx_open', mode.closing ? '</' : '<', start, startLine, startColumn);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (mode?.mode === 'tag') {
|
|
68
|
+
if (char === '>' || char === '/' && peek(1) === '>') {
|
|
69
|
+
const self = char === '/';
|
|
70
|
+
advance();
|
|
71
|
+
if (self)
|
|
72
|
+
advance();
|
|
73
|
+
if (self || mode.closing)
|
|
74
|
+
mode.depth--;
|
|
75
|
+
emit(self ? 'jsx_self' : mode.closing ? 'jsx_close_end' : 'jsx_end', self ? '/>' : '>', start, startLine, startColumn);
|
|
76
|
+
mode.mode = 'text';
|
|
77
|
+
if (mode.depth === 0)
|
|
78
|
+
markup.pop();
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
if (/[A-Za-z_]/.test(char)) {
|
|
82
|
+
let value = '';
|
|
83
|
+
while (/[A-Za-z0-9_:-]/.test(peek()))
|
|
84
|
+
value += advance();
|
|
85
|
+
emit('jsx_name', value, start, startLine, startColumn);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (mode && mode.mode !== 'expression' && char === '{') {
|
|
90
|
+
mode.resume = mode.mode;
|
|
91
|
+
mode.mode = 'expression';
|
|
92
|
+
mode.braces = 0;
|
|
93
|
+
}
|
|
94
|
+
if (char === '<' && (/[A-Za-z_]/.test(peek(1)) || peek(1) === '>') &&
|
|
95
|
+
(!tokens.length || ['return', '=', 'to', '(', ',', '[', '{', ':', 'yield'].includes(tokens.at(-1).kind))) {
|
|
96
|
+
advance();
|
|
97
|
+
markup.push({ mode: 'tag', braces: 0, depth: 1, closing: false });
|
|
98
|
+
emit('jsx_open', '<', start, startLine, startColumn);
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
if (mode?.mode === 'expression') {
|
|
102
|
+
if (char === '{')
|
|
103
|
+
mode.braces++;
|
|
104
|
+
if (char === '}' && --mode.braces === 0) {
|
|
105
|
+
mode.mode = mode.resume;
|
|
106
|
+
mode.resume = undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (char === '#' || (char === '/' && peek(1) === '/')) {
|
|
110
|
+
while (peek() && peek() !== '\n')
|
|
111
|
+
advance();
|
|
112
|
+
if (comments)
|
|
113
|
+
emit('comment', source.slice(start, index), start, startLine, startColumn);
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (char === '/' && peek(1) === '*') {
|
|
117
|
+
advance();
|
|
118
|
+
advance();
|
|
119
|
+
while (peek() && !(peek() === '*' && peek(1) === '/'))
|
|
120
|
+
advance();
|
|
121
|
+
if (!peek())
|
|
122
|
+
error('Unterminated block comment', startLine, startColumn);
|
|
123
|
+
else {
|
|
124
|
+
advance();
|
|
125
|
+
advance();
|
|
126
|
+
}
|
|
127
|
+
if (comments)
|
|
128
|
+
emit('comment', source.slice(start, index), start, startLine, startColumn);
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (/[A-Za-z_]/.test(char)) {
|
|
132
|
+
let value = '';
|
|
133
|
+
while (/[A-Za-z0-9_]/.test(peek()))
|
|
134
|
+
value += advance();
|
|
135
|
+
emit(keywords.has(value) ? value : 'identifier', value, start, startLine, startColumn);
|
|
136
|
+
if (value === 'missing')
|
|
137
|
+
diagnostics.push({ file, line: startLine, column: startColumn, code: 'SYNTAX', message: 'Use null instead of missing; optional values have only a value or null' });
|
|
138
|
+
continue;
|
|
139
|
+
}
|
|
140
|
+
if (/[0-9]/.test(char)) {
|
|
141
|
+
let value = '';
|
|
142
|
+
while (/[0-9]/.test(peek()))
|
|
143
|
+
value += advance();
|
|
144
|
+
if (peek() === '.' && /[0-9]/.test(peek(1))) {
|
|
145
|
+
value += advance();
|
|
146
|
+
while (/[0-9]/.test(peek()))
|
|
147
|
+
value += advance();
|
|
148
|
+
}
|
|
149
|
+
emit('number', value, start, startLine, startColumn);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (char === '"' || char === "'") {
|
|
153
|
+
const quote = advance();
|
|
154
|
+
let value = '';
|
|
155
|
+
let closed = false;
|
|
156
|
+
while (peek()) {
|
|
157
|
+
if (peek() === quote) {
|
|
158
|
+
advance();
|
|
159
|
+
closed = true;
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
if (peek() === '\\') {
|
|
163
|
+
advance();
|
|
164
|
+
const escape = advance();
|
|
165
|
+
value += { n: '\n', r: '\r', t: '\t', '0': '\0', '\\': '\\', '"': '"', "'": "'" }[escape] ?? escape;
|
|
166
|
+
}
|
|
167
|
+
else
|
|
168
|
+
value += advance();
|
|
169
|
+
}
|
|
170
|
+
if (!closed)
|
|
171
|
+
error('Unterminated string literal', startLine, startColumn);
|
|
172
|
+
emit('string', value, start, startLine, startColumn);
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
const two = char + peek(1);
|
|
176
|
+
if (['==', '!=', '<=', '>=', '&&', '||', '->', '=>'].includes(two)) {
|
|
177
|
+
if (['&&', '||', '=>'].includes(two))
|
|
178
|
+
diagnostics.push({ file, line: startLine, column: startColumn, code: 'SYNTAX',
|
|
179
|
+
message: two === '=>' ? 'Use an initialize block inside the class or record instead of =>'
|
|
180
|
+
: `Use ${two === '&&' ? 'and' : 'or'} instead of ${two}; boolean operators use words` });
|
|
181
|
+
advance();
|
|
182
|
+
advance();
|
|
183
|
+
emit(two, two, start, startLine, startColumn);
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
if ('{}();,.:<>?=+-*/![]'.includes(char)) {
|
|
187
|
+
if (char === '!')
|
|
188
|
+
diagnostics.push({ file, line: startLine, column: startColumn, code: 'SYNTAX',
|
|
189
|
+
message: 'Use not instead of !; boolean operators use words' });
|
|
190
|
+
advance();
|
|
191
|
+
emit(char, char, start, startLine, startColumn);
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
advance();
|
|
195
|
+
error(`Unexpected character ${JSON.stringify(char)}`, startLine, startColumn);
|
|
196
|
+
}
|
|
197
|
+
tokens.push({ kind: 'eof', value: '', span: { file, start: index, end: index, line, column }, endLine: line });
|
|
198
|
+
return { tokens, diagnostics };
|
|
199
|
+
}
|
package/src/libraries.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
import { dirname, join, relative } from 'node:path';
|
|
4
|
+
/** The checked-in sources and installed packages expose the same August module paths. */
|
|
5
|
+
export function standardLibraries() {
|
|
6
|
+
const bundled = join(import.meta.dirname, 'stdlib');
|
|
7
|
+
if (existsSync(bundled))
|
|
8
|
+
return { root: bundled, modules: new Map() };
|
|
9
|
+
const require = createRequire(import.meta.url);
|
|
10
|
+
const version = JSON.parse(readFileSync(join(import.meta.dirname, '..', 'package.json'), 'utf8')).version;
|
|
11
|
+
const load = (name) => {
|
|
12
|
+
const file = require.resolve(`@greenpandastudios/aug-${name}/aug-package.json`);
|
|
13
|
+
const manifest = JSON.parse(readFileSync(file, 'utf8'));
|
|
14
|
+
if (manifest.format !== 1 || manifest.version !== version || manifest.compiler !== version)
|
|
15
|
+
throw new Error(`August ${name} must match compiler ${version}; reinstall the CLI and its pinned libraries.`);
|
|
16
|
+
return join(dirname(file), manifest.source);
|
|
17
|
+
};
|
|
18
|
+
return { root: load('stdlib'), modules: new Map([['web', load('web')], ['crypto', load('crypto')]]) };
|
|
19
|
+
}
|
|
20
|
+
export function libraryChild(libraries, folder, name) {
|
|
21
|
+
return folder === libraries.root ? libraries.modules.get(name) ?? join(folder, name) : join(folder, name);
|
|
22
|
+
}
|
|
23
|
+
/** Stable identities and import suggestions are independent of npm's disk layout. */
|
|
24
|
+
export function libraryRelative(libraries, file) {
|
|
25
|
+
for (const [name, folder] of libraries.modules) {
|
|
26
|
+
const path = relative(folder, file);
|
|
27
|
+
if (path === '' || (!path.startsWith('..') && !path.startsWith('/')))
|
|
28
|
+
return join(name, path);
|
|
29
|
+
}
|
|
30
|
+
return relative(libraries.root, file);
|
|
31
|
+
}
|
package/src/lsp.js
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
2
|
+
import { SemanticWorkspace } from "./semantic.js";
|
|
3
|
+
import { diagnosticHelp } from "./help.js";
|
|
4
|
+
import { compilerVersion } from "./package-manager.js";
|
|
5
|
+
const tokenTypes = ['class', 'interface', 'function', 'method', 'property', 'variable', 'parameter', 'type', 'keyword', 'decorator', 'typeParameter'];
|
|
6
|
+
const offsetAt = (source, position) => source.split('\n').slice(0, position.line).reduce((offset, line) => offset + line.length + 1, 0) + position.character;
|
|
7
|
+
const positionAt = (source, offset) => {
|
|
8
|
+
const lines = source.slice(0, offset).split('\n');
|
|
9
|
+
return { line: lines.length - 1, character: lines.at(-1).length };
|
|
10
|
+
};
|
|
11
|
+
/** LSP 3.17, full-text synchronization and immutable cached semantic revisions. */
|
|
12
|
+
export async function runLanguageServer(root) {
|
|
13
|
+
const workspace = new SemanticWorkspace(root);
|
|
14
|
+
const open = new Map();
|
|
15
|
+
const cancelled = new Set();
|
|
16
|
+
const send = (message) => { const data = Buffer.from(JSON.stringify(message)); process.stdout.write(`Content-Length: ${data.length}\r\n\r\n`); process.stdout.write(data); };
|
|
17
|
+
const document = (uri) => workspace.document(fileURLToPath(uri), open.get(uri));
|
|
18
|
+
const publish = () => {
|
|
19
|
+
for (const [uri, edit] of open) {
|
|
20
|
+
const view = document(uri);
|
|
21
|
+
send({ jsonrpc: '2.0', method: 'textDocument/publishDiagnostics', params: { uri, version: edit.version,
|
|
22
|
+
diagnostics: view.diagnostics.filter(issue => issue.file === fileURLToPath(uri)).map(issue => ({
|
|
23
|
+
range: { start: { line: issue.line - 1, character: issue.column - 1 }, end: { line: issue.line - 1, character: issue.column } },
|
|
24
|
+
message: issue.message, severity: issue.severity === 'warning' ? 2 : 1, code: issue.code, source: 'AugScript',
|
|
25
|
+
data: { help: diagnosticHelp[issue.code] }
|
|
26
|
+
})) } });
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
let publishTimer;
|
|
30
|
+
const schedule = () => { if (publishTimer)
|
|
31
|
+
clearTimeout(publishTimer); publishTimer = setTimeout(() => { try {
|
|
32
|
+
publish();
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
process.stderr.write(String(error) + '\n');
|
|
36
|
+
} }, 75); };
|
|
37
|
+
let shutdown = false;
|
|
38
|
+
const handle = (message) => {
|
|
39
|
+
const params = message.params ?? {};
|
|
40
|
+
let result = null;
|
|
41
|
+
if (message.method === '$/cancelRequest') {
|
|
42
|
+
cancelled.add(params.id);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (message.id !== undefined && cancelled.delete(message.id)) {
|
|
46
|
+
send({ jsonrpc: '2.0', id: message.id, error: { code: -32800, message: 'Request cancelled' } });
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (message.method === 'initialize')
|
|
50
|
+
result = { capabilities: {
|
|
51
|
+
textDocumentSync: { openClose: true, change: 1 }, hoverProvider: true, completionProvider: { triggerCharacters: ['.', '(', '=', ' '] },
|
|
52
|
+
definitionProvider: true, documentFormattingProvider: true, codeActionProvider: true,
|
|
53
|
+
semanticTokensProvider: { legend: { tokenTypes, tokenModifiers: ['declaration'] }, full: true },
|
|
54
|
+
}, serverInfo: { name: 'AugScript', version: compilerVersion() } };
|
|
55
|
+
else if (message.method === 'shutdown')
|
|
56
|
+
shutdown = true;
|
|
57
|
+
else if (message.method === 'exit') {
|
|
58
|
+
process.exitCode = shutdown ? 0 : 1;
|
|
59
|
+
process.stdin.destroy();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
else if (message.method === 'textDocument/didOpen') {
|
|
63
|
+
const doc = params.textDocument;
|
|
64
|
+
open.set(doc.uri, { text: doc.text, version: doc.version });
|
|
65
|
+
workspace.document(fileURLToPath(doc.uri), open.get(doc.uri));
|
|
66
|
+
schedule();
|
|
67
|
+
}
|
|
68
|
+
else if (message.method === 'textDocument/didChange') {
|
|
69
|
+
const doc = params.textDocument, previous = open.get(doc.uri);
|
|
70
|
+
if (!previous || doc.version > previous.version) {
|
|
71
|
+
open.set(doc.uri, { text: params.contentChanges.at(-1).text, version: doc.version });
|
|
72
|
+
workspace.document(fileURLToPath(doc.uri), open.get(doc.uri));
|
|
73
|
+
schedule();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else if (message.method === 'textDocument/didClose') {
|
|
77
|
+
open.delete(params.textDocument.uri);
|
|
78
|
+
workspace.close(fileURLToPath(params.textDocument.uri));
|
|
79
|
+
send({ jsonrpc: '2.0', method: 'textDocument/publishDiagnostics', params: { uri: params.textDocument.uri, diagnostics: [] } });
|
|
80
|
+
}
|
|
81
|
+
else if (message.method === 'workspace/didChangeWatchedFiles')
|
|
82
|
+
schedule();
|
|
83
|
+
else if (message.method === 'aug/stats')
|
|
84
|
+
result = { ...workspace.stats };
|
|
85
|
+
else if (message.method === 'aug/editor') {
|
|
86
|
+
const uri = params.uri;
|
|
87
|
+
if (params.text !== undefined) {
|
|
88
|
+
const previous = open.get(uri);
|
|
89
|
+
if (!previous || params.version >= previous.version)
|
|
90
|
+
open.set(uri, { text: params.text, version: params.version });
|
|
91
|
+
}
|
|
92
|
+
const view = document(uri), offset = params.offset ?? 0;
|
|
93
|
+
result = params.command === 'hover' ? view.hover(offset) ?? null : params.command === 'complete' ? view.complete(offset) :
|
|
94
|
+
params.command === 'fixes' ? view.fixes() : params.command === 'semantic-tokens' ? view.tokens() :
|
|
95
|
+
params.command === 'format' ? view.format() : params.command === 'definition' ? view.definition(offset) ?? null : params.command === 'diagnostics' ? view.diagnostics.map(issue => ({ ...issue, help: diagnosticHelp[issue.code] })) : view.describe(params.options);
|
|
96
|
+
}
|
|
97
|
+
else if (message.method.startsWith('textDocument/')) {
|
|
98
|
+
const view = document(params.textDocument.uri);
|
|
99
|
+
const offset = params.position ? offsetAt(view.source, params.position) : 0;
|
|
100
|
+
if (message.method === 'textDocument/hover') {
|
|
101
|
+
const hover = view.hover(offset);
|
|
102
|
+
result = hover ? { contents: { kind: 'markdown', value: `\`\`\`augscript\n${hover.detail}\n\`\`\`\n\n${hover.documentation ?? ''}` } } : null;
|
|
103
|
+
}
|
|
104
|
+
else if (message.method === 'textDocument/completion')
|
|
105
|
+
result = view.complete(offset).map(item => ({ label: item.label,
|
|
106
|
+
kind: { method: 2, function: 3, variable: 6, class: 7, interface: 8, property: 10, keyword: 14, snippet: 15, type: 25 }[item.kind] ?? 6,
|
|
107
|
+
detail: item.detail, documentation: { kind: 'markdown', value: item.documentation ?? '' }, insertText: item.insertText ?? item.label,
|
|
108
|
+
insertTextFormat: item.kind === 'snippet' ? 2 : 1 }));
|
|
109
|
+
else if (message.method === 'textDocument/definition') {
|
|
110
|
+
const target = view.definition(offset);
|
|
111
|
+
result = target ? { uri: pathToFileURL(target.file).href,
|
|
112
|
+
range: { start: { line: target.line - 1, character: target.column - 1 }, end: { line: target.line - 1, character: target.column } } } : null;
|
|
113
|
+
}
|
|
114
|
+
else if (message.method === 'textDocument/formatting')
|
|
115
|
+
result = [{ range: { start: { line: 0, character: 0 }, end: positionAt(view.source, view.source.length) }, newText: view.format() }];
|
|
116
|
+
else if (message.method === 'textDocument/codeAction')
|
|
117
|
+
result = view.fixes().map(fix => {
|
|
118
|
+
const changes = {};
|
|
119
|
+
for (const edit of fix.edits) {
|
|
120
|
+
const source = workspace.document(edit.file).source, uri = pathToFileURL(edit.file).href;
|
|
121
|
+
(changes[uri] ??= []).push({ range: { start: positionAt(source, edit.start), end: positionAt(source, edit.end) }, newText: edit.text });
|
|
122
|
+
}
|
|
123
|
+
return { title: fix.title, kind: 'quickfix', edit: { changes } };
|
|
124
|
+
});
|
|
125
|
+
else if (message.method === 'textDocument/semanticTokens/full') {
|
|
126
|
+
let line = 0, column = 0;
|
|
127
|
+
const data = [];
|
|
128
|
+
for (const token of view.tokens().sort((a, b) => a.line - b.line || a.start - b.start)) {
|
|
129
|
+
data.push(token.line - line, token.line === line ? token.start - column : token.start, token.length, tokenTypes.indexOf(token.type), token.declaration ? 1 : 0);
|
|
130
|
+
line = token.line;
|
|
131
|
+
column = token.start;
|
|
132
|
+
}
|
|
133
|
+
result = { data, resultId: view.revision };
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
else if (message.id !== undefined) {
|
|
137
|
+
send({ jsonrpc: '2.0', id: message.id, error: { code: -32601, message: `Unsupported method ${message.method}` } });
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
if (message.id !== undefined)
|
|
141
|
+
send({ jsonrpc: '2.0', id: message.id, result });
|
|
142
|
+
};
|
|
143
|
+
let buffer = Buffer.alloc(0);
|
|
144
|
+
await new Promise(resolve => {
|
|
145
|
+
process.stdin.on('data', chunk => {
|
|
146
|
+
buffer = Buffer.concat([buffer, chunk]);
|
|
147
|
+
while (true) {
|
|
148
|
+
const headerEnd = buffer.indexOf('\r\n\r\n');
|
|
149
|
+
if (headerEnd < 0)
|
|
150
|
+
break;
|
|
151
|
+
const length = Number(/Content-Length:\s*(\d+)/i.exec(buffer.subarray(0, headerEnd).toString())?.[1]);
|
|
152
|
+
if (!Number.isSafeInteger(length) || length < 0 || length > 16 * 1024 * 1024) {
|
|
153
|
+
process.stderr.write('Invalid LSP frame\n');
|
|
154
|
+
process.stdin.destroy();
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
if (buffer.length < headerEnd + 4 + length)
|
|
158
|
+
break;
|
|
159
|
+
const payload = buffer.subarray(headerEnd + 4, headerEnd + 4 + length);
|
|
160
|
+
buffer = buffer.subarray(headerEnd + 4 + length);
|
|
161
|
+
let message;
|
|
162
|
+
try {
|
|
163
|
+
message = JSON.parse(payload.toString('utf8'));
|
|
164
|
+
handle(message);
|
|
165
|
+
}
|
|
166
|
+
catch (error) {
|
|
167
|
+
if (message?.id !== undefined)
|
|
168
|
+
send({ jsonrpc: '2.0', id: message.id, error: { code: -32603, message: String(error) } });
|
|
169
|
+
else
|
|
170
|
+
process.stderr.write(String(error) + '\n');
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
process.stdin.on('close', resolve);
|
|
175
|
+
process.stdin.on('end', resolve);
|
|
176
|
+
});
|
|
177
|
+
if (publishTimer)
|
|
178
|
+
clearTimeout(publishTimer);
|
|
179
|
+
return process.exitCode === 1 ? 1 : 0;
|
|
180
|
+
}
|