@hydranium/core 1.0.0-next.10 → 1.0.0-next.104
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/lib/documents/ast-document-manager.d.ts +75 -16
- package/lib/documents/ast-document-manager.d.ts.map +1 -1
- package/lib/documents/ast-document-manager.js +57 -19
- package/lib/documents/ast-document-manager.js.map +1 -1
- package/lib/documents/client-ids.d.ts +5 -19
- package/lib/documents/client-ids.d.ts.map +1 -1
- package/lib/documents/client-ids.js +5 -19
- package/lib/documents/client-ids.js.map +1 -1
- package/lib/documents/hydranium-text-documents.d.ts +124 -36
- package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
- package/lib/documents/hydranium-text-documents.js +191 -51
- package/lib/documents/hydranium-text-documents.js.map +1 -1
- package/lib/documents/language-client-text-shadow.d.ts +41 -9
- package/lib/documents/language-client-text-shadow.d.ts.map +1 -1
- package/lib/documents/language-client-text-shadow.js +56 -11
- package/lib/documents/language-client-text-shadow.js.map +1 -1
- package/lib/documents/self-save-registry.d.ts +37 -6
- package/lib/documents/self-save-registry.d.ts.map +1 -1
- package/lib/documents/self-save-registry.js +28 -15
- package/lib/documents/self-save-registry.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -1
- package/lib/langium/ast-extension/ast-node-builder.d.ts +32 -9
- package/lib/langium/ast-extension/ast-node-builder.d.ts.map +1 -1
- package/lib/langium/ast-extension/ast-node-builder.js +60 -22
- package/lib/langium/ast-extension/ast-node-builder.js.map +1 -1
- package/lib/langium/bootstrap.d.ts.map +1 -1
- package/lib/langium/bootstrap.js +16 -9
- package/lib/langium/bootstrap.js.map +1 -1
- package/lib/langium/config/configuration-provider.d.ts +81 -0
- package/lib/langium/config/configuration-provider.d.ts.map +1 -0
- package/lib/langium/config/configuration-provider.js +112 -0
- package/lib/langium/config/configuration-provider.js.map +1 -0
- package/lib/langium/config/index.d.ts +1 -0
- package/lib/langium/config/index.d.ts.map +1 -1
- package/lib/langium/config/index.js +1 -0
- package/lib/langium/config/index.js.map +1 -1
- package/lib/langium/diagnostics/lsp-logger.d.ts +17 -0
- package/lib/langium/diagnostics/lsp-logger.d.ts.map +1 -1
- package/lib/langium/diagnostics/lsp-logger.js +40 -6
- package/lib/langium/diagnostics/lsp-logger.js.map +1 -1
- package/lib/langium/document-builder/build-pipeline-integration.d.ts +21 -1
- package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
- package/lib/langium/document-builder/build-pipeline-integration.js +32 -5
- package/lib/langium/document-builder/build-pipeline-integration.js.map +1 -1
- package/lib/langium/document-builder/build-session.d.ts +93 -0
- package/lib/langium/document-builder/build-session.d.ts.map +1 -0
- package/lib/langium/document-builder/build-session.js +72 -0
- package/lib/langium/document-builder/build-session.js.map +1 -0
- package/lib/langium/document-builder/document-builder.d.ts +150 -7
- package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
- package/lib/langium/document-builder/document-builder.js +298 -11
- package/lib/langium/document-builder/document-builder.js.map +1 -1
- package/lib/langium/document-builder/index.d.ts +1 -0
- package/lib/langium/document-builder/index.d.ts.map +1 -1
- package/lib/langium/document-builder/index.js +1 -0
- package/lib/langium/document-builder/index.js.map +1 -1
- package/lib/langium/integration-services.d.ts +45 -1
- package/lib/langium/integration-services.d.ts.map +1 -1
- package/lib/langium/integration-services.js +10 -5
- package/lib/langium/integration-services.js.map +1 -1
- package/lib/langium/integrity/integrity-service.d.ts +16 -0
- package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
- package/lib/langium/integrity/integrity-service.js +110 -2
- package/lib/langium/integrity/integrity-service.js.map +1 -1
- package/lib/langium/keys/containment.d.ts +64 -0
- package/lib/langium/keys/containment.d.ts.map +1 -0
- package/lib/langium/keys/containment.js +53 -0
- package/lib/langium/keys/containment.js.map +1 -0
- package/lib/langium/keys/index.d.ts +1 -0
- package/lib/langium/keys/index.d.ts.map +1 -1
- package/lib/langium/keys/index.js +1 -0
- package/lib/langium/keys/index.js.map +1 -1
- package/lib/langium/keys/name-based-key-provider.d.ts +4 -0
- package/lib/langium/keys/name-based-key-provider.d.ts.map +1 -1
- package/lib/langium/keys/name-based-key-provider.js +4 -0
- package/lib/langium/keys/name-based-key-provider.js.map +1 -1
- package/lib/langium/language-module.d.ts +25 -0
- package/lib/langium/language-module.d.ts.map +1 -1
- package/lib/langium/language-module.js +14 -0
- package/lib/langium/language-module.js.map +1 -1
- package/lib/langium/model-service/model-service.d.ts +161 -10
- package/lib/langium/model-service/model-service.d.ts.map +1 -1
- package/lib/langium/model-service/model-service.js +174 -95
- package/lib/langium/model-service/model-service.js.map +1 -1
- package/lib/langium/module.d.ts +84 -15
- package/lib/langium/module.d.ts.map +1 -1
- package/lib/langium/module.js +26 -12
- package/lib/langium/module.js.map +1 -1
- package/lib/langium/naming/name-provider.d.ts +25 -4
- package/lib/langium/naming/name-provider.d.ts.map +1 -1
- package/lib/langium/naming/name-provider.js +2 -1
- package/lib/langium/naming/name-provider.js.map +1 -1
- package/lib/langium/naming/name-separator-validation.d.ts +23 -0
- package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
- package/lib/langium/naming/name-separator-validation.js +30 -1
- package/lib/langium/naming/name-separator-validation.js.map +1 -1
- package/lib/langium/residency/cst-residency-service.d.ts +31 -11
- package/lib/langium/residency/cst-residency-service.d.ts.map +1 -1
- package/lib/langium/residency/cst-residency-service.js +13 -56
- package/lib/langium/residency/cst-residency-service.js.map +1 -1
- package/lib/langium/scope/hydranium-scope-provider.d.ts +48 -13
- package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
- package/lib/langium/scope/hydranium-scope-provider.js +56 -20
- package/lib/langium/scope/hydranium-scope-provider.js.map +1 -1
- package/lib/langium/serialization/abstract-serializer.d.ts +11 -20
- package/lib/langium/serialization/abstract-serializer.d.ts.map +1 -1
- package/lib/langium/serialization/abstract-serializer.js +12 -21
- package/lib/langium/serialization/abstract-serializer.js.map +1 -1
- package/lib/langium/service-registry.d.ts +15 -1
- package/lib/langium/service-registry.d.ts.map +1 -1
- package/lib/langium/service-registry.js +16 -0
- package/lib/langium/service-registry.js.map +1 -1
- package/lib/langium/shared-services.d.ts +15 -2
- package/lib/langium/shared-services.d.ts.map +1 -1
- package/lib/langium/shared-services.js.map +1 -1
- package/lib/langium/transfer/transfer-encoder.d.ts +60 -17
- package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
- package/lib/langium/transfer/transfer-encoder.js +38 -16
- package/lib/langium/transfer/transfer-encoder.js.map +1 -1
- package/lib/langium/trivia/comment-preserver.d.ts +423 -0
- package/lib/langium/trivia/comment-preserver.d.ts.map +1 -0
- package/lib/langium/trivia/comment-preserver.js +906 -0
- package/lib/langium/trivia/comment-preserver.js.map +1 -0
- package/lib/langium/trivia/document-ending-preserver.d.ts +43 -0
- package/lib/langium/trivia/document-ending-preserver.d.ts.map +1 -0
- package/lib/langium/trivia/document-ending-preserver.js +48 -0
- package/lib/langium/trivia/document-ending-preserver.js.map +1 -0
- package/lib/langium/trivia/index.d.ts +14 -0
- package/lib/langium/trivia/index.d.ts.map +1 -0
- package/lib/langium/trivia/index.js +14 -0
- package/lib/langium/trivia/index.js.map +1 -0
- package/lib/langium/trivia/trivia-contribution.d.ts +37 -0
- package/lib/langium/trivia/trivia-contribution.d.ts.map +1 -0
- package/lib/langium/trivia/trivia-contribution.js +10 -0
- package/lib/langium/trivia/trivia-contribution.js.map +1 -0
- package/lib/langium/trivia/trivia-preserver.d.ts +50 -0
- package/lib/langium/trivia/trivia-preserver.d.ts.map +1 -0
- package/lib/langium/trivia/trivia-preserver.js +10 -0
- package/lib/langium/trivia/trivia-preserver.js.map +1 -0
- package/lib/langium/trivia/trivia-service.d.ts +70 -0
- package/lib/langium/trivia/trivia-service.d.ts.map +1 -0
- package/lib/langium/trivia/trivia-service.js +56 -0
- package/lib/langium/trivia/trivia-service.js.map +1 -0
- package/lib/langium/validation/document-validator.d.ts +294 -10
- package/lib/langium/validation/document-validator.d.ts.map +1 -1
- package/lib/langium/validation/document-validator.js +448 -5
- package/lib/langium/validation/document-validator.js.map +1 -1
- package/lib/langium/workspace/document-uri-policy.d.ts +3 -4
- package/lib/langium/workspace/document-uri-policy.d.ts.map +1 -1
- package/lib/langium/workspace/document-uri-policy.js +3 -4
- package/lib/langium/workspace/document-uri-policy.js.map +1 -1
- package/lib/langium/workspace/file-system-provider.d.ts +9 -1
- package/lib/langium/workspace/file-system-provider.d.ts.map +1 -1
- package/lib/langium/workspace/file-system-provider.js +40 -7
- package/lib/langium/workspace/file-system-provider.js.map +1 -1
- package/lib/langium/workspace/hydranium-langium-document-factory.d.ts +25 -0
- package/lib/langium/workspace/hydranium-langium-document-factory.d.ts.map +1 -1
- package/lib/langium/workspace/hydranium-langium-document-factory.js +25 -0
- package/lib/langium/workspace/hydranium-langium-document-factory.js.map +1 -1
- package/lib/langium/workspace/hydranium-workspace-manager.d.ts +21 -1
- package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
- package/lib/langium/workspace/hydranium-workspace-manager.js +28 -0
- package/lib/langium/workspace/hydranium-workspace-manager.js.map +1 -1
- package/lib/langium/workspace/in-memory-file-system-provider.d.ts +23 -0
- package/lib/langium/workspace/in-memory-file-system-provider.d.ts.map +1 -1
- package/lib/langium/workspace/in-memory-file-system-provider.js +47 -9
- package/lib/langium/workspace/in-memory-file-system-provider.js.map +1 -1
- package/lib/langium/workspace/initialize-workspace.d.ts +22 -2
- package/lib/langium/workspace/initialize-workspace.d.ts.map +1 -1
- package/lib/langium/workspace/initialize-workspace.js +13 -5
- package/lib/langium/workspace/initialize-workspace.js.map +1 -1
- package/lib/langium/workspace/langium-documents.d.ts +79 -17
- package/lib/langium/workspace/langium-documents.d.ts.map +1 -1
- package/lib/langium/workspace/langium-documents.js +83 -28
- package/lib/langium/workspace/langium-documents.js.map +1 -1
- package/lib/langium/workspace/virtual-document.d.ts +18 -3
- package/lib/langium/workspace/virtual-document.d.ts.map +1 -1
- package/lib/langium/workspace/virtual-document.js +19 -2
- package/lib/langium/workspace/virtual-document.js.map +1 -1
- package/lib/locale/index.d.ts +10 -0
- package/lib/locale/index.d.ts.map +1 -0
- package/lib/locale/index.js +10 -0
- package/lib/locale/index.js.map +1 -0
- package/lib/locale/server-locale.d.ts +73 -0
- package/lib/locale/server-locale.d.ts.map +1 -0
- package/lib/locale/server-locale.js +61 -0
- package/lib/locale/server-locale.js.map +1 -0
- package/lib/lsp/hydranium-document-update-handler.js +1 -1
- package/lib/lsp/hydranium-document-update-handler.js.map +1 -1
- package/lib/lsp/index.d.ts +1 -1
- package/lib/lsp/index.d.ts.map +1 -1
- package/lib/lsp/index.js +1 -1
- package/lib/lsp/index.js.map +1 -1
- package/lib/lsp/lsp-latency.d.ts +39 -0
- package/lib/lsp/lsp-latency.d.ts.map +1 -0
- package/lib/lsp/lsp-latency.js +58 -0
- package/lib/lsp/lsp-latency.js.map +1 -0
- package/lib/lsp/semantic-token-provider.d.ts +34 -1
- package/lib/lsp/semantic-token-provider.d.ts.map +1 -1
- package/lib/lsp/semantic-token-provider.js +55 -8
- package/lib/lsp/semantic-token-provider.js.map +1 -1
- package/lib/messages/carriers.d.ts +54 -0
- package/lib/messages/carriers.d.ts.map +1 -0
- package/lib/messages/carriers.js +62 -0
- package/lib/messages/carriers.js.map +1 -0
- package/lib/messages/index.d.ts +25 -0
- package/lib/messages/index.d.ts.map +1 -0
- package/lib/messages/index.js +25 -0
- package/lib/messages/index.js.map +1 -0
- package/lib/messages/renderer.d.ts +136 -0
- package/lib/messages/renderer.d.ts.map +1 -0
- package/lib/messages/renderer.js +159 -0
- package/lib/messages/renderer.js.map +1 -0
- package/lib/node/heap-ceiling.d.ts +61 -0
- package/lib/node/heap-ceiling.d.ts.map +1 -0
- package/lib/node/heap-ceiling.js +72 -0
- package/lib/node/heap-ceiling.js.map +1 -0
- package/lib/node/index.d.ts +1 -0
- package/lib/node/index.d.ts.map +1 -1
- package/lib/node/index.js +1 -0
- package/lib/node/index.js.map +1 -1
- package/lib/node/latency-from-env.d.ts +1 -1
- package/lib/node/latency-from-env.js +1 -1
- package/lib/node/node-file-system-provider.d.ts +35 -1
- package/lib/node/node-file-system-provider.d.ts.map +1 -1
- package/lib/node/node-file-system-provider.js +140 -45
- package/lib/node/node-file-system-provider.js.map +1 -1
- package/lib/node/profile-capture.d.ts +8 -2
- package/lib/node/profile-capture.d.ts.map +1 -1
- package/lib/node/profile-capture.js.map +1 -1
- package/lib/node/profiling-run.d.ts +2 -2
- package/lib/node/profiling-run.js +1 -1
- package/lib/node/profiling-run.js.map +1 -1
- package/lib/node/rename-over-open-readers.d.ts +52 -0
- package/lib/node/rename-over-open-readers.d.ts.map +1 -0
- package/lib/node/rename-over-open-readers.js +66 -0
- package/lib/node/rename-over-open-readers.js.map +1 -0
- package/lib/node/socket-launcher.d.ts +15 -0
- package/lib/node/socket-launcher.d.ts.map +1 -1
- package/lib/node/socket-launcher.js +3 -2
- package/lib/node/socket-launcher.js.map +1 -1
- package/lib/testing/fake-document.d.ts +16 -4
- package/lib/testing/fake-document.d.ts.map +1 -1
- package/lib/testing/fake-document.js +18 -3
- package/lib/testing/fake-document.js.map +1 -1
- package/lib/testing/make-noop-shared-services.d.ts +14 -0
- package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
- package/lib/testing/make-noop-shared-services.js +28 -2
- package/lib/testing/make-noop-shared-services.js.map +1 -1
- package/lib/testing/make-test-services.d.ts +44 -8
- package/lib/testing/make-test-services.d.ts.map +1 -1
- package/lib/testing/make-test-services.js +19 -3
- package/lib/testing/make-test-services.js.map +1 -1
- package/lib/testing/node/scratch-workspace.d.ts.map +1 -1
- package/lib/testing/node/scratch-workspace.js +9 -4
- package/lib/testing/node/scratch-workspace.js.map +1 -1
- package/lib/testing/node/spawned-server.d.ts +14 -0
- package/lib/testing/node/spawned-server.d.ts.map +1 -1
- package/lib/testing/node/spawned-server.js +33 -1
- package/lib/testing/node/spawned-server.js.map +1 -1
- package/lib/testing/playwright/flaky-network-proxy.d.ts +76 -0
- package/lib/testing/playwright/flaky-network-proxy.d.ts.map +1 -0
- package/lib/testing/playwright/flaky-network-proxy.js +164 -0
- package/lib/testing/playwright/flaky-network-proxy.js.map +1 -0
- package/lib/testing/playwright/index.d.ts +1 -0
- package/lib/testing/playwright/index.d.ts.map +1 -1
- package/lib/testing/playwright/index.js +1 -0
- package/lib/testing/playwright/index.js.map +1 -1
- package/lib/testing/playwright/server-log-capture.d.ts +14 -4
- package/lib/testing/playwright/server-log-capture.d.ts.map +1 -1
- package/lib/testing/playwright/server-log-capture.js +21 -4
- package/lib/testing/playwright/server-log-capture.js.map +1 -1
- package/lib/testing/playwright/server-log-rename-reporter.d.ts.map +1 -1
- package/lib/testing/playwright/server-log-rename-reporter.js +10 -1
- package/lib/testing/playwright/server-log-rename-reporter.js.map +1 -1
- package/lib/testing/stub-ast-document-manager.d.ts +5 -5
- package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
- package/lib/testing/stub-ast-document-manager.js +4 -6
- package/lib/testing/stub-ast-document-manager.js.map +1 -1
- package/lib/testing/stub-document-builder.d.ts +8 -0
- package/lib/testing/stub-document-builder.d.ts.map +1 -1
- package/lib/testing/stub-document-builder.js +22 -3
- package/lib/testing/stub-document-builder.js.map +1 -1
- package/lib/testing/stub-langium-documents.d.ts +3 -2
- package/lib/testing/stub-langium-documents.d.ts.map +1 -1
- package/lib/testing/stub-langium-documents.js.map +1 -1
- package/lib/testing/stub-model-service.d.ts +5 -4
- package/lib/testing/stub-model-service.d.ts.map +1 -1
- package/lib/testing/stub-model-service.js +2 -2
- package/lib/testing/stub-model-service.js.map +1 -1
- package/package.json +17 -8
- package/src/documents/ast-document-manager.ts +129 -36
- package/src/documents/client-ids.ts +5 -22
- package/src/documents/hydranium-text-documents.ts +248 -75
- package/src/documents/language-client-text-shadow.ts +59 -11
- package/src/documents/self-save-registry.ts +52 -13
- package/src/index.ts +6 -0
- package/src/langium/ast-extension/ast-node-builder.ts +66 -22
- package/src/langium/bootstrap.ts +16 -9
- package/src/langium/config/configuration-provider.ts +119 -0
- package/src/langium/config/index.ts +1 -0
- package/src/langium/diagnostics/lsp-logger.ts +41 -6
- package/src/langium/document-builder/build-pipeline-integration.ts +50 -5
- package/src/langium/document-builder/build-session.ts +87 -0
- package/src/langium/document-builder/document-builder.ts +339 -11
- package/src/langium/document-builder/index.ts +1 -0
- package/src/langium/integration-services.ts +67 -6
- package/src/langium/integrity/integrity-service.ts +116 -2
- package/src/langium/keys/containment.ts +87 -0
- package/src/langium/keys/index.ts +1 -0
- package/src/langium/keys/name-based-key-provider.ts +4 -0
- package/src/langium/language-module.ts +38 -0
- package/src/langium/model-service/model-service.ts +264 -32
- package/src/langium/module.ts +106 -21
- package/src/langium/naming/name-provider.ts +27 -5
- package/src/langium/naming/name-separator-validation.ts +34 -5
- package/src/langium/residency/cst-residency-service.ts +36 -14
- package/src/langium/scope/hydranium-scope-provider.ts +60 -22
- package/src/langium/serialization/abstract-serializer.ts +13 -32
- package/src/langium/service-registry.ts +19 -2
- package/src/langium/shared-services.ts +19 -2
- package/src/langium/transfer/transfer-encoder.ts +85 -24
- package/src/langium/trivia/comment-preserver.ts +1100 -0
- package/src/langium/trivia/document-ending-preserver.ts +55 -0
- package/src/langium/trivia/index.ts +14 -0
- package/src/langium/trivia/trivia-contribution.ts +39 -0
- package/src/langium/trivia/trivia-preserver.ts +54 -0
- package/src/langium/trivia/trivia-service.ts +99 -0
- package/src/langium/validation/document-validator.ts +537 -11
- package/src/langium/workspace/document-uri-policy.ts +3 -4
- package/src/langium/workspace/file-system-provider.ts +48 -8
- package/src/langium/workspace/hydranium-langium-document-factory.ts +34 -0
- package/src/langium/workspace/hydranium-workspace-manager.ts +30 -1
- package/src/langium/workspace/in-memory-file-system-provider.ts +53 -10
- package/src/langium/workspace/initialize-workspace.ts +34 -5
- package/src/langium/workspace/langium-documents.ts +106 -33
- package/src/langium/workspace/virtual-document.ts +21 -3
- package/src/locale/index.ts +10 -0
- package/src/locale/server-locale.ts +86 -0
- package/src/lsp/hydranium-document-update-handler.ts +1 -1
- package/src/lsp/index.ts +1 -1
- package/src/lsp/lsp-latency.ts +62 -0
- package/src/lsp/semantic-token-provider.ts +74 -7
- package/src/messages/carriers.ts +78 -0
- package/src/messages/index.ts +36 -0
- package/src/messages/renderer.ts +204 -0
- package/src/node/heap-ceiling.ts +108 -0
- package/src/node/index.ts +1 -0
- package/src/node/latency-from-env.ts +1 -1
- package/src/node/node-file-system-provider.ts +154 -47
- package/src/node/profile-capture.ts +8 -2
- package/src/node/profiling-run.ts +3 -3
- package/src/node/rename-over-open-readers.ts +78 -0
- package/src/node/socket-launcher.ts +18 -2
- package/src/testing/fake-document.ts +24 -5
- package/src/testing/make-noop-shared-services.ts +50 -2
- package/src/testing/make-test-services.ts +73 -18
- package/src/testing/node/scratch-workspace.ts +9 -4
- package/src/testing/node/spawned-server.ts +35 -1
- package/src/testing/playwright/flaky-network-proxy.ts +240 -0
- package/src/testing/playwright/index.ts +1 -0
- package/src/testing/playwright/server-log-capture.ts +24 -5
- package/src/testing/playwright/server-log-rename-reporter.ts +12 -1
- package/src/testing/stub-ast-document-manager.ts +10 -14
- package/src/testing/stub-document-builder.ts +32 -3
- package/src/testing/stub-langium-documents.ts +3 -2
- package/src/testing/stub-model-service.ts +7 -6
- package/lib/lsp/instrument-connection.d.ts +0 -36
- package/lib/lsp/instrument-connection.d.ts.map +0 -1
- package/lib/lsp/instrument-connection.js +0 -62
- package/lib/lsp/instrument-connection.js.map +0 -1
- package/src/lsp/instrument-connection.ts +0 -66
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import type { Tracer } from '@hydranium/protocol';
|
|
11
|
+
import { type LogNameOptions } from '../langium/diagnostics/logger.js';
|
|
12
|
+
import type { ServerSharedServicesMinimal } from '../langium/shared-services.js';
|
|
13
|
+
|
|
14
|
+
/** Construction options for {@link ServerLocale}. */
|
|
15
|
+
export type ServerLocaleOptions = LogNameOptions;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The locale contract the `ServerLocale` slot holds, implemented by
|
|
19
|
+
* {@link DefaultServerLocale}.
|
|
20
|
+
*
|
|
21
|
+
* An interface rather than the class, so the slot is compared STRUCTURALLY —
|
|
22
|
+
* a class-typed slot carries its `protected` members into every assignability
|
|
23
|
+
* check, compared nominally, which makes it unsatisfiable across two physical
|
|
24
|
+
* copies of this package and unreplaceable by an adopter's own declaration.
|
|
25
|
+
*/
|
|
26
|
+
export interface ServerLocale {
|
|
27
|
+
/** The locale, or `undefined` when no init supplied one — the framework's English. */
|
|
28
|
+
readonly value: string | undefined;
|
|
29
|
+
accept(locale: string): void;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The locale the server was handed at init, for whoever needs to render in the
|
|
34
|
+
* reading user's language. Held apart from the message renderer that reads it,
|
|
35
|
+
* so replacing the renderer cannot drop locale handling.
|
|
36
|
+
*
|
|
37
|
+
* A plain string in and out. A consumer that must react to a change rather than
|
|
38
|
+
* read the current value wraps this itself — nothing does today, and both real
|
|
39
|
+
* hosts respawn the server on a display-language switch.
|
|
40
|
+
*/
|
|
41
|
+
export class DefaultServerLocale implements ServerLocale {
|
|
42
|
+
protected readonly tracer: Tracer;
|
|
43
|
+
protected current: string | undefined;
|
|
44
|
+
|
|
45
|
+
constructor(services: ServerSharedServicesMinimal, options: ServerLocaleOptions = {}) {
|
|
46
|
+
this.tracer = services.Tracer.for(options.logName ?? 'ServerLocale').trace('instantiated');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The locale, or `undefined` when no init supplied one — which means the framework's English. */
|
|
50
|
+
get value(): string | undefined {
|
|
51
|
+
return this.current;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Take the locale an init declared.
|
|
56
|
+
*
|
|
57
|
+
* **One locale per process, and the reason the OTHER heads need none of
|
|
58
|
+
* their own.** The data and GLSP heads publish a port over the LSP
|
|
59
|
+
* connection and are reached by forwarding a socket to it, so they are the
|
|
60
|
+
* same process as the LSP head that was handed this locale — there is no
|
|
61
|
+
* topology in which one of them serves a second frontend. The Theia backend
|
|
62
|
+
* is the case that would break it, and it holds no locale precisely because
|
|
63
|
+
* it serves every frontend at once; nothing there writes here.
|
|
64
|
+
*
|
|
65
|
+
* The framework accepts a locale and never sources one, and neither
|
|
66
|
+
* validates nor normalises the tag: rejecting an unfamiliar one would be
|
|
67
|
+
* selecting a locale.
|
|
68
|
+
*
|
|
69
|
+
* Override to ignore the argument, which is how a host pins a locale it
|
|
70
|
+
* already knows but has no LSP client to declare.
|
|
71
|
+
*
|
|
72
|
+
* **The line is at `info`, which is a deliberate exception to the
|
|
73
|
+
* per-service default.** A locale is written once per process and it is the
|
|
74
|
+
* one setting that silently changes every user-facing sentence the server
|
|
75
|
+
* produces, so a reader trying to explain an unexpected language has nothing
|
|
76
|
+
* else to look at: the framework ships no catalogue, so "no entry for this
|
|
77
|
+
* code" and "no locale declared" both render the English and are
|
|
78
|
+
* indistinguishable in the output. At `debug` the line is below the default
|
|
79
|
+
* threshold and therefore absent from exactly the log someone would be
|
|
80
|
+
* reading.
|
|
81
|
+
*/
|
|
82
|
+
accept(locale: string): void {
|
|
83
|
+
this.current = locale;
|
|
84
|
+
this.tracer.info(`rendering messages in locale '${locale}'`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -257,7 +257,7 @@ export class HydraniumDocumentUpdateHandler extends DefaultDocumentUpdateHandler
|
|
|
257
257
|
}
|
|
258
258
|
const uri = UriUtils.toUri(change.uri);
|
|
259
259
|
const mtimeMs = await this.fileSystemProvider.mtimeMs?.(uri);
|
|
260
|
-
if (mtimeMs !== undefined && this.selfSaveRegistry.
|
|
260
|
+
if (mtimeMs !== undefined && this.selfSaveRegistry.isRegistered(uri.fsPath, mtimeMs)) {
|
|
261
261
|
return undefined;
|
|
262
262
|
}
|
|
263
263
|
return change;
|
package/src/lsp/index.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
export * from './completion/hydranium-completion-provider.js';
|
|
11
|
-
export * from './
|
|
11
|
+
export * from './lsp-latency.js';
|
|
12
12
|
export * from './semantic-token-provider.js';
|
|
13
13
|
export * from './language-module.js';
|
|
14
14
|
export * from './shared-module.js';
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import type { LatencyCollector } from '@hydranium/protocol';
|
|
11
|
+
import type { ConnectionOptions, Message } from 'vscode-jsonrpc';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Connection options that time every inbound LSP message into `latency` under
|
|
15
|
+
* its method name — the LSP analog of the data-server RPC chokepoint.
|
|
16
|
+
*
|
|
17
|
+
* Pass the result to `createConnection` where the head builds its connection:
|
|
18
|
+
* `createConnection(ProposedFeatures.all, lspLatencyOptions(latency))`. The
|
|
19
|
+
* transport is untouched, so a head keeps whatever `--stdio` / `--socket`
|
|
20
|
+
* selection its arguments make.
|
|
21
|
+
*
|
|
22
|
+
* **`messageStrategy` is the seam because it is the only one the handlers
|
|
23
|
+
* actually pass through.** `vscode-languageserver` builds its `Connection` as an
|
|
24
|
+
* object whose `onHover`, `onCompletion` and every other named helper register
|
|
25
|
+
* against the inner protocol connection captured in their closure — not against
|
|
26
|
+
* the returned object's own `onRequest`. Langium registers exclusively through
|
|
27
|
+
* those helpers, so decorating the `Connection` reaches none of them and reports
|
|
28
|
+
* an empty LSP half no matter how much traffic ran. `handleMessage` sits on the
|
|
29
|
+
* dispatch path itself, which every request and notification crosses, so it also
|
|
30
|
+
* catches `initialize` — special-cased into `onInitialize` and invisible to any
|
|
31
|
+
* `onRequest` decoration.
|
|
32
|
+
*
|
|
33
|
+
* What it measures is **dispatch plus handler**, not handler alone: the wait a
|
|
34
|
+
* client actually experiences, including time queued behind other work.
|
|
35
|
+
*
|
|
36
|
+
* When `latency` is `undefined` the seam is off and this returns `undefined`, so
|
|
37
|
+
* a head can pass the result of an env-gated factory (`latencyFromEnv()`)
|
|
38
|
+
* straight through and pay nothing when timing is not enabled.
|
|
39
|
+
*/
|
|
40
|
+
export function lspLatencyOptions(latency: LatencyCollector | undefined): ConnectionOptions | undefined {
|
|
41
|
+
if (!latency) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return {
|
|
45
|
+
messageStrategy: {
|
|
46
|
+
handleMessage: (message: Message, next: (message: Message) => void | Promise<void>) => {
|
|
47
|
+
// Responses to requests the SERVER sent carry no method and are not
|
|
48
|
+
// work this head performed; timing them would report the client's
|
|
49
|
+
// latency under a name this collector cannot supply.
|
|
50
|
+
if (!hasMethod(message)) {
|
|
51
|
+
return next(message);
|
|
52
|
+
}
|
|
53
|
+
return latency.time(message.method, () => next(message));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Narrow to the messages that name an operation — requests and notifications. */
|
|
60
|
+
function hasMethod(message: Message): message is Message & { method: string } {
|
|
61
|
+
return typeof (message as { method?: unknown }).method === 'string';
|
|
62
|
+
}
|
|
@@ -14,7 +14,9 @@ import {
|
|
|
14
14
|
CstUtils,
|
|
15
15
|
GrammarAST,
|
|
16
16
|
interruptAndCheck,
|
|
17
|
+
isLeafCstNode,
|
|
17
18
|
type LangiumDocument,
|
|
19
|
+
type LeafCstNode,
|
|
18
20
|
type ReferenceInfo
|
|
19
21
|
} from '@hydranium/langium';
|
|
20
22
|
import { AbstractSemanticTokenProvider, type SemanticTokenAcceptor } from '@hydranium/langium/lsp';
|
|
@@ -54,6 +56,23 @@ export interface HydraniumSemanticTokenProviderOptions {
|
|
|
54
56
|
* render in the editor's default foreground.
|
|
55
57
|
*/
|
|
56
58
|
readonly highlightKeywords?: boolean;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Also emit a `comment` token for every comment leaf of the CST.
|
|
62
|
+
*
|
|
63
|
+
* OFF by default for the same reason as {@link highlightKeywords}, and the
|
|
64
|
+
* loss is larger: a TextMate grammar distinguishes `comment.line` from
|
|
65
|
+
* `comment.block` and scopes the delimiters separately, where a semantic
|
|
66
|
+
* token carries one flat `comment` that overrides all of them. It exists
|
|
67
|
+
* for the host that ships no client-side grammar, where a comment otherwise
|
|
68
|
+
* renders in the editor's default foreground.
|
|
69
|
+
*
|
|
70
|
+
* What counts as a comment is every hidden terminal the lexer retains,
|
|
71
|
+
* which is every hidden terminal whose pattern is not whitespace. A grammar
|
|
72
|
+
* whose hidden non-whitespace terminal means something other than a comment
|
|
73
|
+
* is miscoloured, and this option is the place to say no.
|
|
74
|
+
*/
|
|
75
|
+
readonly highlightComments?: boolean;
|
|
57
76
|
}
|
|
58
77
|
|
|
59
78
|
/**
|
|
@@ -133,7 +152,9 @@ export abstract class AbstractHydraniumSemanticTokenProvider extends AbstractSem
|
|
|
133
152
|
cancelToken: CancellationToken
|
|
134
153
|
): Promise<void> {
|
|
135
154
|
await super.computeHighlighting(document, acceptor, cancelToken);
|
|
136
|
-
|
|
155
|
+
const keywords = this.options.highlightKeywords === true;
|
|
156
|
+
const comments = this.options.highlightComments === true;
|
|
157
|
+
if (!keywords && !comments) {
|
|
137
158
|
return;
|
|
138
159
|
}
|
|
139
160
|
const root = document.parseResult.value.$cstNode;
|
|
@@ -142,14 +163,60 @@ export abstract class AbstractHydraniumSemanticTokenProvider extends AbstractSem
|
|
|
142
163
|
}
|
|
143
164
|
for (const cst of CstUtils.streamCst(root)) {
|
|
144
165
|
await interruptAndCheck(cancelToken);
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
|
|
148
|
-
// neither a composite-node check nor a hidden-token check adds
|
|
149
|
-
// anything here.
|
|
150
|
-
if (GrammarAST.isKeyword(cst.grammarSource)) {
|
|
166
|
+
// A keyword is always a leaf with a `Keyword` grammar source, so that
|
|
167
|
+
// check alone separates it from everything else in the walk.
|
|
168
|
+
if (keywords && GrammarAST.isKeyword(cst.grammarSource)) {
|
|
151
169
|
acceptor({ cst, type: SemanticTokenTypes.keyword });
|
|
152
170
|
}
|
|
171
|
+
// A comment leaf cannot be recognised the same way — the CST builder
|
|
172
|
+
// adds hidden nodes from the token alone, so `grammarSource` is
|
|
173
|
+
// undefined, which is also why the keyword filter never matches one.
|
|
174
|
+
//
|
|
175
|
+
// `hidden` alone IS the comment test, and nothing narrower is needed:
|
|
176
|
+
// the token builder groups a hidden terminal as `Lexer.SKIPPED` when
|
|
177
|
+
// its pattern matches whitespace and as `hidden` otherwise, so the
|
|
178
|
+
// lexer discards whitespace before a CST node is ever built and every
|
|
179
|
+
// hidden leaf that survives is a comment. Classifying the terminal
|
|
180
|
+
// again here would be a second guard for the same property, which no
|
|
181
|
+
// test could then distinguish. An adopter whose token builder RETAINS
|
|
182
|
+
// whitespace breaks that equivalence and would colour its gaps.
|
|
183
|
+
if (comments && isLeafCstNode(cst) && cst.hidden) {
|
|
184
|
+
this.acceptComment(cst, acceptor);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Emit a comment as ONE TOKEN PER LINE, never as one multi-line range.
|
|
191
|
+
*
|
|
192
|
+
* A block comment is the first token this provider emits that can span
|
|
193
|
+
* lines, and the upstream encoder mishandles that for a client which does
|
|
194
|
+
* not advertise `multilineTokenSupport` — the split path computes the first
|
|
195
|
+
* line's length as `nextLineOffset - range.start.character - 1`, subtracting
|
|
196
|
+
* a COLUMN from a document OFFSET, so the length is right only for a token
|
|
197
|
+
* starting on line 0 and overruns its line everywhere else. No client in
|
|
198
|
+
* this repository advertises that capability, so the broken path is the one
|
|
199
|
+
* taken. Splitting here means every range handed over starts and ends on one
|
|
200
|
+
* line and the arithmetic is never reached.
|
|
201
|
+
*
|
|
202
|
+
* Lines come from the leaf's own text rather than from the document, so
|
|
203
|
+
* nothing has to re-derive where the comment ends.
|
|
204
|
+
*/
|
|
205
|
+
protected acceptComment(cst: LeafCstNode, acceptor: SemanticTokenAcceptor): void {
|
|
206
|
+
const lines = cst.text.split('\n');
|
|
207
|
+
for (let index = 0; index < lines.length; index++) {
|
|
208
|
+
// A `\r\n` document leaves the carriage return on the line's end;
|
|
209
|
+
// colouring it would extend the token past the visible text.
|
|
210
|
+
const length = lines[index].replace(/\r$/, '').length;
|
|
211
|
+
const character = index === 0 ? cst.range.start.character : 0;
|
|
212
|
+
if (length === 0) {
|
|
213
|
+
continue;
|
|
214
|
+
}
|
|
215
|
+
const line = cst.range.start.line + index;
|
|
216
|
+
acceptor({
|
|
217
|
+
range: { start: { line, character }, end: { line, character: character + length } },
|
|
218
|
+
type: SemanticTokenTypes.comment
|
|
219
|
+
});
|
|
153
220
|
}
|
|
154
221
|
}
|
|
155
222
|
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
hasMessageIdentity,
|
|
12
|
+
messageData,
|
|
13
|
+
type HydraniumMessageData,
|
|
14
|
+
type MessageDefinition,
|
|
15
|
+
type ParamsArg,
|
|
16
|
+
type ResolvedMessage
|
|
17
|
+
} from '@hydranium/protocol';
|
|
18
|
+
import type { AstNode, DiagnosticData, DiagnosticInfo, Properties, ValidationAcceptor } from '@hydranium/langium';
|
|
19
|
+
import { Diagnostic } from 'vscode-languageserver-protocol';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Raise a validation diagnostic from a declaration, so the call site never
|
|
23
|
+
* restates the code or the sentence.
|
|
24
|
+
*
|
|
25
|
+
* `code` is omitted from `info` because this owns it — the framework claims LSP
|
|
26
|
+
* `Diagnostic.code` for framework codes, which collides with no adopter today
|
|
27
|
+
* and is a stated rule rather than an accident. `data` is deliberately NOT
|
|
28
|
+
* omitted: Langium owns `data.code` for code-action dispatch, so a caller has to
|
|
29
|
+
* be able to request a quick fix. The identity is merged OVER whatever they
|
|
30
|
+
* pass, which makes the two conventions co-exist rather than compete.
|
|
31
|
+
*
|
|
32
|
+
* `data` admits adopter-owned keys beside Langium's, which is why the index
|
|
33
|
+
* signature is there rather than a bare `Partial<DiagnosticData>`. Langium's
|
|
34
|
+
* shape is closed, and a diagnostic that carries a COMPANION payload for its own
|
|
35
|
+
* surface to read — the field a form must highlight, say — has nowhere else to
|
|
36
|
+
* put it: an encoder projecting that payload reads `diagnostic.data`, so the
|
|
37
|
+
* narrower type made the identity and the companion mutually exclusive.
|
|
38
|
+
*
|
|
39
|
+
* The identity lands in both `code` and `data.hydranium` on purpose. `code` is
|
|
40
|
+
* what survives to the editor surface; Theia's converter drops `data` before the
|
|
41
|
+
* squiggle, so a parameterised diagnostic falls back to the server's English
|
|
42
|
+
* there while any adopter-owned surface can still render the parameterised form
|
|
43
|
+
* from the marker store.
|
|
44
|
+
*
|
|
45
|
+
* `DiagnosticInfo` must be Langium's own type: a `Parameters<ValidationAcceptor>[2]`
|
|
46
|
+
* shortcut compiles but loses the `property?: Properties<N>` relation. The `data`
|
|
47
|
+
* re-type has to be an intersection rather than an `Omit` alone, because Langium
|
|
48
|
+
* declares `data?: unknown` and an `unknown` cannot be spread.
|
|
49
|
+
*/
|
|
50
|
+
export function acceptMessage<S extends string, N extends AstNode, P extends Properties<N> = Properties<N>>(
|
|
51
|
+
accept: ValidationAcceptor,
|
|
52
|
+
severity: 'error' | 'warning' | 'info' | 'hint',
|
|
53
|
+
message: MessageDefinition<S>,
|
|
54
|
+
info: Omit<DiagnosticInfo<N, P>, 'code' | 'data'> & { data?: Partial<DiagnosticData> & Record<string, unknown> },
|
|
55
|
+
...params: ParamsArg<S>
|
|
56
|
+
): void {
|
|
57
|
+
const data: HydraniumMessageData & Partial<DiagnosticData> & Record<string, unknown> = {
|
|
58
|
+
...info.data,
|
|
59
|
+
...messageData(message, ...params)
|
|
60
|
+
};
|
|
61
|
+
accept(severity, message.format(...params), { ...info, code: message.code, data });
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Recover the identity from a published diagnostic, for a surface that
|
|
66
|
+
* identifies or renders diagnostics itself.
|
|
67
|
+
*
|
|
68
|
+
* `Diagnostic.message` is `string | MarkupContent` in LSP 3.17+, so the text
|
|
69
|
+
* comes from upstream's own `Diagnostic.getMessageString` rather than a
|
|
70
|
+
* hand-rolled narrowing — consuming the library in its style, and one fewer
|
|
71
|
+
* place restating the union.
|
|
72
|
+
*/
|
|
73
|
+
export function resolvedFromDiagnostic(diagnostic: Diagnostic): ResolvedMessage | undefined {
|
|
74
|
+
if (!hasMessageIdentity(diagnostic.data)) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
return { ...diagnostic.data.hydranium, text: Diagnostic.getMessageString(diagnostic) };
|
|
78
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Every user-facing message `@hydranium/core` raises, plus the carrier helpers
|
|
12
|
+
* that attach an identity to one.
|
|
13
|
+
*
|
|
14
|
+
* Declarations stay beside their call sites and are re-exported here, so this is
|
|
15
|
+
* enumeration rather than centralization: a code's package segment has to name
|
|
16
|
+
* the package that raises it. The English is a fallback, not a contract; the
|
|
17
|
+
* code is the contract, and renaming one is a breaking change.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
export * from './carriers.js';
|
|
21
|
+
export * from './renderer.js';
|
|
22
|
+
|
|
23
|
+
export { MODEL_UPDATE_EDIT } from '../langium/model-service/model-service.js';
|
|
24
|
+
export { SEPARATOR_IN_NAME } from '../langium/naming/name-separator-validation.js';
|
|
25
|
+
export {
|
|
26
|
+
INVALID_DEDENT,
|
|
27
|
+
UNEXPECTED_CHARACTER,
|
|
28
|
+
MISSING_ITERATION,
|
|
29
|
+
NO_VIABLE_ALTERNATIVE,
|
|
30
|
+
TRAILING_INPUT,
|
|
31
|
+
UNEXPECTED_TOKEN,
|
|
32
|
+
UNPOPPABLE_LEXER_MODE,
|
|
33
|
+
UNRESOLVED_REFERENCE
|
|
34
|
+
} from '../langium/validation/document-validator.js';
|
|
35
|
+
export { NO_LOADABLE_CONTENT } from '../langium/workspace/langium-documents.js';
|
|
36
|
+
export { NO_SUCH_FILE, NO_SUCH_PATH, UNSUPPORTED_WRITE } from '../langium/workspace/in-memory-file-system-provider.js';
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/********************************************************************************
|
|
2
|
+
* Copyright (c) 2026 CrossBreeze, EclipseSource and others.
|
|
3
|
+
*
|
|
4
|
+
* This program and the accompanying materials are made available under the
|
|
5
|
+
* terms of the MIT License which is available in the project root.
|
|
6
|
+
*
|
|
7
|
+
* SPDX-License-Identifier: MIT
|
|
8
|
+
********************************************************************************/
|
|
9
|
+
|
|
10
|
+
import {
|
|
11
|
+
describeError,
|
|
12
|
+
renderFrameworkMessage,
|
|
13
|
+
resolve,
|
|
14
|
+
resolvedFromResponseError,
|
|
15
|
+
type MessageDefinition,
|
|
16
|
+
type ParamsArg,
|
|
17
|
+
type ResolvedMessage,
|
|
18
|
+
type Tracer
|
|
19
|
+
} from '@hydranium/protocol';
|
|
20
|
+
import { SimpleCache } from '@hydranium/langium';
|
|
21
|
+
import type { ResponseError } from 'vscode-jsonrpc';
|
|
22
|
+
import { Diagnostic } from 'vscode-languageserver-protocol';
|
|
23
|
+
import { type LogNameOptions } from '../langium/diagnostics/logger.js';
|
|
24
|
+
import type { ServerSharedServicesMinimal } from '../langium/shared-services.js';
|
|
25
|
+
import type { ServerLocale } from '../locale/server-locale.js';
|
|
26
|
+
import { resolvedFromDiagnostic } from './carriers.js';
|
|
27
|
+
|
|
28
|
+
/** Construction options for {@link DefaultMessageRenderer}. */
|
|
29
|
+
export type MessageRendererOptions = LogNameOptions;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* The render contract the `MessageRenderer` slot holds, implemented by
|
|
33
|
+
* {@link DefaultMessageRenderer}.
|
|
34
|
+
*
|
|
35
|
+
* An interface rather than the class, so the slot is compared STRUCTURALLY. A
|
|
36
|
+
* class-typed slot carries its `protected` members into every assignability
|
|
37
|
+
* check and TypeScript compares those nominally — which makes the slot
|
|
38
|
+
* unsatisfiable by a subclass declared against a second physical copy of this
|
|
39
|
+
* package, which any duplicated install produces. It also
|
|
40
|
+
* lets an adopter REPLACE this declaration rather than intersect with it, so
|
|
41
|
+
* slot resolution does not depend on the order a services type is written in.
|
|
42
|
+
*
|
|
43
|
+
* Every method carries a no-throw contract; see the implementation.
|
|
44
|
+
*/
|
|
45
|
+
export interface MessageRenderer {
|
|
46
|
+
renderDiagnostic(diagnostic: Diagnostic): string;
|
|
47
|
+
renderError(error: ResponseError<unknown>): string;
|
|
48
|
+
renderMessage<S extends string>(message: MessageDefinition<S>, ...params: ParamsArg<S>): string;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Renders every user-facing message the server sends, in the locale the server
|
|
53
|
+
* was handed at init. The framework ships no catalogue, so its own behaviour is
|
|
54
|
+
* a pass-through.
|
|
55
|
+
*
|
|
56
|
+
* Adopters override {@link translationsFor}: the public render methods carry
|
|
57
|
+
* the no-throw contract, and the catalogue lookup they wrap is what can fail.
|
|
58
|
+
*
|
|
59
|
+
* Two render methods rather than one, because what is useful to an adopter is
|
|
60
|
+
* the carrier's structured fields and the two carriers have different ones. A
|
|
61
|
+
* single `render(text)` would force an adopter to match English prose, which
|
|
62
|
+
* breaks on the first Langium reword.
|
|
63
|
+
*/
|
|
64
|
+
export class DefaultMessageRenderer implements MessageRenderer {
|
|
65
|
+
protected readonly tracer: Tracer;
|
|
66
|
+
protected readonly serverLocale: ServerLocale;
|
|
67
|
+
/**
|
|
68
|
+
* {@link translationsFor}'s answer per locale, `undefined` answers included —
|
|
69
|
+
* a `SimpleCache` distinguishes "absent" from "cached as none", which matters
|
|
70
|
+
* because shipping no catalogue is the framework's own hot path.
|
|
71
|
+
*
|
|
72
|
+
* `SimpleCache` rather than Langium's `WorkspaceCache`: the eviction axis
|
|
73
|
+
* there is document change, and a catalogue does not depend on documents, so
|
|
74
|
+
* it would evict on every build AND put a `DocumentBuilder` dependency on a
|
|
75
|
+
* service the shared tier declares free of one. Nothing evicts this: the
|
|
76
|
+
* locale arrives once per process. A subclass whose catalogue can change
|
|
77
|
+
* clears it.
|
|
78
|
+
*/
|
|
79
|
+
protected readonly catalogues = new SimpleCache<string | undefined, Record<string, string> | undefined>();
|
|
80
|
+
|
|
81
|
+
constructor(services: ServerSharedServicesMinimal, options: MessageRendererOptions = {}) {
|
|
82
|
+
this.serverLocale = services.ServerLocale;
|
|
83
|
+
this.tracer = services.Tracer.for(options.logName ?? 'MessageRenderer').trace('instantiated');
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* The sentence to publish for `diagnostic`, replacing its current `message`.
|
|
88
|
+
* Sees lexer and parser errors too, which Langium pushes onto the document
|
|
89
|
+
* without routing them through `toDiagnostic`.
|
|
90
|
+
*
|
|
91
|
+
* **Must not throw**, which is why the guard is here and not at the call
|
|
92
|
+
* site: this runs inside the `Validated` phase, and Langium's
|
|
93
|
+
* `notifyDocumentPhase` rethrows anything that is not a cancellation — so an
|
|
94
|
+
* escaping error leaves the document AT `Validated` with the phase's
|
|
95
|
+
* listeners never run, and the client receives no diagnostics for that file.
|
|
96
|
+
* A subclass overriding this method takes that contract on itself.
|
|
97
|
+
*/
|
|
98
|
+
renderDiagnostic(diagnostic: Diagnostic): string {
|
|
99
|
+
try {
|
|
100
|
+
const resolved = resolvedFromDiagnostic(diagnostic);
|
|
101
|
+
return resolved ? this.render(resolved) : Diagnostic.getMessageString(diagnostic);
|
|
102
|
+
} catch (err: unknown) {
|
|
103
|
+
this.reportFailure(err, 'a diagnostic');
|
|
104
|
+
return Diagnostic.getMessageString(diagnostic);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The sentence to send for `error`, replacing its current `message`. Same
|
|
110
|
+
* no-throw contract as {@link renderDiagnostic}: an escaping error replaces a
|
|
111
|
+
* typed rejection the caller can handle with one it cannot.
|
|
112
|
+
*/
|
|
113
|
+
renderError(error: ResponseError<unknown>): string {
|
|
114
|
+
try {
|
|
115
|
+
const resolved = resolvedFromResponseError(error);
|
|
116
|
+
return resolved ? this.render(resolved) : error.message;
|
|
117
|
+
} catch (err: unknown) {
|
|
118
|
+
this.reportFailure(err, 'an RPC error');
|
|
119
|
+
return error.message;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The sentence for a declaration the caller holds directly, for a carrier
|
|
125
|
+
* with no slot to put an identity in.
|
|
126
|
+
*
|
|
127
|
+
* GLSP's action protocol is the case: every member of its message, status
|
|
128
|
+
* and reject actions is prose or an enum, so a code cannot travel and the
|
|
129
|
+
* raise site is the last place that still knows which message this is.
|
|
130
|
+
* Prefer {@link renderDiagnostic} / {@link renderError} wherever a carrier
|
|
131
|
+
* does hold the identity — they keep the render off the raise site, so an
|
|
132
|
+
* adopter's own messages ride the same one binding.
|
|
133
|
+
*
|
|
134
|
+
* Same no-throw contract as the carrier methods.
|
|
135
|
+
*/
|
|
136
|
+
renderMessage<S extends string>(message: MessageDefinition<S>, ...params: ParamsArg<S>): string {
|
|
137
|
+
// `resolve` is inside the guard with the render, not before it: it calls
|
|
138
|
+
// the declaration's own `format`, which for an adopter declaration is
|
|
139
|
+
// arbitrary code, and a throw there would escape a method whose contract
|
|
140
|
+
// says it cannot.
|
|
141
|
+
let resolved: ResolvedMessage | undefined;
|
|
142
|
+
try {
|
|
143
|
+
resolved = resolve(message, ...params);
|
|
144
|
+
return this.render(resolved);
|
|
145
|
+
} catch (err: unknown) {
|
|
146
|
+
this.reportFailure(err, `the message '${message.code}'`);
|
|
147
|
+
// Unset only when `format` ITSELF threw, which leaves the
|
|
148
|
+
// uninterpolated template as the only text there is. A failed render
|
|
149
|
+
// still has the resolved English.
|
|
150
|
+
return resolved?.text ?? message.text;
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The catalogue for the current locale, or `undefined` for none — the
|
|
156
|
+
* framework's answer, shipping none. Overriding this leaves every identity
|
|
157
|
+
* decision, every pass-through and the no-throw guard in place.
|
|
158
|
+
*
|
|
159
|
+
* **Called once per locale, not once per message**, so an override may load
|
|
160
|
+
* a file or build a map without that cost landing per diagnostic. The
|
|
161
|
+
* corollary is that a catalogue mutated in place afterwards is not seen;
|
|
162
|
+
* clear {@link catalogues} to invalidate.
|
|
163
|
+
*
|
|
164
|
+
* An adopter wanting Langium's own uncoded sentences instead matches
|
|
165
|
+
* `Diagnostic.data.code` from an overridden {@link renderDiagnostic}, never
|
|
166
|
+
* the sentence.
|
|
167
|
+
*/
|
|
168
|
+
protected translationsFor(_locale: string | undefined): Record<string, string> | undefined {
|
|
169
|
+
return undefined;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Resolve one identity against the current locale's catalogue.
|
|
174
|
+
*
|
|
175
|
+
* Reads the locale per call. Copying it into a field at construction pins
|
|
176
|
+
* whatever was there before init ran, which is always `undefined` — services
|
|
177
|
+
* compose first.
|
|
178
|
+
*
|
|
179
|
+
* The catalogue behind it is memoized, because a workspace-wide validation
|
|
180
|
+
* renders once per diagnostic and the naive override — parse a JSON file,
|
|
181
|
+
* build a map — then pays that per diagnostic rather than per locale.
|
|
182
|
+
*/
|
|
183
|
+
protected render(message: ResolvedMessage): string {
|
|
184
|
+
const locale = this.serverLocale.value;
|
|
185
|
+
return renderFrameworkMessage(
|
|
186
|
+
message,
|
|
187
|
+
this.catalogues.get(locale, () => this.translationsFor(locale))
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Emit a failed render. Logged rather than swallowed: the fallback output is
|
|
193
|
+
* byte-identical to a correctly-configured default, so a throwing catalogue
|
|
194
|
+
* is otherwise invisible.
|
|
195
|
+
*/
|
|
196
|
+
protected reportFailure(err: unknown, carrier: string): void {
|
|
197
|
+
this.tracer.error(this.formatRenderFailure(err, carrier));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Format the failed-render line. Override to name the adopter's catalogue entry. */
|
|
201
|
+
protected formatRenderFailure(err: unknown, carrier: string): string {
|
|
202
|
+
return `rendering ${carrier} failed; falling back to the server's own text. ${describeError(err)}`;
|
|
203
|
+
}
|
|
204
|
+
}
|