@hydranium/core 1.0.0-next.8 → 1.0.0-next.85
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 +55 -21
- package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
- package/lib/documents/hydranium-text-documents.js +142 -46
- 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 +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -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 +13 -1
- package/lib/langium/document-builder/build-pipeline-integration.d.ts.map +1 -1
- package/lib/langium/document-builder/build-pipeline-integration.js +1 -1
- 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 +5 -0
- package/lib/langium/integrity/integrity-service.d.ts.map +1 -1
- package/lib/langium/integrity/integrity-service.js +34 -1
- 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/model-service/model-service.d.ts +149 -10
- package/lib/langium/model-service/model-service.d.ts.map +1 -1
- package/lib/langium/model-service/model-service.js +120 -93
- 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 -9
- 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 +32 -13
- package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
- package/lib/langium/scope/hydranium-scope-provider.js +37 -20
- package/lib/langium/scope/hydranium-scope-provider.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/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/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 +8 -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 +11 -2
- 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/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.map +1 -1
- package/lib/node/node-file-system-provider.js +1 -40
- package/lib/node/node-file-system-provider.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/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/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 +167 -61
- package/src/documents/language-client-text-shadow.ts +59 -11
- package/src/documents/self-save-registry.ts +52 -13
- package/src/index.ts +5 -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 +14 -1
- 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 +35 -1
- 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/model-service/model-service.ts +211 -30
- 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 -12
- package/src/langium/scope/hydranium-scope-provider.ts +40 -22
- package/src/langium/shared-services.ts +19 -2
- package/src/langium/transfer/transfer-encoder.ts +85 -24
- package/src/langium/validation/document-validator.ts +537 -11
- package/src/langium/workspace/document-uri-policy.ts +3 -4
- 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 +13 -3
- package/src/langium/workspace/initialize-workspace.ts +34 -5
- package/src/langium/workspace/langium-documents.ts +106 -33
- 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 +1 -41
- package/src/node/profiling-run.ts +3 -3
- package/src/node/rename-over-open-readers.ts +78 -0
- 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/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
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
|
-
import { AstUtils, CstUtils, GrammarAST, interruptAndCheck } from '@hydranium/langium';
|
|
9
|
+
import { AstUtils, CstUtils, GrammarAST, interruptAndCheck, isLeafCstNode } from '@hydranium/langium';
|
|
10
10
|
import { AbstractSemanticTokenProvider } from '@hydranium/langium/lsp';
|
|
11
11
|
import { SemanticTokenModifiers, SemanticTokenTypes } from 'vscode-languageserver';
|
|
12
12
|
/** Normalise both {@link SemanticTokenKind} forms to the acceptor's shape. */
|
|
@@ -86,7 +86,9 @@ export class AbstractHydraniumSemanticTokenProvider extends AbstractSemanticToke
|
|
|
86
86
|
*/
|
|
87
87
|
async computeHighlighting(document, acceptor, cancelToken) {
|
|
88
88
|
await super.computeHighlighting(document, acceptor, cancelToken);
|
|
89
|
-
|
|
89
|
+
const keywords = this.options.highlightKeywords === true;
|
|
90
|
+
const comments = this.options.highlightComments === true;
|
|
91
|
+
if (!keywords && !comments) {
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
94
|
const root = document.parseResult.value.$cstNode;
|
|
@@ -95,14 +97,59 @@ export class AbstractHydraniumSemanticTokenProvider extends AbstractSemanticToke
|
|
|
95
97
|
}
|
|
96
98
|
for (const cst of CstUtils.streamCst(root)) {
|
|
97
99
|
await interruptAndCheck(cancelToken);
|
|
98
|
-
//
|
|
99
|
-
//
|
|
100
|
-
|
|
101
|
-
// neither a composite-node check nor a hidden-token check adds
|
|
102
|
-
// anything here.
|
|
103
|
-
if (GrammarAST.isKeyword(cst.grammarSource)) {
|
|
100
|
+
// A keyword is always a leaf with a `Keyword` grammar source, so that
|
|
101
|
+
// check alone separates it from everything else in the walk.
|
|
102
|
+
if (keywords && GrammarAST.isKeyword(cst.grammarSource)) {
|
|
104
103
|
acceptor({ cst, type: SemanticTokenTypes.keyword });
|
|
105
104
|
}
|
|
105
|
+
// A comment leaf cannot be recognised the same way — the CST builder
|
|
106
|
+
// adds hidden nodes from the token alone, so `grammarSource` is
|
|
107
|
+
// undefined, which is also why the keyword filter never matches one.
|
|
108
|
+
//
|
|
109
|
+
// `hidden` alone IS the comment test, and nothing narrower is needed:
|
|
110
|
+
// the token builder groups a hidden terminal as `Lexer.SKIPPED` when
|
|
111
|
+
// its pattern matches whitespace and as `hidden` otherwise, so the
|
|
112
|
+
// lexer discards whitespace before a CST node is ever built and every
|
|
113
|
+
// hidden leaf that survives is a comment. Classifying the terminal
|
|
114
|
+
// again here would be a second guard for the same property, which no
|
|
115
|
+
// test could then distinguish. An adopter whose token builder RETAINS
|
|
116
|
+
// whitespace breaks that equivalence and would colour its gaps.
|
|
117
|
+
if (comments && isLeafCstNode(cst) && cst.hidden) {
|
|
118
|
+
this.acceptComment(cst, acceptor);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Emit a comment as ONE TOKEN PER LINE, never as one multi-line range.
|
|
124
|
+
*
|
|
125
|
+
* A block comment is the first token this provider emits that can span
|
|
126
|
+
* lines, and the upstream encoder mishandles that for a client which does
|
|
127
|
+
* not advertise `multilineTokenSupport` — the split path computes the first
|
|
128
|
+
* line's length as `nextLineOffset - range.start.character - 1`, subtracting
|
|
129
|
+
* a COLUMN from a document OFFSET, so the length is right only for a token
|
|
130
|
+
* starting on line 0 and overruns its line everywhere else. No client in
|
|
131
|
+
* this repository advertises that capability, so the broken path is the one
|
|
132
|
+
* taken. Splitting here means every range handed over starts and ends on one
|
|
133
|
+
* line and the arithmetic is never reached.
|
|
134
|
+
*
|
|
135
|
+
* Lines come from the leaf's own text rather than from the document, so
|
|
136
|
+
* nothing has to re-derive where the comment ends.
|
|
137
|
+
*/
|
|
138
|
+
acceptComment(cst, acceptor) {
|
|
139
|
+
const lines = cst.text.split('\n');
|
|
140
|
+
for (let index = 0; index < lines.length; index++) {
|
|
141
|
+
// A `\r\n` document leaves the carriage return on the line's end;
|
|
142
|
+
// colouring it would extend the token past the visible text.
|
|
143
|
+
const length = lines[index].replace(/\r$/, '').length;
|
|
144
|
+
const character = index === 0 ? cst.range.start.character : 0;
|
|
145
|
+
if (length === 0) {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const line = cst.range.start.line + index;
|
|
149
|
+
acceptor({
|
|
150
|
+
range: { start: { line, character }, end: { line, character: character + length } },
|
|
151
|
+
type: SemanticTokenTypes.comment
|
|
152
|
+
});
|
|
106
153
|
}
|
|
107
154
|
}
|
|
108
155
|
highlightElement(node, acceptor) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic-token-provider.js","sourceRoot":"","sources":["../../src/lsp/semantic-token-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAGJ,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,iBAAiB,
|
|
1
|
+
{"version":3,"file":"semantic-token-provider.js","sourceRoot":"","sources":["../../src/lsp/semantic-token-provider.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAGJ,QAAQ,EACR,QAAQ,EACR,UAAU,EACV,iBAAiB,EACjB,aAAa,EAIf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,6BAA6B,EAA8B,MAAM,wBAAwB,CAAC;AACnG,OAAO,EAA0B,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAY3G,8EAA8E;AAC9E,SAAS,gBAAgB,CAAC,IAAuB,EAAE,gBAAyB;IACzE,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC5B,OAAO,gBAAgB,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,gBAAgB,EAAE,CAAC;IACvG,CAAC;IACD,OAAO,IAAI,CAAC,QAAQ,KAAK,SAAS,IAAI,gBAAgB,KAAK,SAAS,CAAC,CAA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AC;gBACtB,SAAS;YACZ,CAAC;YACD,QAAQ,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,GAAG,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC7G,CAAC;IACJ,CAAC;IAiBD,0FAA0F;IAChF,kBAAkB,CAAC,IAAa;QACvC,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACxC,CAAC;IAED,4GAA4G;IAClG,gBAAgB,CAAC,IAAmB;QAC3C,OAAO,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,uFAAuF;IAC7E,eAAe,CAAC,IAAa;QACpC,OAAO,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAClD,CAAC;CACH"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
import { type MessageDefinition, type ParamsArg, type ResolvedMessage } from '@hydranium/protocol';
|
|
10
|
+
import type { AstNode, DiagnosticData, DiagnosticInfo, Properties, ValidationAcceptor } from '@hydranium/langium';
|
|
11
|
+
import { Diagnostic } from 'vscode-languageserver-protocol';
|
|
12
|
+
/**
|
|
13
|
+
* Raise a validation diagnostic from a declaration, so the call site never
|
|
14
|
+
* restates the code or the sentence.
|
|
15
|
+
*
|
|
16
|
+
* `code` is omitted from `info` because this owns it — the framework claims LSP
|
|
17
|
+
* `Diagnostic.code` for framework codes, which collides with no adopter today
|
|
18
|
+
* and is a stated rule rather than an accident. `data` is deliberately NOT
|
|
19
|
+
* omitted: Langium owns `data.code` for code-action dispatch, so a caller has to
|
|
20
|
+
* be able to request a quick fix. The identity is merged OVER whatever they
|
|
21
|
+
* pass, which makes the two conventions co-exist rather than compete.
|
|
22
|
+
*
|
|
23
|
+
* `data` admits adopter-owned keys beside Langium's, which is why the index
|
|
24
|
+
* signature is there rather than a bare `Partial<DiagnosticData>`. Langium's
|
|
25
|
+
* shape is closed, and a diagnostic that carries a COMPANION payload for its own
|
|
26
|
+
* surface to read — the field a form must highlight, say — has nowhere else to
|
|
27
|
+
* put it: an encoder projecting that payload reads `diagnostic.data`, so the
|
|
28
|
+
* narrower type made the identity and the companion mutually exclusive.
|
|
29
|
+
*
|
|
30
|
+
* The identity lands in both `code` and `data.hydranium` on purpose. `code` is
|
|
31
|
+
* what survives to the editor surface; Theia's converter drops `data` before the
|
|
32
|
+
* squiggle, so a parameterised diagnostic falls back to the server's English
|
|
33
|
+
* there while any adopter-owned surface can still render the parameterised form
|
|
34
|
+
* from the marker store.
|
|
35
|
+
*
|
|
36
|
+
* `DiagnosticInfo` must be Langium's own type: a `Parameters<ValidationAcceptor>[2]`
|
|
37
|
+
* shortcut compiles but loses the `property?: Properties<N>` relation. The `data`
|
|
38
|
+
* re-type has to be an intersection rather than an `Omit` alone, because Langium
|
|
39
|
+
* declares `data?: unknown` and an `unknown` cannot be spread.
|
|
40
|
+
*/
|
|
41
|
+
export declare function acceptMessage<S extends string, N extends AstNode, P extends Properties<N> = Properties<N>>(accept: ValidationAcceptor, severity: 'error' | 'warning' | 'info' | 'hint', message: MessageDefinition<S>, info: Omit<DiagnosticInfo<N, P>, 'code' | 'data'> & {
|
|
42
|
+
data?: Partial<DiagnosticData> & Record<string, unknown>;
|
|
43
|
+
}, ...params: ParamsArg<S>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Recover the identity from a published diagnostic, for a surface that
|
|
46
|
+
* identifies or renders diagnostics itself.
|
|
47
|
+
*
|
|
48
|
+
* `Diagnostic.message` is `string | MarkupContent` in LSP 3.17+, so the text
|
|
49
|
+
* comes from upstream's own `Diagnostic.getMessageString` rather than a
|
|
50
|
+
* hand-rolled narrowing — consuming the library in its style, and one fewer
|
|
51
|
+
* place restating the union.
|
|
52
|
+
*/
|
|
53
|
+
export declare function resolvedFromDiagnostic(diagnostic: Diagnostic): ResolvedMessage | undefined;
|
|
54
|
+
//# sourceMappingURL=carriers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carriers.d.ts","sourceRoot":"","sources":["../../src/messages/carriers.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAIJ,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,eAAe,EACtB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAClH,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,OAAO,EAAE,CAAC,SAAS,UAAU,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,EACvG,MAAM,EAAE,kBAAkB,EAC1B,QAAQ,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,MAAM,EAC/C,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAC7B,IAAI,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,GAAG;IAAE,IAAI,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CAAE,EAChH,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GACvB,IAAI,CAMN;AAED;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,GAAG,eAAe,GAAG,SAAS,CAK1F"}
|
|
@@ -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
|
+
import { hasMessageIdentity, messageData } from '@hydranium/protocol';
|
|
10
|
+
import { Diagnostic } from 'vscode-languageserver-protocol';
|
|
11
|
+
/**
|
|
12
|
+
* Raise a validation diagnostic from a declaration, so the call site never
|
|
13
|
+
* restates the code or the sentence.
|
|
14
|
+
*
|
|
15
|
+
* `code` is omitted from `info` because this owns it — the framework claims LSP
|
|
16
|
+
* `Diagnostic.code` for framework codes, which collides with no adopter today
|
|
17
|
+
* and is a stated rule rather than an accident. `data` is deliberately NOT
|
|
18
|
+
* omitted: Langium owns `data.code` for code-action dispatch, so a caller has to
|
|
19
|
+
* be able to request a quick fix. The identity is merged OVER whatever they
|
|
20
|
+
* pass, which makes the two conventions co-exist rather than compete.
|
|
21
|
+
*
|
|
22
|
+
* `data` admits adopter-owned keys beside Langium's, which is why the index
|
|
23
|
+
* signature is there rather than a bare `Partial<DiagnosticData>`. Langium's
|
|
24
|
+
* shape is closed, and a diagnostic that carries a COMPANION payload for its own
|
|
25
|
+
* surface to read — the field a form must highlight, say — has nowhere else to
|
|
26
|
+
* put it: an encoder projecting that payload reads `diagnostic.data`, so the
|
|
27
|
+
* narrower type made the identity and the companion mutually exclusive.
|
|
28
|
+
*
|
|
29
|
+
* The identity lands in both `code` and `data.hydranium` on purpose. `code` is
|
|
30
|
+
* what survives to the editor surface; Theia's converter drops `data` before the
|
|
31
|
+
* squiggle, so a parameterised diagnostic falls back to the server's English
|
|
32
|
+
* there while any adopter-owned surface can still render the parameterised form
|
|
33
|
+
* from the marker store.
|
|
34
|
+
*
|
|
35
|
+
* `DiagnosticInfo` must be Langium's own type: a `Parameters<ValidationAcceptor>[2]`
|
|
36
|
+
* shortcut compiles but loses the `property?: Properties<N>` relation. The `data`
|
|
37
|
+
* re-type has to be an intersection rather than an `Omit` alone, because Langium
|
|
38
|
+
* declares `data?: unknown` and an `unknown` cannot be spread.
|
|
39
|
+
*/
|
|
40
|
+
export function acceptMessage(accept, severity, message, info, ...params) {
|
|
41
|
+
const data = {
|
|
42
|
+
...info.data,
|
|
43
|
+
...messageData(message, ...params)
|
|
44
|
+
};
|
|
45
|
+
accept(severity, message.format(...params), { ...info, code: message.code, data });
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Recover the identity from a published diagnostic, for a surface that
|
|
49
|
+
* identifies or renders diagnostics itself.
|
|
50
|
+
*
|
|
51
|
+
* `Diagnostic.message` is `string | MarkupContent` in LSP 3.17+, so the text
|
|
52
|
+
* comes from upstream's own `Diagnostic.getMessageString` rather than a
|
|
53
|
+
* hand-rolled narrowing — consuming the library in its style, and one fewer
|
|
54
|
+
* place restating the union.
|
|
55
|
+
*/
|
|
56
|
+
export function resolvedFromDiagnostic(diagnostic) {
|
|
57
|
+
if (!hasMessageIdentity(diagnostic.data)) {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
return { ...diagnostic.data.hydranium, text: Diagnostic.getMessageString(diagnostic) };
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=carriers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"carriers.js","sourceRoot":"","sources":["../../src/messages/carriers.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EACJ,kBAAkB,EAClB,WAAW,EAKb,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAE5D;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,aAAa,CAC1B,MAA0B,EAC1B,QAA+C,EAC/C,OAA6B,EAC7B,IAAgH,EAChH,GAAG,MAAoB;IAEvB,MAAM,IAAI,GAA6E;QACpF,GAAG,IAAI,CAAC,IAAI;QACZ,GAAG,WAAW,CAAC,OAAO,EAAE,GAAG,MAAM,CAAC;KACpC,CAAC;IACF,MAAM,CAAC,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;AACtF,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAsB;IAC1D,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IACpB,CAAC;IACD,OAAO,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,UAAU,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;AAC1F,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* Every user-facing message `@hydranium/core` raises, plus the carrier helpers
|
|
11
|
+
* that attach an identity to one.
|
|
12
|
+
*
|
|
13
|
+
* Declarations stay beside their call sites and are re-exported here, so this is
|
|
14
|
+
* enumeration rather than centralization: a code's package segment has to name
|
|
15
|
+
* the package that raises it. The English is a fallback, not a contract; the
|
|
16
|
+
* code is the contract, and renaming one is a breaking change.
|
|
17
|
+
*/
|
|
18
|
+
export * from './carriers.js';
|
|
19
|
+
export * from './renderer.js';
|
|
20
|
+
export { MODEL_UPDATE_EDIT } from '../langium/model-service/model-service.js';
|
|
21
|
+
export { SEPARATOR_IN_NAME } from '../langium/naming/name-separator-validation.js';
|
|
22
|
+
export { INVALID_DEDENT, UNEXPECTED_CHARACTER, MISSING_ITERATION, NO_VIABLE_ALTERNATIVE, TRAILING_INPUT, UNEXPECTED_TOKEN, UNPOPPABLE_LEXER_MODE, UNRESOLVED_REFERENCE } from '../langium/validation/document-validator.js';
|
|
23
|
+
export { NO_LOADABLE_CONTENT } from '../langium/workspace/langium-documents.js';
|
|
24
|
+
export { NO_SUCH_FILE, NO_SUCH_PATH } from '../langium/workspace/in-memory-file-system-provider.js';
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;GAQG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EACJ,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACtB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wDAAwD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
* Every user-facing message `@hydranium/core` raises, plus the carrier helpers
|
|
11
|
+
* that attach an identity to one.
|
|
12
|
+
*
|
|
13
|
+
* Declarations stay beside their call sites and are re-exported here, so this is
|
|
14
|
+
* enumeration rather than centralization: a code's package segment has to name
|
|
15
|
+
* the package that raises it. The English is a fallback, not a contract; the
|
|
16
|
+
* code is the contract, and renaming one is a breaking change.
|
|
17
|
+
*/
|
|
18
|
+
export * from './carriers.js';
|
|
19
|
+
export * from './renderer.js';
|
|
20
|
+
export { MODEL_UPDATE_EDIT } from '../langium/model-service/model-service.js';
|
|
21
|
+
export { SEPARATOR_IN_NAME } from '../langium/naming/name-separator-validation.js';
|
|
22
|
+
export { INVALID_DEDENT, UNEXPECTED_CHARACTER, MISSING_ITERATION, NO_VIABLE_ALTERNATIVE, TRAILING_INPUT, UNEXPECTED_TOKEN, UNPOPPABLE_LEXER_MODE, UNRESOLVED_REFERENCE } from '../langium/validation/document-validator.js';
|
|
23
|
+
export { NO_LOADABLE_CONTENT } from '../langium/workspace/langium-documents.js';
|
|
24
|
+
export { NO_SUCH_FILE, NO_SUCH_PATH } from '../langium/workspace/in-memory-file-system-provider.js';
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/messages/index.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF;;;;;;;;GAQG;AAEH,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC;AAE9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AACnF,OAAO,EACJ,cAAc,EACd,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,cAAc,EACd,gBAAgB,EAChB,qBAAqB,EACrB,oBAAoB,EACtB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,wDAAwD,CAAC"}
|
|
@@ -0,0 +1,136 @@
|
|
|
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
|
+
import { type MessageDefinition, type ParamsArg, type ResolvedMessage, type Tracer } from '@hydranium/protocol';
|
|
10
|
+
import { SimpleCache } from '@hydranium/langium';
|
|
11
|
+
import type { ResponseError } from 'vscode-jsonrpc';
|
|
12
|
+
import { Diagnostic } from 'vscode-languageserver-protocol';
|
|
13
|
+
import { type LogNameOptions } from '../langium/diagnostics/logger.js';
|
|
14
|
+
import type { ServerSharedServicesMinimal } from '../langium/shared-services.js';
|
|
15
|
+
import type { ServerLocale } from '../locale/server-locale.js';
|
|
16
|
+
/** Construction options for {@link DefaultMessageRenderer}. */
|
|
17
|
+
export type MessageRendererOptions = LogNameOptions;
|
|
18
|
+
/**
|
|
19
|
+
* The render contract the `MessageRenderer` slot holds, implemented by
|
|
20
|
+
* {@link DefaultMessageRenderer}.
|
|
21
|
+
*
|
|
22
|
+
* An interface rather than the class, so the slot is compared STRUCTURALLY. A
|
|
23
|
+
* class-typed slot carries its `protected` members into every assignability
|
|
24
|
+
* check and TypeScript compares those nominally — which makes the slot
|
|
25
|
+
* unsatisfiable by a subclass declared against a second physical copy of this
|
|
26
|
+
* package, which any duplicated install produces. It also
|
|
27
|
+
* lets an adopter REPLACE this declaration rather than intersect with it, so
|
|
28
|
+
* slot resolution does not depend on the order a services type is written in.
|
|
29
|
+
*
|
|
30
|
+
* Every method carries a no-throw contract; see the implementation.
|
|
31
|
+
*/
|
|
32
|
+
export interface MessageRenderer {
|
|
33
|
+
renderDiagnostic(diagnostic: Diagnostic): string;
|
|
34
|
+
renderError(error: ResponseError<unknown>): string;
|
|
35
|
+
renderMessage<S extends string>(message: MessageDefinition<S>, ...params: ParamsArg<S>): string;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Renders every user-facing message the server sends, in the locale the server
|
|
39
|
+
* was handed at init. The framework ships no catalogue, so its own behaviour is
|
|
40
|
+
* a pass-through.
|
|
41
|
+
*
|
|
42
|
+
* Adopters override {@link translationsFor}: the public render methods carry
|
|
43
|
+
* the no-throw contract, and the catalogue lookup they wrap is what can fail.
|
|
44
|
+
*
|
|
45
|
+
* Two render methods rather than one, because what is useful to an adopter is
|
|
46
|
+
* the carrier's structured fields and the two carriers have different ones. A
|
|
47
|
+
* single `render(text)` would force an adopter to match English prose, which
|
|
48
|
+
* breaks on the first Langium reword.
|
|
49
|
+
*/
|
|
50
|
+
export declare class DefaultMessageRenderer implements MessageRenderer {
|
|
51
|
+
protected readonly tracer: Tracer;
|
|
52
|
+
protected readonly serverLocale: ServerLocale;
|
|
53
|
+
/**
|
|
54
|
+
* {@link translationsFor}'s answer per locale, `undefined` answers included —
|
|
55
|
+
* a `SimpleCache` distinguishes "absent" from "cached as none", which matters
|
|
56
|
+
* because shipping no catalogue is the framework's own hot path.
|
|
57
|
+
*
|
|
58
|
+
* `SimpleCache` rather than Langium's `WorkspaceCache`: the eviction axis
|
|
59
|
+
* there is document change, and a catalogue does not depend on documents, so
|
|
60
|
+
* it would evict on every build AND put a `DocumentBuilder` dependency on a
|
|
61
|
+
* service the shared tier declares free of one. Nothing evicts this: the
|
|
62
|
+
* locale arrives once per process. A subclass whose catalogue can change
|
|
63
|
+
* clears it.
|
|
64
|
+
*/
|
|
65
|
+
protected readonly catalogues: SimpleCache<string | undefined, Record<string, string> | undefined>;
|
|
66
|
+
constructor(services: ServerSharedServicesMinimal, options?: MessageRendererOptions);
|
|
67
|
+
/**
|
|
68
|
+
* The sentence to publish for `diagnostic`, replacing its current `message`.
|
|
69
|
+
* Sees lexer and parser errors too, which Langium pushes onto the document
|
|
70
|
+
* without routing them through `toDiagnostic`.
|
|
71
|
+
*
|
|
72
|
+
* **Must not throw**, which is why the guard is here and not at the call
|
|
73
|
+
* site: this runs inside the `Validated` phase, and Langium's
|
|
74
|
+
* `notifyDocumentPhase` rethrows anything that is not a cancellation — so an
|
|
75
|
+
* escaping error leaves the document AT `Validated` with the phase's
|
|
76
|
+
* listeners never run, and the client receives no diagnostics for that file.
|
|
77
|
+
* A subclass overriding this method takes that contract on itself.
|
|
78
|
+
*/
|
|
79
|
+
renderDiagnostic(diagnostic: Diagnostic): string;
|
|
80
|
+
/**
|
|
81
|
+
* The sentence to send for `error`, replacing its current `message`. Same
|
|
82
|
+
* no-throw contract as {@link renderDiagnostic}: an escaping error replaces a
|
|
83
|
+
* typed rejection the caller can handle with one it cannot.
|
|
84
|
+
*/
|
|
85
|
+
renderError(error: ResponseError<unknown>): string;
|
|
86
|
+
/**
|
|
87
|
+
* The sentence for a declaration the caller holds directly, for a carrier
|
|
88
|
+
* with no slot to put an identity in.
|
|
89
|
+
*
|
|
90
|
+
* GLSP's action protocol is the case: every member of its message, status
|
|
91
|
+
* and reject actions is prose or an enum, so a code cannot travel and the
|
|
92
|
+
* raise site is the last place that still knows which message this is.
|
|
93
|
+
* Prefer {@link renderDiagnostic} / {@link renderError} wherever a carrier
|
|
94
|
+
* does hold the identity — they keep the render off the raise site, so an
|
|
95
|
+
* adopter's own messages ride the same one binding.
|
|
96
|
+
*
|
|
97
|
+
* Same no-throw contract as the carrier methods.
|
|
98
|
+
*/
|
|
99
|
+
renderMessage<S extends string>(message: MessageDefinition<S>, ...params: ParamsArg<S>): string;
|
|
100
|
+
/**
|
|
101
|
+
* The catalogue for the current locale, or `undefined` for none — the
|
|
102
|
+
* framework's answer, shipping none. Overriding this leaves every identity
|
|
103
|
+
* decision, every pass-through and the no-throw guard in place.
|
|
104
|
+
*
|
|
105
|
+
* **Called once per locale, not once per message**, so an override may load
|
|
106
|
+
* a file or build a map without that cost landing per diagnostic. The
|
|
107
|
+
* corollary is that a catalogue mutated in place afterwards is not seen;
|
|
108
|
+
* clear {@link catalogues} to invalidate.
|
|
109
|
+
*
|
|
110
|
+
* An adopter wanting Langium's own uncoded sentences instead matches
|
|
111
|
+
* `Diagnostic.data.code` from an overridden {@link renderDiagnostic}, never
|
|
112
|
+
* the sentence.
|
|
113
|
+
*/
|
|
114
|
+
protected translationsFor(_locale: string | undefined): Record<string, string> | undefined;
|
|
115
|
+
/**
|
|
116
|
+
* Resolve one identity against the current locale's catalogue.
|
|
117
|
+
*
|
|
118
|
+
* Reads the locale per call. Copying it into a field at construction pins
|
|
119
|
+
* whatever was there before init ran, which is always `undefined` — services
|
|
120
|
+
* compose first.
|
|
121
|
+
*
|
|
122
|
+
* The catalogue behind it is memoized, because a workspace-wide validation
|
|
123
|
+
* renders once per diagnostic and the naive override — parse a JSON file,
|
|
124
|
+
* build a map — then pays that per diagnostic rather than per locale.
|
|
125
|
+
*/
|
|
126
|
+
protected render(message: ResolvedMessage): string;
|
|
127
|
+
/**
|
|
128
|
+
* Emit a failed render. Logged rather than swallowed: the fallback output is
|
|
129
|
+
* byte-identical to a correctly-configured default, so a throwing catalogue
|
|
130
|
+
* is otherwise invisible.
|
|
131
|
+
*/
|
|
132
|
+
protected reportFailure(err: unknown, carrier: string): void;
|
|
133
|
+
/** Format the failed-render line. Override to name the adopter's catalogue entry. */
|
|
134
|
+
protected formatRenderFailure(err: unknown, carrier: string): string;
|
|
135
|
+
}
|
|
136
|
+
//# sourceMappingURL=renderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.d.ts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,gBAAgB,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM;IAUhD;;;;OAIG;IACH,WAAW,CAAC,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,GAAG,MAAM;IAUlD;;;;;;;;;;;;OAYG;IACH,aAAa,CAAC,CAAC,SAAS,MAAM,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,MAAM;IAkB/F;;;;;;;;;;;;;OAaG;IACH,SAAS,CAAC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,SAAS;IAI1F;;;;;;;;;;OAUG;IACH,SAAS,CAAC,MAAM,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM;IAQlD;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAI5D,qFAAqF;IACrF,SAAS,CAAC,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;CAGtE"}
|
|
@@ -0,0 +1,159 @@
|
|
|
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
|
+
import { describeError, renderFrameworkMessage, resolve, resolvedFromResponseError } from '@hydranium/protocol';
|
|
10
|
+
import { SimpleCache } from '@hydranium/langium';
|
|
11
|
+
import { Diagnostic } from 'vscode-languageserver-protocol';
|
|
12
|
+
import { resolvedFromDiagnostic } from './carriers.js';
|
|
13
|
+
/**
|
|
14
|
+
* Renders every user-facing message the server sends, in the locale the server
|
|
15
|
+
* was handed at init. The framework ships no catalogue, so its own behaviour is
|
|
16
|
+
* a pass-through.
|
|
17
|
+
*
|
|
18
|
+
* Adopters override {@link translationsFor}: the public render methods carry
|
|
19
|
+
* the no-throw contract, and the catalogue lookup they wrap is what can fail.
|
|
20
|
+
*
|
|
21
|
+
* Two render methods rather than one, because what is useful to an adopter is
|
|
22
|
+
* the carrier's structured fields and the two carriers have different ones. A
|
|
23
|
+
* single `render(text)` would force an adopter to match English prose, which
|
|
24
|
+
* breaks on the first Langium reword.
|
|
25
|
+
*/
|
|
26
|
+
export class DefaultMessageRenderer {
|
|
27
|
+
tracer;
|
|
28
|
+
serverLocale;
|
|
29
|
+
/**
|
|
30
|
+
* {@link translationsFor}'s answer per locale, `undefined` answers included —
|
|
31
|
+
* a `SimpleCache` distinguishes "absent" from "cached as none", which matters
|
|
32
|
+
* because shipping no catalogue is the framework's own hot path.
|
|
33
|
+
*
|
|
34
|
+
* `SimpleCache` rather than Langium's `WorkspaceCache`: the eviction axis
|
|
35
|
+
* there is document change, and a catalogue does not depend on documents, so
|
|
36
|
+
* it would evict on every build AND put a `DocumentBuilder` dependency on a
|
|
37
|
+
* service the shared tier declares free of one. Nothing evicts this: the
|
|
38
|
+
* locale arrives once per process. A subclass whose catalogue can change
|
|
39
|
+
* clears it.
|
|
40
|
+
*/
|
|
41
|
+
catalogues = new SimpleCache();
|
|
42
|
+
constructor(services, options = {}) {
|
|
43
|
+
this.serverLocale = services.ServerLocale;
|
|
44
|
+
this.tracer = services.Tracer.for(options.logName ?? 'MessageRenderer').trace('instantiated');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The sentence to publish for `diagnostic`, replacing its current `message`.
|
|
48
|
+
* Sees lexer and parser errors too, which Langium pushes onto the document
|
|
49
|
+
* without routing them through `toDiagnostic`.
|
|
50
|
+
*
|
|
51
|
+
* **Must not throw**, which is why the guard is here and not at the call
|
|
52
|
+
* site: this runs inside the `Validated` phase, and Langium's
|
|
53
|
+
* `notifyDocumentPhase` rethrows anything that is not a cancellation — so an
|
|
54
|
+
* escaping error leaves the document AT `Validated` with the phase's
|
|
55
|
+
* listeners never run, and the client receives no diagnostics for that file.
|
|
56
|
+
* A subclass overriding this method takes that contract on itself.
|
|
57
|
+
*/
|
|
58
|
+
renderDiagnostic(diagnostic) {
|
|
59
|
+
try {
|
|
60
|
+
const resolved = resolvedFromDiagnostic(diagnostic);
|
|
61
|
+
return resolved ? this.render(resolved) : Diagnostic.getMessageString(diagnostic);
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
this.reportFailure(err, 'a diagnostic');
|
|
65
|
+
return Diagnostic.getMessageString(diagnostic);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* The sentence to send for `error`, replacing its current `message`. Same
|
|
70
|
+
* no-throw contract as {@link renderDiagnostic}: an escaping error replaces a
|
|
71
|
+
* typed rejection the caller can handle with one it cannot.
|
|
72
|
+
*/
|
|
73
|
+
renderError(error) {
|
|
74
|
+
try {
|
|
75
|
+
const resolved = resolvedFromResponseError(error);
|
|
76
|
+
return resolved ? this.render(resolved) : error.message;
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
this.reportFailure(err, 'an RPC error');
|
|
80
|
+
return error.message;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The sentence for a declaration the caller holds directly, for a carrier
|
|
85
|
+
* with no slot to put an identity in.
|
|
86
|
+
*
|
|
87
|
+
* GLSP's action protocol is the case: every member of its message, status
|
|
88
|
+
* and reject actions is prose or an enum, so a code cannot travel and the
|
|
89
|
+
* raise site is the last place that still knows which message this is.
|
|
90
|
+
* Prefer {@link renderDiagnostic} / {@link renderError} wherever a carrier
|
|
91
|
+
* does hold the identity — they keep the render off the raise site, so an
|
|
92
|
+
* adopter's own messages ride the same one binding.
|
|
93
|
+
*
|
|
94
|
+
* Same no-throw contract as the carrier methods.
|
|
95
|
+
*/
|
|
96
|
+
renderMessage(message, ...params) {
|
|
97
|
+
// `resolve` is inside the guard with the render, not before it: it calls
|
|
98
|
+
// the declaration's own `format`, which for an adopter declaration is
|
|
99
|
+
// arbitrary code, and a throw there would escape a method whose contract
|
|
100
|
+
// says it cannot.
|
|
101
|
+
let resolved;
|
|
102
|
+
try {
|
|
103
|
+
resolved = resolve(message, ...params);
|
|
104
|
+
return this.render(resolved);
|
|
105
|
+
}
|
|
106
|
+
catch (err) {
|
|
107
|
+
this.reportFailure(err, `the message '${message.code}'`);
|
|
108
|
+
// Unset only when `format` ITSELF threw, which leaves the
|
|
109
|
+
// uninterpolated template as the only text there is. A failed render
|
|
110
|
+
// still has the resolved English.
|
|
111
|
+
return resolved?.text ?? message.text;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* The catalogue for the current locale, or `undefined` for none — the
|
|
116
|
+
* framework's answer, shipping none. Overriding this leaves every identity
|
|
117
|
+
* decision, every pass-through and the no-throw guard in place.
|
|
118
|
+
*
|
|
119
|
+
* **Called once per locale, not once per message**, so an override may load
|
|
120
|
+
* a file or build a map without that cost landing per diagnostic. The
|
|
121
|
+
* corollary is that a catalogue mutated in place afterwards is not seen;
|
|
122
|
+
* clear {@link catalogues} to invalidate.
|
|
123
|
+
*
|
|
124
|
+
* An adopter wanting Langium's own uncoded sentences instead matches
|
|
125
|
+
* `Diagnostic.data.code` from an overridden {@link renderDiagnostic}, never
|
|
126
|
+
* the sentence.
|
|
127
|
+
*/
|
|
128
|
+
translationsFor(_locale) {
|
|
129
|
+
return undefined;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Resolve one identity against the current locale's catalogue.
|
|
133
|
+
*
|
|
134
|
+
* Reads the locale per call. Copying it into a field at construction pins
|
|
135
|
+
* whatever was there before init ran, which is always `undefined` — services
|
|
136
|
+
* compose first.
|
|
137
|
+
*
|
|
138
|
+
* The catalogue behind it is memoized, because a workspace-wide validation
|
|
139
|
+
* renders once per diagnostic and the naive override — parse a JSON file,
|
|
140
|
+
* build a map — then pays that per diagnostic rather than per locale.
|
|
141
|
+
*/
|
|
142
|
+
render(message) {
|
|
143
|
+
const locale = this.serverLocale.value;
|
|
144
|
+
return renderFrameworkMessage(message, this.catalogues.get(locale, () => this.translationsFor(locale)));
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Emit a failed render. Logged rather than swallowed: the fallback output is
|
|
148
|
+
* byte-identical to a correctly-configured default, so a throwing catalogue
|
|
149
|
+
* is otherwise invisible.
|
|
150
|
+
*/
|
|
151
|
+
reportFailure(err, carrier) {
|
|
152
|
+
this.tracer.error(this.formatRenderFailure(err, carrier));
|
|
153
|
+
}
|
|
154
|
+
/** Format the failed-render line. Override to name the adopter's catalogue entry. */
|
|
155
|
+
formatRenderFailure(err, carrier) {
|
|
156
|
+
return `rendering ${carrier} failed; falling back to the server's own text. ${describeError(err)}`;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"renderer.js","sourceRoot":"","sources":["../../src/messages/renderer.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EACJ,aAAa,EACb,sBAAsB,EACtB,OAAO,EACP,yBAAyB,EAK3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEjD,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAI5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAC;AAyBvD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,sBAAsB;IACb,MAAM,CAAS;IACf,YAAY,CAAe;IAC9C;;;;;;;;;;;OAWG;IACgB,UAAU,GAAG,IAAI,WAAW,EAA0D,CAAC;IAE1G,YAAY,QAAqC,EAAE,UAAkC,EAAE;QACpF,IAAI,CAAC,YAAY,GAAG,QAAQ,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