@hydranium/core 1.0.0-next.7 → 1.0.0-next.70
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 +58 -5
- package/lib/documents/ast-document-manager.d.ts.map +1 -1
- package/lib/documents/ast-document-manager.js +50 -18
- 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 +51 -17
- package/lib/documents/hydranium-text-documents.d.ts.map +1 -1
- package/lib/documents/hydranium-text-documents.js +136 -40
- 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 +103 -7
- package/lib/langium/model-service/model-service.d.ts.map +1 -1
- package/lib/langium/model-service/model-service.js +70 -89
- package/lib/langium/model-service/model-service.js.map +1 -1
- package/lib/langium/module.d.ts +82 -13
- 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 +10 -0
- package/lib/langium/naming/name-provider.d.ts.map +1 -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 +33 -2
- package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
- package/lib/langium/transfer/transfer-encoder.js +14 -3
- package/lib/langium/transfer/transfer-encoder.js.map +1 -1
- package/lib/langium/validation/document-validator.d.ts +145 -6
- package/lib/langium/validation/document-validator.d.ts.map +1 -1
- package/lib/langium/validation/document-validator.js +211 -4
- 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/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/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 +14 -3
- 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 +31 -4
- 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 +3 -4
- package/lib/testing/stub-ast-document-manager.d.ts.map +1 -1
- package/lib/testing/stub-ast-document-manager.js +2 -5
- 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-model-service.d.ts +1 -1
- 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 +99 -23
- package/src/documents/client-ids.ts +5 -22
- package/src/documents/hydranium-text-documents.ts +161 -55
- 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 +145 -22
- package/src/langium/module.ts +104 -19
- package/src/langium/naming/name-provider.ts +10 -0
- 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 +45 -3
- package/src/langium/validation/document-validator.ts +255 -8
- 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/messages/carriers.ts +78 -0
- package/src/messages/index.ts +27 -0
- package/src/messages/renderer.ts +204 -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 +22 -4
- package/src/testing/make-noop-shared-services.ts +50 -2
- package/src/testing/make-test-services.ts +49 -7
- 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 +5 -10
- package/src/testing/stub-document-builder.ts +32 -3
- package/src/testing/stub-model-service.ts +2 -2
- 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,87 @@
|
|
|
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 URI } from '@hydranium/langium';
|
|
11
|
+
|
|
12
|
+
/** What a build is about, handed to `HydraniumDocumentBuilder.createBuildSession`. */
|
|
13
|
+
export interface BuildSessionContext {
|
|
14
|
+
/**
|
|
15
|
+
* Which entry point opened the build: `'build'` is the workspace-wide pass
|
|
16
|
+
* (initialization), `'update'` an incremental rebuild. A subclass deriving
|
|
17
|
+
* cascade state skips the work for `'build'`, where every document is in the
|
|
18
|
+
* set already and `shouldRelink` is never consulted.
|
|
19
|
+
*/
|
|
20
|
+
readonly kind: 'build' | 'update';
|
|
21
|
+
/** Formatted description of what caused the build — a URI, a count summary. */
|
|
22
|
+
readonly trigger: string;
|
|
23
|
+
/** True when {@link trigger} already states the document count. */
|
|
24
|
+
readonly triggerCountsDocs: boolean;
|
|
25
|
+
/** URIs the build was asked to rebuild, already flattened and canonicalized. */
|
|
26
|
+
readonly changed: readonly URI[];
|
|
27
|
+
/** URIs the build was asked to delete, already expanded by `collectDeletedURIs`. Empty for a `build` call. */
|
|
28
|
+
readonly deleted: readonly URI[];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One rebuild, treated as a correlated unit.
|
|
33
|
+
*
|
|
34
|
+
* Everything a build phase needs to know about the build it belongs to — what
|
|
35
|
+
* triggered it, when it started, whether it was cancelled, and the log lines it
|
|
36
|
+
* has produced so far. A `HydraniumDocumentBuilder` opens one per `update` /
|
|
37
|
+
* `build` call and holds it for the duration, so a per-phase hook can reach
|
|
38
|
+
* build-wide facts that no per-line formatting hook could.
|
|
39
|
+
*
|
|
40
|
+
* **Identity is the object, not {@link traceId}.** `Tracer.time` short-circuits
|
|
41
|
+
* when its log level is suppressed and never calls `captureId`, so `traceId` is
|
|
42
|
+
* `undefined` on every build in a production configuration that logs above
|
|
43
|
+
* `debug`. A teardown guard keyed on the id would then compare `undefined`
|
|
44
|
+
* against `undefined` and let a preempted build clear its successor's state.
|
|
45
|
+
* Reference equality against `HydraniumDocumentBuilder.activeSession` holds in
|
|
46
|
+
* both configurations, which is why nothing here is keyed on the id.
|
|
47
|
+
*
|
|
48
|
+
* Adopters carrying build-scoped state of their own subclass this and return it
|
|
49
|
+
* from `HydraniumDocumentBuilder.createBuildSession`, narrowing with an
|
|
50
|
+
* `instanceof` where they read it back. That buys them the framework's
|
|
51
|
+
* preemption-correct teardown rather than a second copy of it.
|
|
52
|
+
*/
|
|
53
|
+
export class BuildSession {
|
|
54
|
+
/**
|
|
55
|
+
* `Tracer.time` correlation id, so a phase line and the build line share a
|
|
56
|
+
* `#N`. `undefined` until the timer starts, and permanently `undefined` when
|
|
57
|
+
* the timing line is suppressed.
|
|
58
|
+
*/
|
|
59
|
+
traceId?: number;
|
|
60
|
+
/** Set when the build ended in `OperationCancelled`, so the successor can tag itself "cancels #N". */
|
|
61
|
+
cancelled = false;
|
|
62
|
+
/** Phase-reached lines produced so far; the first one measures from {@link startMs} rather than from the previous phase. */
|
|
63
|
+
phasesLogged = 0;
|
|
64
|
+
/** Lines held back by {@link detailThresholdMs}; flushed or dropped when the build ends. */
|
|
65
|
+
readonly bufferedLines: string[] = [];
|
|
66
|
+
|
|
67
|
+
constructor(
|
|
68
|
+
/** Millisecond timestamp the build started at, on the same clock as `performance.now()`. */
|
|
69
|
+
readonly startMs: number,
|
|
70
|
+
/** What caused this build — a formatted URI, a count summary, or an adopter label. */
|
|
71
|
+
readonly trigger: string,
|
|
72
|
+
/** True when {@link trigger} already states the document count, so a phase line must not repeat it. */
|
|
73
|
+
readonly triggerCountsDocs: boolean,
|
|
74
|
+
/**
|
|
75
|
+
* Build duration at or above which the buffered lines are emitted; `0`
|
|
76
|
+
* disables buffering entirely. Captured per session so the flush decision
|
|
77
|
+
* uses the same value the buffering decision did, even if the underlying
|
|
78
|
+
* observable changed mid-build.
|
|
79
|
+
*/
|
|
80
|
+
readonly detailThresholdMs: number
|
|
81
|
+
) {}
|
|
82
|
+
|
|
83
|
+
/** True while lines are being held rather than emitted as they are produced. */
|
|
84
|
+
get buffers(): boolean {
|
|
85
|
+
return this.detailThresholdMs > 0;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { type Clock, type LogThreshold, type MaybeObservableValue, ObservableValue, type Tracer } from '@hydranium/protocol';
|
|
11
11
|
import {
|
|
12
|
+
type AstNode,
|
|
12
13
|
type BuildOptions,
|
|
13
14
|
DefaultDocumentBuilder,
|
|
14
15
|
type DocumentPhaseListener,
|
|
@@ -20,12 +21,17 @@ import {
|
|
|
20
21
|
interruptAndCheck,
|
|
21
22
|
isOperationCancelled
|
|
22
23
|
} from '@hydranium/langium';
|
|
23
|
-
|
|
24
|
+
// `Diagnostic` as a VALUE: `renderDiagnostics` needs its `getMessageString`
|
|
25
|
+
// namespace helper to read the `string | MarkupContent` union without
|
|
26
|
+
// restating it.
|
|
27
|
+
import { CancellationToken, Diagnostic } from 'vscode-languageserver-protocol';
|
|
24
28
|
import { type LogNameOptions } from '../diagnostics/logger.js';
|
|
29
|
+
import type { MessageRenderer } from '../../messages/renderer.js';
|
|
25
30
|
import { CST_REHYDRATION_RESET_STATE, isCstShed } from '../residency/cst-residency-service.js';
|
|
26
31
|
import { type ExtendedServiceRegistry } from '../service-registry.js';
|
|
27
32
|
import { type ServerSharedServicesMinimal } from '../shared-services.js';
|
|
28
33
|
import { type DocumentUriPolicy } from '../workspace/document-uri-policy.js';
|
|
34
|
+
import { BuildSession, type BuildSessionContext } from './build-session.js';
|
|
29
35
|
import { type LabeledPhaseListener, labelPhaseListener } from './labeled-phase-listener.js';
|
|
30
36
|
|
|
31
37
|
/** Document states a phase-reached line is emitted for by default — every built phase. */
|
|
@@ -78,6 +84,18 @@ export interface DocumentBuilderOptions extends LogNameOptions {
|
|
|
78
84
|
* logged. Default: `25`. Read per phase; accepts a {@link MaybeObservableValue}.
|
|
79
85
|
*/
|
|
80
86
|
readonly slowBuildMs?: MaybeObservableValue<number>;
|
|
87
|
+
/**
|
|
88
|
+
* Build duration at or above which a build's phase-reached and slow-listener
|
|
89
|
+
* lines are emitted; they are held for the duration of the build and dropped
|
|
90
|
+
* when it finishes faster. Default `0` — no buffering, every line emitted as
|
|
91
|
+
* it is produced, which is the only setting that keeps lines interleaved with
|
|
92
|
+
* the rest of the log in real time.
|
|
93
|
+
*
|
|
94
|
+
* Set it to make a fast rebuild log nothing but its one build line. The
|
|
95
|
+
* decision needs the build's TOTAL duration, so it cannot be made by any
|
|
96
|
+
* per-line hook. Read once per build; accepts a {@link MaybeObservableValue}.
|
|
97
|
+
*/
|
|
98
|
+
readonly phaseDetailMs?: MaybeObservableValue<number>;
|
|
81
99
|
/**
|
|
82
100
|
* Refresh cross-document `ComputedScopes` derivations when a referencing
|
|
83
101
|
* document is cascade-rebuilt (see
|
|
@@ -105,15 +123,24 @@ export interface DocumentBuilderOptions extends LogNameOptions {
|
|
|
105
123
|
* - **In-place rebuild helpers** — {@link reparse} and
|
|
106
124
|
* {@link reparseAndRelink} — for a build-phase listener that mutated a
|
|
107
125
|
* document's AST and must reconcile it within the same build.
|
|
108
|
-
* - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics})
|
|
126
|
+
* - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}), followed
|
|
127
|
+
* by the **one server-side message render** every head inherits
|
|
128
|
+
* ({@link renderDiagnostics}).
|
|
129
|
+
* - **Build sessions** ({@link BuildSession}): each `update` / `build` call is
|
|
130
|
+
* one correlated unit carrying an id, a trigger label, a start time and
|
|
131
|
+
* cancellation lineage, so every line of a rebuild reads as belonging to it
|
|
132
|
+
* and a preempted build is distinguishable from the winner.
|
|
109
133
|
* - **Logging instrumentation** (default on, opt-out via `logLevel: 'off'`):
|
|
110
|
-
* phase-reached lines, slow-listener breakdowns on
|
|
111
|
-
* and slow-build-phase totals on `notifyBuildPhase`.
|
|
134
|
+
* a per-build line, phase-reached lines, slow-listener breakdowns on
|
|
135
|
+
* `notifyDocumentPhase`, and slow-build-phase totals on `notifyBuildPhase`.
|
|
112
136
|
*
|
|
113
137
|
* Adopters extend this class — the configuration knobs cover what most
|
|
114
138
|
* adopters need; the `format*Line` methods, `formatUri`, and
|
|
115
139
|
* `collectDeletedURIs` are protected so subclasses can customise wording or
|
|
116
|
-
* domain-aware cascades without re-implementing surrounding logic.
|
|
140
|
+
* domain-aware cascades without re-implementing surrounding logic. An adopter
|
|
141
|
+
* with build-scoped state of its own subclasses {@link BuildSession} and
|
|
142
|
+
* overrides {@link createBuildSession}, which puts that state under the same
|
|
143
|
+
* preemption-correct teardown rather than a reimplementation of it.
|
|
117
144
|
*/
|
|
118
145
|
export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
119
146
|
protected readonly tracer: Tracer;
|
|
@@ -127,8 +154,11 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
127
154
|
protected readonly slowListenerMs: ObservableValue<number>;
|
|
128
155
|
/** Live slow-build-phase-total threshold; read `.value` per phase. */
|
|
129
156
|
protected readonly slowBuildMs: ObservableValue<number>;
|
|
157
|
+
/** Live phase-detail buffering threshold; read `.value` once per build, onto the session. */
|
|
158
|
+
protected readonly phaseDetailMs: ObservableValue<number>;
|
|
130
159
|
protected readonly uriPolicy: DocumentUriPolicy;
|
|
131
160
|
protected readonly clock: Clock;
|
|
161
|
+
protected readonly messageRenderer: MessageRenderer;
|
|
132
162
|
/** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
|
|
133
163
|
protected readonly languageRegistry: ExtendedServiceRegistry;
|
|
134
164
|
protected languageFileExtensions: string[] = [];
|
|
@@ -139,18 +169,36 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
139
169
|
protected readonly refreshCrossDocumentComputedScopes: boolean;
|
|
140
170
|
/** LSP event name (e.g. `'didChangeWatchedFiles'`) staged for the next `update()` call. */
|
|
141
171
|
protected pendingUpdateReason?: string;
|
|
172
|
+
/**
|
|
173
|
+
* The build currently in progress, or `undefined` between builds.
|
|
174
|
+
*
|
|
175
|
+
* A subclass carrying its own build-scoped state returns a {@link BuildSession}
|
|
176
|
+
* subclass from {@link createBuildSession} and narrows this with a typeguard
|
|
177
|
+
* where it reads that state — rather than redeclaring the field, whose
|
|
178
|
+
* initialiser would run after `super()` and clear a session opened during
|
|
179
|
+
* construction.
|
|
180
|
+
*/
|
|
181
|
+
protected activeSession?: BuildSession;
|
|
182
|
+
/**
|
|
183
|
+
* `traceId` of the last build that ended in cancellation, for the successor's
|
|
184
|
+
* "cancels #N" tag. Held here rather than on a session because the session
|
|
185
|
+
* that carries it is already gone by the time its successor is opened.
|
|
186
|
+
*/
|
|
187
|
+
protected lastCancelledTraceId?: number;
|
|
142
188
|
|
|
143
189
|
constructor(services: ServerSharedServicesMinimal, options: DocumentBuilderOptions = {}) {
|
|
144
190
|
super(services);
|
|
145
191
|
this.languageRegistry = services.ServiceRegistry;
|
|
146
192
|
this.uriPolicy = services.workspace.DocumentUriPolicy;
|
|
147
193
|
this.clock = services.Clock;
|
|
194
|
+
this.messageRenderer = services.MessageRenderer;
|
|
148
195
|
this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
|
|
149
196
|
this.logLevel = options.logLevel ?? 'debug';
|
|
150
197
|
this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
|
|
151
198
|
this.slowPhaseMs = ObservableValue.from(options.slowPhaseMs ?? 25);
|
|
152
199
|
this.slowListenerMs = ObservableValue.from(options.slowListenerMs ?? 5);
|
|
153
200
|
this.slowBuildMs = ObservableValue.from(options.slowBuildMs ?? 25);
|
|
201
|
+
this.phaseDetailMs = ObservableValue.from(options.phaseDetailMs ?? 0);
|
|
154
202
|
this.refreshCrossDocumentComputedScopes = options.refreshCrossDocumentComputedScopes ?? false;
|
|
155
203
|
if (this.logLevel !== 'off') {
|
|
156
204
|
this.registerPhaseListeners();
|
|
@@ -193,7 +241,16 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
193
241
|
const doc = this.langiumDocuments.getDocument(UriUtils.toUri(this.uriPolicy.canonicalUri(uri)));
|
|
194
242
|
const docState = doc ? DocumentState[doc.state] : 'unknown (document not loaded)';
|
|
195
243
|
const lastPhase = this.lastPhaseMs > 0 ? `${Math.round(performance.now() - this.lastPhaseMs)}ms ago` : 'no phase observed';
|
|
196
|
-
return `current state: '${docState}', last phase: ${lastPhase}`;
|
|
244
|
+
return `current state: '${docState}', last phase: ${lastPhase}, active build: ${this.formatSession(this.activeSession)}`;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/** Render a session for a status line. `undefined` — no build in progress — reads as `none`. */
|
|
248
|
+
protected formatSession(session: BuildSession | undefined): string {
|
|
249
|
+
if (!session) {
|
|
250
|
+
return 'none';
|
|
251
|
+
}
|
|
252
|
+
const id = session.traceId !== undefined ? `#${session.traceId}` : 'untimed';
|
|
253
|
+
return `${id} (${session.trigger}, ${Math.round(performance.now() - session.startMs)}ms in)`;
|
|
197
254
|
}
|
|
198
255
|
|
|
199
256
|
// ============================================================
|
|
@@ -409,7 +466,35 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
409
466
|
this.ensureLanguageFileExtensions();
|
|
410
467
|
const changedURIs = changed.flatMap(uri => this.flattenAndAdaptURI(uri));
|
|
411
468
|
const deletedURIs = deleted.flatMap(uri => this.collectDeletedURIs(uri));
|
|
412
|
-
return
|
|
469
|
+
return this.runInSession(
|
|
470
|
+
{
|
|
471
|
+
kind: 'update',
|
|
472
|
+
trigger: this.buildTriggerLabel(changedURIs, deletedURIs),
|
|
473
|
+
triggerCountsDocs: changedURIs.length + deletedURIs.length !== 1,
|
|
474
|
+
changed: changedURIs,
|
|
475
|
+
deleted: deletedURIs
|
|
476
|
+
},
|
|
477
|
+
this.rebuildLabel(changedURIs, deletedURIs),
|
|
478
|
+
() => super.update(changedURIs, deletedURIs, cancelToken)
|
|
479
|
+
);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
/**
|
|
483
|
+
* The workspace-initialization entry point, bracketed by a session like
|
|
484
|
+
* {@link update}. Langium's `update` reaches `buildDocuments` directly rather
|
|
485
|
+
* than through here, so the two never nest.
|
|
486
|
+
*/
|
|
487
|
+
override build<T extends AstNode>(
|
|
488
|
+
documents: Array<LangiumDocument<T>>,
|
|
489
|
+
options?: BuildOptions,
|
|
490
|
+
cancelToken?: CancellationToken
|
|
491
|
+
): Promise<void> {
|
|
492
|
+
const uris = documents.map(document => document.uri);
|
|
493
|
+
return this.runInSession(
|
|
494
|
+
{ kind: 'build', trigger: `${documents.length} docs`, triggerCountsDocs: true, changed: uris, deleted: [] },
|
|
495
|
+
`Build documents (${documents.length} docs)`,
|
|
496
|
+
() => super.build(documents, options, cancelToken)
|
|
497
|
+
);
|
|
413
498
|
}
|
|
414
499
|
|
|
415
500
|
/**
|
|
@@ -615,6 +700,149 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
615
700
|
];
|
|
616
701
|
}
|
|
617
702
|
|
|
703
|
+
// ============================================================
|
|
704
|
+
// Build sessions — one rebuild as a correlated unit
|
|
705
|
+
// ============================================================
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Open a session, run `body` inside it, and close it — the bracket every
|
|
709
|
+
* line of a rebuild is emitted within.
|
|
710
|
+
*
|
|
711
|
+
* The session is installed **synchronously**, before the timed body runs, so
|
|
712
|
+
* that state a subclass computed in {@link createBuildSession} is already
|
|
713
|
+
* readable by the time Langium's `update` consults `shouldRelink`.
|
|
714
|
+
*
|
|
715
|
+
* Teardown is preemption-correct, which is the reason this is framework code
|
|
716
|
+
* rather than a recipe. Langium's write mutex cancels an in-flight build when
|
|
717
|
+
* a later one arrives, so two sessions overlap: the successor installs itself
|
|
718
|
+
* as {@link activeSession} while the predecessor is still unwinding, and the
|
|
719
|
+
* predecessor's `finally` runs LAST. Clearing unconditionally there would
|
|
720
|
+
* discard the winner's state mid-build. Only the session that is still
|
|
721
|
+
* current clears — and the check is reference equality on the session object,
|
|
722
|
+
* not on {@link BuildSession.traceId}, which is `undefined` for every build
|
|
723
|
+
* whenever the timing level is suppressed and would compare equal to itself
|
|
724
|
+
* across two different builds.
|
|
725
|
+
*
|
|
726
|
+
* Re-entrancy is not hypothetical even without an adopter: {@link
|
|
727
|
+
* requeueOrphaned} calls `update` from inside a wait, while a build may be
|
|
728
|
+
* running.
|
|
729
|
+
*/
|
|
730
|
+
protected runInSession(context: BuildSessionContext, label: string, body: () => Promise<void>): Promise<void> {
|
|
731
|
+
// Read before installing the new session: the id being superseded belongs
|
|
732
|
+
// to the OUTGOING build, or — when the previous one already finished
|
|
733
|
+
// cancelled — to the id it parked for its successor.
|
|
734
|
+
const supersededId = this.activeSession?.traceId ?? this.lastCancelledTraceId;
|
|
735
|
+
this.lastCancelledTraceId = undefined;
|
|
736
|
+
const reason = this.pendingUpdateReason;
|
|
737
|
+
this.pendingUpdateReason = undefined;
|
|
738
|
+
const tags: string[] = [];
|
|
739
|
+
if (reason) {
|
|
740
|
+
tags.push(`event: ${reason}`);
|
|
741
|
+
}
|
|
742
|
+
if (supersededId !== undefined) {
|
|
743
|
+
tags.push(`cancels #${supersededId}`);
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
const session = this.createBuildSession(context);
|
|
747
|
+
this.activeSession = session;
|
|
748
|
+
// A phase's "since previous phase" must measure from the build's start,
|
|
749
|
+
// not from whenever the last build's final phase happened to land.
|
|
750
|
+
this.lastPhaseMs = session.startMs;
|
|
751
|
+
return this.tracer.time(
|
|
752
|
+
label,
|
|
753
|
+
async () => {
|
|
754
|
+
try {
|
|
755
|
+
await body();
|
|
756
|
+
} catch (err: unknown) {
|
|
757
|
+
if (isOperationCancelled(err)) {
|
|
758
|
+
session.cancelled = true;
|
|
759
|
+
}
|
|
760
|
+
throw err;
|
|
761
|
+
} finally {
|
|
762
|
+
this.endSession(session);
|
|
763
|
+
}
|
|
764
|
+
},
|
|
765
|
+
this.logLevel,
|
|
766
|
+
{
|
|
767
|
+
logAfterMs: 0,
|
|
768
|
+
forceMemoryAboveMs: session.buffers ? session.detailThresholdMs : undefined,
|
|
769
|
+
captureId: id => {
|
|
770
|
+
session.traceId = id;
|
|
771
|
+
},
|
|
772
|
+
tags
|
|
773
|
+
}
|
|
774
|
+
);
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
/**
|
|
778
|
+
* Construct the session for one build. Override to return a
|
|
779
|
+
* {@link BuildSession} subclass carrying adopter build-scoped state — it is
|
|
780
|
+
* called before the build body, so anything derived here is readable
|
|
781
|
+
* throughout it.
|
|
782
|
+
*/
|
|
783
|
+
protected createBuildSession(context: BuildSessionContext): BuildSession {
|
|
784
|
+
return new BuildSession(performance.now(), context.trigger, context.triggerCountsDocs, this.phaseDetailMs.value);
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
/**
|
|
788
|
+
* Close `session`: flush what it buffered, then release it if it is still the
|
|
789
|
+
* current one (see {@link runInSession} on why that check is conditional).
|
|
790
|
+
* The flush is unconditional — a preempted build's lines still describe work
|
|
791
|
+
* that happened.
|
|
792
|
+
*/
|
|
793
|
+
protected endSession(session: BuildSession): void {
|
|
794
|
+
this.flushSession(session);
|
|
795
|
+
if (this.activeSession === session) {
|
|
796
|
+
this.activeSession = undefined;
|
|
797
|
+
if (session.cancelled) {
|
|
798
|
+
this.lastCancelledTraceId = session.traceId;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
/**
|
|
804
|
+
* Emit the lines `session` held back, if it ran long enough to be worth the
|
|
805
|
+
* detail; drop them otherwise. Emits through {@link emit} rather than
|
|
806
|
+
* {@link log}, which would route them straight back into the buffer.
|
|
807
|
+
*/
|
|
808
|
+
protected flushSession(session: BuildSession): void {
|
|
809
|
+
const elapsedMs = performance.now() - session.startMs;
|
|
810
|
+
if (elapsedMs >= session.detailThresholdMs) {
|
|
811
|
+
for (const line of session.bufferedLines) {
|
|
812
|
+
this.emit(line);
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
session.bufferedLines.length = 0;
|
|
816
|
+
}
|
|
817
|
+
|
|
818
|
+
/** Label for the build's own log line. Override to customise wording. */
|
|
819
|
+
protected rebuildLabel(changed: URI[], deleted: URI[]): string {
|
|
820
|
+
if (changed.length === 0 && deleted.length === 0) {
|
|
821
|
+
return 'Rebuild documents (nothing to do)';
|
|
822
|
+
}
|
|
823
|
+
if (changed.length === 1 && deleted.length === 0) {
|
|
824
|
+
return `Rebuild document: ${this.formatUri(changed[0])}`;
|
|
825
|
+
}
|
|
826
|
+
if (changed.length === 0 && deleted.length === 1) {
|
|
827
|
+
return `Rebuild after delete: ${this.formatUri(deleted[0])}`;
|
|
828
|
+
}
|
|
829
|
+
return `Rebuild documents (${changed.length} changed, ${deleted.length} deleted)`;
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
/** Short description of what triggered the build, repeated on every phase line. Override to customise wording. */
|
|
833
|
+
protected buildTriggerLabel(changed: URI[], deleted: URI[]): string {
|
|
834
|
+
if (changed.length === 0 && deleted.length === 0) {
|
|
835
|
+
return 'nothing';
|
|
836
|
+
}
|
|
837
|
+
if (changed.length === 1 && deleted.length === 0) {
|
|
838
|
+
return this.formatUri(changed[0]);
|
|
839
|
+
}
|
|
840
|
+
if (changed.length === 0 && deleted.length === 1) {
|
|
841
|
+
return `deleted ${this.formatUri(deleted[0])}`;
|
|
842
|
+
}
|
|
843
|
+
return `${changed.length} changed, ${deleted.length} deleted`;
|
|
844
|
+
}
|
|
845
|
+
|
|
618
846
|
// ============================================================
|
|
619
847
|
// Logging — phase-reached listeners
|
|
620
848
|
// ============================================================
|
|
@@ -630,13 +858,35 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
630
858
|
const now = performance.now();
|
|
631
859
|
const elapsedMs = Math.round(now - this.lastPhaseMs);
|
|
632
860
|
this.lastPhaseMs = now;
|
|
861
|
+
// Counted before the line is formatted, so the formatter stays a pure
|
|
862
|
+
// function of state a caller can also set up in a test.
|
|
863
|
+
if (this.activeSession) {
|
|
864
|
+
this.activeSession.phasesLogged++;
|
|
865
|
+
}
|
|
633
866
|
this.log(this.phaseReachedLine(state, documents, elapsedMs));
|
|
634
867
|
}
|
|
635
868
|
|
|
636
|
-
/**
|
|
869
|
+
/**
|
|
870
|
+
* Format the phase-reached log line. Override to customise wording.
|
|
871
|
+
*
|
|
872
|
+
* Within a session the line names what triggered the build, so a phase read
|
|
873
|
+
* in isolation still says which rebuild it belongs to. `elapsedMs` is ignored
|
|
874
|
+
* for the FIRST phase of a session: it measures from the previous build's
|
|
875
|
+
* last phase, an idle gap that says nothing about this build.
|
|
876
|
+
*/
|
|
637
877
|
protected phaseReachedLine(state: DocumentState, documents: LangiumDocument[], elapsedMs: number): string {
|
|
638
|
-
const
|
|
639
|
-
|
|
878
|
+
const session = this.activeSession;
|
|
879
|
+
let docInfo: string;
|
|
880
|
+
if (session) {
|
|
881
|
+
docInfo = session.triggerCountsDocs ? `building ${session.trigger}` : `building ${session.trigger}, ${documents.length} docs`;
|
|
882
|
+
} else {
|
|
883
|
+
docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
|
|
884
|
+
}
|
|
885
|
+
const elapsedInfo =
|
|
886
|
+
session && session.phasesLogged <= 1
|
|
887
|
+
? `${Math.round(performance.now() - session.startMs)}ms since build start`
|
|
888
|
+
: `${elapsedMs}ms since previous phase`;
|
|
889
|
+
return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedInfo}]`;
|
|
640
890
|
}
|
|
641
891
|
|
|
642
892
|
// ============================================================
|
|
@@ -651,8 +901,12 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
651
901
|
// build settling inside that window therefore appends after this call has
|
|
652
902
|
// already deduped, and the appended duplicate is published by the listener
|
|
653
903
|
// of the build that deduped. Only `serializeBuilds` closes the window.
|
|
904
|
+
//
|
|
905
|
+
// Dedupe before rendering: rendering is deterministic, so it cannot
|
|
906
|
+
// change which entries are structurally equal, and fewer survive to render.
|
|
654
907
|
if (state === DocumentState.Validated) {
|
|
655
908
|
this.dedupeDiagnostics(document);
|
|
909
|
+
this.renderDiagnostics(document);
|
|
656
910
|
}
|
|
657
911
|
if (this.logLevel === 'off') {
|
|
658
912
|
return super.notifyDocumentPhase(document, state, cancelToken);
|
|
@@ -828,12 +1082,86 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
828
1082
|
}
|
|
829
1083
|
}
|
|
830
1084
|
|
|
1085
|
+
/**
|
|
1086
|
+
* Render every diagnostic on `document` through the bound message renderer,
|
|
1087
|
+
* in ONE pass over the finished list.
|
|
1088
|
+
*
|
|
1089
|
+
* All three heads read `document.diagnostics` — the LSP publish,
|
|
1090
|
+
* `TransferEncoder.toTransferDiagnostic` and the GLSP validation path — so
|
|
1091
|
+
* one pass here is what keeps the render from happening per head. It is also
|
|
1092
|
+
* the only placement that covers lexer and parser errors, which Langium
|
|
1093
|
+
* pushes onto the document without routing them through `toDiagnostic`.
|
|
1094
|
+
*
|
|
1095
|
+
* Running here rather than from a `Validated` phase listener needs no
|
|
1096
|
+
* ordering assumption: Langium publishes from `addDiagnosticsHandler`, a free
|
|
1097
|
+
* function it registers as such a listener, which can only be outrun.
|
|
1098
|
+
*
|
|
1099
|
+
* **It inherits {@link dedupeDiagnostics}'s window, and therefore the same
|
|
1100
|
+
* precondition.** A build settling inside the listener window appends
|
|
1101
|
+
* diagnostics this pass never saw, and the publisher of the build that
|
|
1102
|
+
* rendered sends them — unrendered. `ModelServiceOptions.serializeBuilds`
|
|
1103
|
+
* closes it and defaults to `true`, so "every diagnostic is rendered" holds
|
|
1104
|
+
* by default and is an opt-out rather than a guarantee. Opting out accepts
|
|
1105
|
+
* unrendered diagnostics on exactly the terms it already accepts duplicates.
|
|
1106
|
+
*
|
|
1107
|
+
* Entries are REPLACED rather than mutated: `sendDiagnostics` passes the
|
|
1108
|
+
* array by reference and serialises later, so an in-place message mutation
|
|
1109
|
+
* reaches the wire even when it runs after the publisher — which would make
|
|
1110
|
+
* a test for the ordering pass in either state.
|
|
1111
|
+
*/
|
|
1112
|
+
protected renderDiagnostics(document: LangiumDocument): void {
|
|
1113
|
+
const diagnostics = document.diagnostics;
|
|
1114
|
+
if (!diagnostics || diagnostics.length === 0) {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
let changed = false;
|
|
1118
|
+
// No try/catch: `renderDiagnostic` carries a no-throw contract, because an
|
|
1119
|
+
// error escaping this phase strands the document at `Validated` with
|
|
1120
|
+
// Langium's publisher never invoked.
|
|
1121
|
+
const rendered = diagnostics.map(diagnostic => {
|
|
1122
|
+
const text = this.messageRenderer.renderDiagnostic(diagnostic);
|
|
1123
|
+
// Against the message's STRING FORM, not the field. `renderDiagnostic`
|
|
1124
|
+
// answers a `string` by contract, while `Diagnostic.message` is
|
|
1125
|
+
// `string | MarkupContent` since LSP 3.17 — so comparing the answer
|
|
1126
|
+
// against the field never matches for a markup message, and a pass
|
|
1127
|
+
// that replaced on mismatch flattened every un-identified markup
|
|
1128
|
+
// diagnostic to its own plain text. That is silent data loss on the
|
|
1129
|
+
// path whose whole job is to leave such entries alone.
|
|
1130
|
+
if (text === Diagnostic.getMessageString(diagnostic)) {
|
|
1131
|
+
return diagnostic;
|
|
1132
|
+
}
|
|
1133
|
+
changed = true;
|
|
1134
|
+
return { ...diagnostic, message: text };
|
|
1135
|
+
});
|
|
1136
|
+
if (changed) {
|
|
1137
|
+
document.diagnostics = rendered;
|
|
1138
|
+
}
|
|
1139
|
+
}
|
|
1140
|
+
|
|
831
1141
|
// ============================================================
|
|
832
1142
|
// Internal helpers
|
|
833
1143
|
// ============================================================
|
|
834
1144
|
|
|
835
|
-
/**
|
|
1145
|
+
/**
|
|
1146
|
+
* Dispatch a log line at the configured log level; a no-op when `logLevel ===
|
|
1147
|
+
* 'off'`.
|
|
1148
|
+
*
|
|
1149
|
+
* Held on the active session when it buffers, so the "was this build worth a
|
|
1150
|
+
* per-phase breakdown" decision — which needs the build's total duration, and
|
|
1151
|
+
* so cannot be taken by anything that runs while the lines are produced — is
|
|
1152
|
+
* deferred to {@link flushSession}.
|
|
1153
|
+
*/
|
|
836
1154
|
protected log(message: string): void {
|
|
1155
|
+
const session = this.activeSession;
|
|
1156
|
+
if (session?.buffers) {
|
|
1157
|
+
session.bufferedLines.push(message);
|
|
1158
|
+
return;
|
|
1159
|
+
}
|
|
1160
|
+
this.emit(message);
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1163
|
+
/** Write a line out, bypassing session buffering. The single sink every framework log line reaches. */
|
|
1164
|
+
protected emit(message: string): void {
|
|
837
1165
|
this.tracer.logAt(this.logLevel, message);
|
|
838
1166
|
}
|
|
839
1167
|
}
|