@hydranium/core 1.0.0-next.9 → 1.0.0-next.90
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/service-registry.d.ts +5 -1
- package/lib/langium/service-registry.d.ts.map +1 -1
- package/lib/langium/service-registry.js +4 -0
- package/lib/langium/service-registry.js.map +1 -1
- package/lib/langium/shared-services.d.ts +15 -2
- package/lib/langium/shared-services.d.ts.map +1 -1
- package/lib/langium/shared-services.js.map +1 -1
- package/lib/langium/transfer/transfer-encoder.d.ts +60 -17
- package/lib/langium/transfer/transfer-encoder.d.ts.map +1 -1
- package/lib/langium/transfer/transfer-encoder.js +38 -16
- package/lib/langium/transfer/transfer-encoder.js.map +1 -1
- package/lib/langium/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/node/socket-launcher.d.ts +15 -0
- package/lib/node/socket-launcher.d.ts.map +1 -1
- package/lib/node/socket-launcher.js +3 -2
- package/lib/node/socket-launcher.js.map +1 -1
- package/lib/testing/fake-document.d.ts +16 -4
- package/lib/testing/fake-document.d.ts.map +1 -1
- package/lib/testing/fake-document.js +18 -3
- package/lib/testing/fake-document.js.map +1 -1
- package/lib/testing/make-noop-shared-services.d.ts +14 -0
- package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
- package/lib/testing/make-noop-shared-services.js +28 -2
- package/lib/testing/make-noop-shared-services.js.map +1 -1
- package/lib/testing/make-test-services.d.ts +44 -8
- package/lib/testing/make-test-services.d.ts.map +1 -1
- package/lib/testing/make-test-services.js +19 -3
- package/lib/testing/make-test-services.js.map +1 -1
- package/lib/testing/node/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/service-registry.ts +6 -2
- 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/node/socket-launcher.ts +18 -2
- package/src/testing/fake-document.ts +24 -5
- package/src/testing/make-noop-shared-services.ts +50 -2
- package/src/testing/make-test-services.ts +73 -18
- package/src/testing/node/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
|
@@ -7,12 +7,14 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import { type Clock, type LogThreshold, type MaybeObservableValue, ObservableValue, type Tracer } from '@hydranium/protocol';
|
|
10
|
-
import { type BuildOptions, DefaultDocumentBuilder, type DocumentPhaseListener, DocumentState, type LangiumDocument, type URI } from '@hydranium/langium';
|
|
10
|
+
import { type AstNode, type BuildOptions, DefaultDocumentBuilder, type DocumentPhaseListener, DocumentState, type LangiumDocument, type URI } from '@hydranium/langium';
|
|
11
11
|
import { CancellationToken } from 'vscode-languageserver-protocol';
|
|
12
12
|
import { type LogNameOptions } from '../diagnostics/logger.js';
|
|
13
|
+
import type { MessageRenderer } from '../../messages/renderer.js';
|
|
13
14
|
import { type ExtendedServiceRegistry } from '../service-registry.js';
|
|
14
15
|
import { type ServerSharedServicesMinimal } from '../shared-services.js';
|
|
15
16
|
import { type DocumentUriPolicy } from '../workspace/document-uri-policy.js';
|
|
17
|
+
import { BuildSession, type BuildSessionContext } from './build-session.js';
|
|
16
18
|
/** Document states a phase-reached line is emitted for by default — every built phase. */
|
|
17
19
|
export declare const DEFAULT_LOGGED_PHASES: DocumentState[];
|
|
18
20
|
/** Constructor options for {@link HydraniumDocumentBuilder}. */
|
|
@@ -46,6 +48,18 @@ export interface DocumentBuilderOptions extends LogNameOptions {
|
|
|
46
48
|
* logged. Default: `25`. Read per phase; accepts a {@link MaybeObservableValue}.
|
|
47
49
|
*/
|
|
48
50
|
readonly slowBuildMs?: MaybeObservableValue<number>;
|
|
51
|
+
/**
|
|
52
|
+
* Build duration at or above which a build's phase-reached and slow-listener
|
|
53
|
+
* lines are emitted; they are held for the duration of the build and dropped
|
|
54
|
+
* when it finishes faster. Default `0` — no buffering, every line emitted as
|
|
55
|
+
* it is produced, which is the only setting that keeps lines interleaved with
|
|
56
|
+
* the rest of the log in real time.
|
|
57
|
+
*
|
|
58
|
+
* Set it to make a fast rebuild log nothing but its one build line. The
|
|
59
|
+
* decision needs the build's TOTAL duration, so it cannot be made by any
|
|
60
|
+
* per-line hook. Read once per build; accepts a {@link MaybeObservableValue}.
|
|
61
|
+
*/
|
|
62
|
+
readonly phaseDetailMs?: MaybeObservableValue<number>;
|
|
49
63
|
/**
|
|
50
64
|
* Refresh cross-document `ComputedScopes` derivations when a referencing
|
|
51
65
|
* document is cascade-rebuilt (see
|
|
@@ -72,15 +86,24 @@ export interface DocumentBuilderOptions extends LogNameOptions {
|
|
|
72
86
|
* - **In-place rebuild helpers** — {@link reparse} and
|
|
73
87
|
* {@link reparseAndRelink} — for a build-phase listener that mutated a
|
|
74
88
|
* document's AST and must reconcile it within the same build.
|
|
75
|
-
* - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics})
|
|
89
|
+
* - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}), followed
|
|
90
|
+
* by the **one server-side message render** every head inherits
|
|
91
|
+
* ({@link renderDiagnostics}).
|
|
92
|
+
* - **Build sessions** ({@link BuildSession}): each `update` / `build` call is
|
|
93
|
+
* one correlated unit carrying an id, a trigger label, a start time and
|
|
94
|
+
* cancellation lineage, so every line of a rebuild reads as belonging to it
|
|
95
|
+
* and a preempted build is distinguishable from the winner.
|
|
76
96
|
* - **Logging instrumentation** (default on, opt-out via `logLevel: 'off'`):
|
|
77
|
-
* phase-reached lines, slow-listener breakdowns on
|
|
78
|
-
* and slow-build-phase totals on `notifyBuildPhase`.
|
|
97
|
+
* a per-build line, phase-reached lines, slow-listener breakdowns on
|
|
98
|
+
* `notifyDocumentPhase`, and slow-build-phase totals on `notifyBuildPhase`.
|
|
79
99
|
*
|
|
80
100
|
* Adopters extend this class — the configuration knobs cover what most
|
|
81
101
|
* adopters need; the `format*Line` methods, `formatUri`, and
|
|
82
102
|
* `collectDeletedURIs` are protected so subclasses can customise wording or
|
|
83
|
-
* domain-aware cascades without re-implementing surrounding logic.
|
|
103
|
+
* domain-aware cascades without re-implementing surrounding logic. An adopter
|
|
104
|
+
* with build-scoped state of its own subclasses {@link BuildSession} and
|
|
105
|
+
* overrides {@link createBuildSession}, which puts that state under the same
|
|
106
|
+
* preemption-correct teardown rather than a reimplementation of it.
|
|
84
107
|
*/
|
|
85
108
|
export declare class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
86
109
|
protected readonly tracer: Tracer;
|
|
@@ -94,8 +117,11 @@ export declare class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
94
117
|
protected readonly slowListenerMs: ObservableValue<number>;
|
|
95
118
|
/** Live slow-build-phase-total threshold; read `.value` per phase. */
|
|
96
119
|
protected readonly slowBuildMs: ObservableValue<number>;
|
|
120
|
+
/** Live phase-detail buffering threshold; read `.value` once per build, onto the session. */
|
|
121
|
+
protected readonly phaseDetailMs: ObservableValue<number>;
|
|
97
122
|
protected readonly uriPolicy: DocumentUriPolicy;
|
|
98
123
|
protected readonly clock: Clock;
|
|
124
|
+
protected readonly messageRenderer: MessageRenderer;
|
|
99
125
|
/** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
|
|
100
126
|
protected readonly languageRegistry: ExtendedServiceRegistry;
|
|
101
127
|
protected languageFileExtensions: string[];
|
|
@@ -106,6 +132,22 @@ export declare class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
106
132
|
protected readonly refreshCrossDocumentComputedScopes: boolean;
|
|
107
133
|
/** LSP event name (e.g. `'didChangeWatchedFiles'`) staged for the next `update()` call. */
|
|
108
134
|
protected pendingUpdateReason?: string;
|
|
135
|
+
/**
|
|
136
|
+
* The build currently in progress, or `undefined` between builds.
|
|
137
|
+
*
|
|
138
|
+
* A subclass carrying its own build-scoped state returns a {@link BuildSession}
|
|
139
|
+
* subclass from {@link createBuildSession} and narrows this with a typeguard
|
|
140
|
+
* where it reads that state — rather than redeclaring the field, whose
|
|
141
|
+
* initialiser would run after `super()` and clear a session opened during
|
|
142
|
+
* construction.
|
|
143
|
+
*/
|
|
144
|
+
protected activeSession?: BuildSession;
|
|
145
|
+
/**
|
|
146
|
+
* `traceId` of the last build that ended in cancellation, for the successor's
|
|
147
|
+
* "cancels #N" tag. Held here rather than on a session because the session
|
|
148
|
+
* that carries it is already gone by the time its successor is opened.
|
|
149
|
+
*/
|
|
150
|
+
protected lastCancelledTraceId?: number;
|
|
109
151
|
constructor(services: ServerSharedServicesMinimal, options?: DocumentBuilderOptions);
|
|
110
152
|
/**
|
|
111
153
|
* Stage an LSP event name for the next `update()` call. Adopters call before
|
|
@@ -130,6 +172,8 @@ export declare class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
130
172
|
* duplicate what this already knows.
|
|
131
173
|
*/
|
|
132
174
|
formatBuildStatus(uri: URI): string;
|
|
175
|
+
/** Render a session for a status line. `undefined` — no build in progress — reads as `none`. */
|
|
176
|
+
protected formatSession(session: BuildSession | undefined): string;
|
|
133
177
|
/**
|
|
134
178
|
* Two edge cases the default Langium implementation rejects on:
|
|
135
179
|
* - Document below target state with no build active (newly-created file):
|
|
@@ -228,6 +272,12 @@ export declare class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
228
272
|
*/
|
|
229
273
|
protected shouldRelink(document: LangiumDocument, changedUris: Set<string>): boolean;
|
|
230
274
|
update(changed: URI[], deleted: URI[], cancelToken?: CancellationToken): Promise<void>;
|
|
275
|
+
/**
|
|
276
|
+
* The workspace-initialization entry point, bracketed by a session like
|
|
277
|
+
* {@link update}. Langium's `update` reaches `buildDocuments` directly rather
|
|
278
|
+
* than through here, so the two never nest.
|
|
279
|
+
*/
|
|
280
|
+
build<T extends AstNode>(documents: Array<LangiumDocument<T>>, options?: BuildOptions, cancelToken?: CancellationToken): Promise<void>;
|
|
231
281
|
/**
|
|
232
282
|
* Refresh cross-document `ComputedScopes` derivations on cascade, when
|
|
233
283
|
* {@link refreshCrossDocumentComputedScopes} is set (default off).
|
|
@@ -340,10 +390,65 @@ export declare class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
340
390
|
* project descriptor should cascade to all its members).
|
|
341
391
|
*/
|
|
342
392
|
protected collectDeletedURIs(uri: URI): URI[];
|
|
393
|
+
/**
|
|
394
|
+
* Open a session, run `body` inside it, and close it — the bracket every
|
|
395
|
+
* line of a rebuild is emitted within.
|
|
396
|
+
*
|
|
397
|
+
* The session is installed **synchronously**, before the timed body runs, so
|
|
398
|
+
* that state a subclass computed in {@link createBuildSession} is already
|
|
399
|
+
* readable by the time Langium's `update` consults `shouldRelink`.
|
|
400
|
+
*
|
|
401
|
+
* Teardown is preemption-correct, which is the reason this is framework code
|
|
402
|
+
* rather than a recipe. Langium's write mutex cancels an in-flight build when
|
|
403
|
+
* a later one arrives, so two sessions overlap: the successor installs itself
|
|
404
|
+
* as {@link activeSession} while the predecessor is still unwinding, and the
|
|
405
|
+
* predecessor's `finally` runs LAST. Clearing unconditionally there would
|
|
406
|
+
* discard the winner's state mid-build. Only the session that is still
|
|
407
|
+
* current clears — and the check is reference equality on the session object,
|
|
408
|
+
* not on {@link BuildSession.traceId}, which is `undefined` for every build
|
|
409
|
+
* whenever the timing level is suppressed and would compare equal to itself
|
|
410
|
+
* across two different builds.
|
|
411
|
+
*
|
|
412
|
+
* Re-entrancy is not hypothetical even without an adopter: {@link
|
|
413
|
+
* requeueOrphaned} calls `update` from inside a wait, while a build may be
|
|
414
|
+
* running.
|
|
415
|
+
*/
|
|
416
|
+
protected runInSession(context: BuildSessionContext, label: string, body: () => Promise<void>): Promise<void>;
|
|
417
|
+
/**
|
|
418
|
+
* Construct the session for one build. Override to return a
|
|
419
|
+
* {@link BuildSession} subclass carrying adopter build-scoped state — it is
|
|
420
|
+
* called before the build body, so anything derived here is readable
|
|
421
|
+
* throughout it.
|
|
422
|
+
*/
|
|
423
|
+
protected createBuildSession(context: BuildSessionContext): BuildSession;
|
|
424
|
+
/**
|
|
425
|
+
* Close `session`: flush what it buffered, then release it if it is still the
|
|
426
|
+
* current one (see {@link runInSession} on why that check is conditional).
|
|
427
|
+
* The flush is unconditional — a preempted build's lines still describe work
|
|
428
|
+
* that happened.
|
|
429
|
+
*/
|
|
430
|
+
protected endSession(session: BuildSession): void;
|
|
431
|
+
/**
|
|
432
|
+
* Emit the lines `session` held back, if it ran long enough to be worth the
|
|
433
|
+
* detail; drop them otherwise. Emits through {@link emit} rather than
|
|
434
|
+
* {@link log}, which would route them straight back into the buffer.
|
|
435
|
+
*/
|
|
436
|
+
protected flushSession(session: BuildSession): void;
|
|
437
|
+
/** Label for the build's own log line. Override to customise wording. */
|
|
438
|
+
protected rebuildLabel(changed: URI[], deleted: URI[]): string;
|
|
439
|
+
/** Short description of what triggered the build, repeated on every phase line. Override to customise wording. */
|
|
440
|
+
protected buildTriggerLabel(changed: URI[], deleted: URI[]): string;
|
|
343
441
|
protected registerPhaseListeners(): void;
|
|
344
442
|
/** Called once per phase-reached event. Override to add custom side-effects beyond logging. */
|
|
345
443
|
protected onPhaseReached(state: DocumentState, documents: LangiumDocument[]): void;
|
|
346
|
-
/**
|
|
444
|
+
/**
|
|
445
|
+
* Format the phase-reached log line. Override to customise wording.
|
|
446
|
+
*
|
|
447
|
+
* Within a session the line names what triggered the build, so a phase read
|
|
448
|
+
* in isolation still says which rebuild it belongs to. `elapsedMs` is ignored
|
|
449
|
+
* for the FIRST phase of a session: it measures from the previous build's
|
|
450
|
+
* last phase, an idle gap that says nothing about this build.
|
|
451
|
+
*/
|
|
347
452
|
protected phaseReachedLine(state: DocumentState, documents: LangiumDocument[], elapsedMs: number): string;
|
|
348
453
|
notifyDocumentPhase(document: LangiumDocument, state: DocumentState, cancelToken: CancellationToken): Promise<void>;
|
|
349
454
|
/**
|
|
@@ -399,7 +504,45 @@ export declare class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
399
504
|
* serialising anything.
|
|
400
505
|
*/
|
|
401
506
|
protected dedupeDiagnostics(document: LangiumDocument): void;
|
|
402
|
-
/**
|
|
507
|
+
/**
|
|
508
|
+
* Render every diagnostic on `document` through the bound message renderer,
|
|
509
|
+
* in ONE pass over the finished list.
|
|
510
|
+
*
|
|
511
|
+
* All three heads read `document.diagnostics` — the LSP publish,
|
|
512
|
+
* `TransferEncoder.toTransferDiagnostic` and the GLSP validation path — so
|
|
513
|
+
* one pass here is what keeps the render from happening per head. It is also
|
|
514
|
+
* the only placement that covers lexer and parser errors, which Langium
|
|
515
|
+
* pushes onto the document without routing them through `toDiagnostic`.
|
|
516
|
+
*
|
|
517
|
+
* Running here rather than from a `Validated` phase listener needs no
|
|
518
|
+
* ordering assumption: Langium publishes from `addDiagnosticsHandler`, a free
|
|
519
|
+
* function it registers as such a listener, which can only be outrun.
|
|
520
|
+
*
|
|
521
|
+
* **It inherits {@link dedupeDiagnostics}'s window, and therefore the same
|
|
522
|
+
* precondition.** A build settling inside the listener window appends
|
|
523
|
+
* diagnostics this pass never saw, and the publisher of the build that
|
|
524
|
+
* rendered sends them — unrendered. `ModelServiceOptions.serializeBuilds`
|
|
525
|
+
* closes it and defaults to `true`, so "every diagnostic is rendered" holds
|
|
526
|
+
* by default and is an opt-out rather than a guarantee. Opting out accepts
|
|
527
|
+
* unrendered diagnostics on exactly the terms it already accepts duplicates.
|
|
528
|
+
*
|
|
529
|
+
* Entries are REPLACED rather than mutated: `sendDiagnostics` passes the
|
|
530
|
+
* array by reference and serialises later, so an in-place message mutation
|
|
531
|
+
* reaches the wire even when it runs after the publisher — which would make
|
|
532
|
+
* a test for the ordering pass in either state.
|
|
533
|
+
*/
|
|
534
|
+
protected renderDiagnostics(document: LangiumDocument): void;
|
|
535
|
+
/**
|
|
536
|
+
* Dispatch a log line at the configured log level; a no-op when `logLevel ===
|
|
537
|
+
* 'off'`.
|
|
538
|
+
*
|
|
539
|
+
* Held on the active session when it buffers, so the "was this build worth a
|
|
540
|
+
* per-phase breakdown" decision — which needs the build's total duration, and
|
|
541
|
+
* so cannot be taken by anything that runs while the lines are produced — is
|
|
542
|
+
* deferred to {@link flushSession}.
|
|
543
|
+
*/
|
|
403
544
|
protected log(message: string): void;
|
|
545
|
+
/** Write a line out, bypassing session buffering. The single sink every framework log line reaches. */
|
|
546
|
+
protected emit(message: string): void;
|
|
404
547
|
}
|
|
405
548
|
//# sourceMappingURL=document-builder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-builder.d.ts","sourceRoot":"","sources":["../../../src/langium/document-builder/document-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,KAAK,oBAAoB,EAAE,eAAe,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7H,OAAO,EACJ,KAAK,YAAY,EACjB,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,aAAa,EACb,KAAK,eAAe,EAEpB,KAAK,GAAG,EAIV,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"document-builder.d.ts","sourceRoot":"","sources":["../../../src/langium/document-builder/document-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;kFAOkF;AAElF,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,YAAY,EAAE,KAAK,oBAAoB,EAAE,eAAe,EAAE,KAAK,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7H,OAAO,EACJ,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,sBAAsB,EACtB,KAAK,qBAAqB,EAC1B,aAAa,EACb,KAAK,eAAe,EAEpB,KAAK,GAAG,EAIV,MAAM,oBAAoB,CAAC;AAI5B,OAAO,EAAE,iBAAiB,EAAc,MA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AE,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM;IAQhI,iHAAiH;IACjH,SAAS,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,GAAG,MAAM;IAIrC,uGAAuG;IACvG,SAAS,CAAC,cAAc,CAAC,QAAQ,EAAE,qBAAqB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAKhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACH,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAmC5D;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,SAAS,CAAC,iBAAiB,CAAC,QAAQ,EAAE,eAAe,GAAG,IAAI;IAiC5D;;;;;;;;OAQG;IACH,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IASpC,uGAAuG;IACvG,SAAS,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;CAGvC"}
|
|
@@ -8,8 +8,12 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
import { ObservableValue } from '@hydranium/protocol';
|
|
10
10
|
import { DefaultDocumentBuilder, DocumentState, OperationCancelled, UriUtils, interruptAndCheck, isOperationCancelled } from '@hydranium/langium';
|
|
11
|
-
|
|
11
|
+
// `Diagnostic` as a VALUE: `renderDiagnostics` needs its `getMessageString`
|
|
12
|
+
// namespace helper to read the `string | MarkupContent` union without
|
|
13
|
+
// restating it.
|
|
14
|
+
import { CancellationToken, Diagnostic } from 'vscode-languageserver-protocol';
|
|
12
15
|
import { CST_REHYDRATION_RESET_STATE, isCstShed } from '../residency/cst-residency-service.js';
|
|
16
|
+
import { BuildSession } from './build-session.js';
|
|
13
17
|
import { labelPhaseListener } from './labeled-phase-listener.js';
|
|
14
18
|
/** Document states a phase-reached line is emitted for by default — every built phase. */
|
|
15
19
|
export const DEFAULT_LOGGED_PHASES = [
|
|
@@ -42,15 +46,24 @@ const MAX_STALLED_REQUEUES = 3;
|
|
|
42
46
|
* - **In-place rebuild helpers** — {@link reparse} and
|
|
43
47
|
* {@link reparseAndRelink} — for a build-phase listener that mutated a
|
|
44
48
|
* document's AST and must reconcile it within the same build.
|
|
45
|
-
* - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics})
|
|
49
|
+
* - **Diagnostic dedupe** at `Validated` ({@link dedupeDiagnostics}), followed
|
|
50
|
+
* by the **one server-side message render** every head inherits
|
|
51
|
+
* ({@link renderDiagnostics}).
|
|
52
|
+
* - **Build sessions** ({@link BuildSession}): each `update` / `build` call is
|
|
53
|
+
* one correlated unit carrying an id, a trigger label, a start time and
|
|
54
|
+
* cancellation lineage, so every line of a rebuild reads as belonging to it
|
|
55
|
+
* and a preempted build is distinguishable from the winner.
|
|
46
56
|
* - **Logging instrumentation** (default on, opt-out via `logLevel: 'off'`):
|
|
47
|
-
* phase-reached lines, slow-listener breakdowns on
|
|
48
|
-
* and slow-build-phase totals on `notifyBuildPhase`.
|
|
57
|
+
* a per-build line, phase-reached lines, slow-listener breakdowns on
|
|
58
|
+
* `notifyDocumentPhase`, and slow-build-phase totals on `notifyBuildPhase`.
|
|
49
59
|
*
|
|
50
60
|
* Adopters extend this class — the configuration knobs cover what most
|
|
51
61
|
* adopters need; the `format*Line` methods, `formatUri`, and
|
|
52
62
|
* `collectDeletedURIs` are protected so subclasses can customise wording or
|
|
53
|
-
* domain-aware cascades without re-implementing surrounding logic.
|
|
63
|
+
* domain-aware cascades without re-implementing surrounding logic. An adopter
|
|
64
|
+
* with build-scoped state of its own subclasses {@link BuildSession} and
|
|
65
|
+
* overrides {@link createBuildSession}, which puts that state under the same
|
|
66
|
+
* preemption-correct teardown rather than a reimplementation of it.
|
|
54
67
|
*/
|
|
55
68
|
export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
56
69
|
tracer;
|
|
@@ -64,8 +77,11 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
64
77
|
slowListenerMs;
|
|
65
78
|
/** Live slow-build-phase-total threshold; read `.value` per phase. */
|
|
66
79
|
slowBuildMs;
|
|
80
|
+
/** Live phase-detail buffering threshold; read `.value` once per build, onto the session. */
|
|
81
|
+
phaseDetailMs;
|
|
67
82
|
uriPolicy;
|
|
68
83
|
clock;
|
|
84
|
+
messageRenderer;
|
|
69
85
|
/** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
|
|
70
86
|
languageRegistry;
|
|
71
87
|
languageFileExtensions = [];
|
|
@@ -76,17 +92,35 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
76
92
|
refreshCrossDocumentComputedScopes;
|
|
77
93
|
/** LSP event name (e.g. `'didChangeWatchedFiles'`) staged for the next `update()` call. */
|
|
78
94
|
pendingUpdateReason;
|
|
95
|
+
/**
|
|
96
|
+
* The build currently in progress, or `undefined` between builds.
|
|
97
|
+
*
|
|
98
|
+
* A subclass carrying its own build-scoped state returns a {@link BuildSession}
|
|
99
|
+
* subclass from {@link createBuildSession} and narrows this with a typeguard
|
|
100
|
+
* where it reads that state — rather than redeclaring the field, whose
|
|
101
|
+
* initialiser would run after `super()` and clear a session opened during
|
|
102
|
+
* construction.
|
|
103
|
+
*/
|
|
104
|
+
activeSession;
|
|
105
|
+
/**
|
|
106
|
+
* `traceId` of the last build that ended in cancellation, for the successor's
|
|
107
|
+
* "cancels #N" tag. Held here rather than on a session because the session
|
|
108
|
+
* that carries it is already gone by the time its successor is opened.
|
|
109
|
+
*/
|
|
110
|
+
lastCancelledTraceId;
|
|
79
111
|
constructor(services, options = {}) {
|
|
80
112
|
super(services);
|
|
81
113
|
this.languageRegistry = services.ServiceRegistry;
|
|
82
114
|
this.uriPolicy = services.workspace.DocumentUriPolicy;
|
|
83
115
|
this.clock = services.Clock;
|
|
116
|
+
this.messageRenderer = services.MessageRenderer;
|
|
84
117
|
this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
|
|
85
118
|
this.logLevel = options.logLevel ?? 'debug';
|
|
86
119
|
this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
|
|
87
120
|
this.slowPhaseMs = ObservableValue.from(options.slowPhaseMs ?? 25);
|
|
88
121
|
this.slowListenerMs = ObservableValue.from(options.slowListenerMs ?? 5);
|
|
89
122
|
this.slowBuildMs = ObservableValue.from(options.slowBuildMs ?? 25);
|
|
123
|
+
this.phaseDetailMs = ObservableValue.from(options.phaseDetailMs ?? 0);
|
|
90
124
|
this.refreshCrossDocumentComputedScopes = options.refreshCrossDocumentComputedScopes ?? false;
|
|
91
125
|
if (this.logLevel !== 'off') {
|
|
92
126
|
this.registerPhaseListeners();
|
|
@@ -126,7 +160,15 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
126
160
|
const doc = this.langiumDocuments.getDocument(UriUtils.toUri(this.uriPolicy.canonicalUri(uri)));
|
|
127
161
|
const docState = doc ? DocumentState[doc.state] : 'unknown (document not loaded)';
|
|
128
162
|
const lastPhase = this.lastPhaseMs > 0 ? `${Math.round(performance.now() - this.lastPhaseMs)}ms ago` : 'no phase observed';
|
|
129
|
-
return `current state: '${docState}', last phase: ${lastPhase}`;
|
|
163
|
+
return `current state: '${docState}', last phase: ${lastPhase}, active build: ${this.formatSession(this.activeSession)}`;
|
|
164
|
+
}
|
|
165
|
+
/** Render a session for a status line. `undefined` — no build in progress — reads as `none`. */
|
|
166
|
+
formatSession(session) {
|
|
167
|
+
if (!session) {
|
|
168
|
+
return 'none';
|
|
169
|
+
}
|
|
170
|
+
const id = session.traceId !== undefined ? `#${session.traceId}` : 'untimed';
|
|
171
|
+
return `${id} (${session.trigger}, ${Math.round(performance.now() - session.startMs)}ms in)`;
|
|
130
172
|
}
|
|
131
173
|
// ============================================================
|
|
132
174
|
// Bug-fixes (always on)
|
|
@@ -331,7 +373,22 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
331
373
|
this.ensureLanguageFileExtensions();
|
|
332
374
|
const changedURIs = changed.flatMap(uri => this.flattenAndAdaptURI(uri));
|
|
333
375
|
const deletedURIs = deleted.flatMap(uri => this.collectDeletedURIs(uri));
|
|
334
|
-
return
|
|
376
|
+
return this.runInSession({
|
|
377
|
+
kind: 'update',
|
|
378
|
+
trigger: this.buildTriggerLabel(changedURIs, deletedURIs),
|
|
379
|
+
triggerCountsDocs: changedURIs.length + deletedURIs.length !== 1,
|
|
380
|
+
changed: changedURIs,
|
|
381
|
+
deleted: deletedURIs
|
|
382
|
+
}, this.rebuildLabel(changedURIs, deletedURIs), () => super.update(changedURIs, deletedURIs, cancelToken));
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The workspace-initialization entry point, bracketed by a session like
|
|
386
|
+
* {@link update}. Langium's `update` reaches `buildDocuments` directly rather
|
|
387
|
+
* than through here, so the two never nest.
|
|
388
|
+
*/
|
|
389
|
+
build(documents, options, cancelToken) {
|
|
390
|
+
const uris = documents.map(document => document.uri);
|
|
391
|
+
return this.runInSession({ kind: 'build', trigger: `${documents.length} docs`, triggerCountsDocs: true, changed: uris, deleted: [] }, `Build documents (${documents.length} docs)`, () => super.build(documents, options, cancelToken));
|
|
335
392
|
}
|
|
336
393
|
/**
|
|
337
394
|
* Refresh cross-document `ComputedScopes` derivations on cascade, when
|
|
@@ -528,6 +585,138 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
528
585
|
];
|
|
529
586
|
}
|
|
530
587
|
// ============================================================
|
|
588
|
+
// Build sessions — one rebuild as a correlated unit
|
|
589
|
+
// ============================================================
|
|
590
|
+
/**
|
|
591
|
+
* Open a session, run `body` inside it, and close it — the bracket every
|
|
592
|
+
* line of a rebuild is emitted within.
|
|
593
|
+
*
|
|
594
|
+
* The session is installed **synchronously**, before the timed body runs, so
|
|
595
|
+
* that state a subclass computed in {@link createBuildSession} is already
|
|
596
|
+
* readable by the time Langium's `update` consults `shouldRelink`.
|
|
597
|
+
*
|
|
598
|
+
* Teardown is preemption-correct, which is the reason this is framework code
|
|
599
|
+
* rather than a recipe. Langium's write mutex cancels an in-flight build when
|
|
600
|
+
* a later one arrives, so two sessions overlap: the successor installs itself
|
|
601
|
+
* as {@link activeSession} while the predecessor is still unwinding, and the
|
|
602
|
+
* predecessor's `finally` runs LAST. Clearing unconditionally there would
|
|
603
|
+
* discard the winner's state mid-build. Only the session that is still
|
|
604
|
+
* current clears — and the check is reference equality on the session object,
|
|
605
|
+
* not on {@link BuildSession.traceId}, which is `undefined` for every build
|
|
606
|
+
* whenever the timing level is suppressed and would compare equal to itself
|
|
607
|
+
* across two different builds.
|
|
608
|
+
*
|
|
609
|
+
* Re-entrancy is not hypothetical even without an adopter: {@link
|
|
610
|
+
* requeueOrphaned} calls `update` from inside a wait, while a build may be
|
|
611
|
+
* running.
|
|
612
|
+
*/
|
|
613
|
+
runInSession(context, label, body) {
|
|
614
|
+
// Read before installing the new session: the id being superseded belongs
|
|
615
|
+
// to the OUTGOING build, or — when the previous one already finished
|
|
616
|
+
// cancelled — to the id it parked for its successor.
|
|
617
|
+
const supersededId = this.activeSession?.traceId ?? this.lastCancelledTraceId;
|
|
618
|
+
this.lastCancelledTraceId = undefined;
|
|
619
|
+
const reason = this.pendingUpdateReason;
|
|
620
|
+
this.pendingUpdateReason = undefined;
|
|
621
|
+
const tags = [];
|
|
622
|
+
if (reason) {
|
|
623
|
+
tags.push(`event: ${reason}`);
|
|
624
|
+
}
|
|
625
|
+
if (supersededId !== undefined) {
|
|
626
|
+
tags.push(`cancels #${supersededId}`);
|
|
627
|
+
}
|
|
628
|
+
const session = this.createBuildSession(context);
|
|
629
|
+
this.activeSession = session;
|
|
630
|
+
// A phase's "since previous phase" must measure from the build's start,
|
|
631
|
+
// not from whenever the last build's final phase happened to land.
|
|
632
|
+
this.lastPhaseMs = session.startMs;
|
|
633
|
+
return this.tracer.time(label, async () => {
|
|
634
|
+
try {
|
|
635
|
+
await body();
|
|
636
|
+
}
|
|
637
|
+
catch (err) {
|
|
638
|
+
if (isOperationCancelled(err)) {
|
|
639
|
+
session.cancelled = true;
|
|
640
|
+
}
|
|
641
|
+
throw err;
|
|
642
|
+
}
|
|
643
|
+
finally {
|
|
644
|
+
this.endSession(session);
|
|
645
|
+
}
|
|
646
|
+
}, this.logLevel, {
|
|
647
|
+
logAfterMs: 0,
|
|
648
|
+
forceMemoryAboveMs: session.buffers ? session.detailThresholdMs : undefined,
|
|
649
|
+
captureId: id => {
|
|
650
|
+
session.traceId = id;
|
|
651
|
+
},
|
|
652
|
+
tags
|
|
653
|
+
});
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Construct the session for one build. Override to return a
|
|
657
|
+
* {@link BuildSession} subclass carrying adopter build-scoped state — it is
|
|
658
|
+
* called before the build body, so anything derived here is readable
|
|
659
|
+
* throughout it.
|
|
660
|
+
*/
|
|
661
|
+
createBuildSession(context) {
|
|
662
|
+
return new BuildSession(performance.now(), context.trigger, context.triggerCountsDocs, this.phaseDetailMs.value);
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Close `session`: flush what it buffered, then release it if it is still the
|
|
666
|
+
* current one (see {@link runInSession} on why that check is conditional).
|
|
667
|
+
* The flush is unconditional — a preempted build's lines still describe work
|
|
668
|
+
* that happened.
|
|
669
|
+
*/
|
|
670
|
+
endSession(session) {
|
|
671
|
+
this.flushSession(session);
|
|
672
|
+
if (this.activeSession === session) {
|
|
673
|
+
this.activeSession = undefined;
|
|
674
|
+
if (session.cancelled) {
|
|
675
|
+
this.lastCancelledTraceId = session.traceId;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* Emit the lines `session` held back, if it ran long enough to be worth the
|
|
681
|
+
* detail; drop them otherwise. Emits through {@link emit} rather than
|
|
682
|
+
* {@link log}, which would route them straight back into the buffer.
|
|
683
|
+
*/
|
|
684
|
+
flushSession(session) {
|
|
685
|
+
const elapsedMs = performance.now() - session.startMs;
|
|
686
|
+
if (elapsedMs >= session.detailThresholdMs) {
|
|
687
|
+
for (const line of session.bufferedLines) {
|
|
688
|
+
this.emit(line);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
session.bufferedLines.length = 0;
|
|
692
|
+
}
|
|
693
|
+
/** Label for the build's own log line. Override to customise wording. */
|
|
694
|
+
rebuildLabel(changed, deleted) {
|
|
695
|
+
if (changed.length === 0 && deleted.length === 0) {
|
|
696
|
+
return 'Rebuild documents (nothing to do)';
|
|
697
|
+
}
|
|
698
|
+
if (changed.length === 1 && deleted.length === 0) {
|
|
699
|
+
return `Rebuild document: ${this.formatUri(changed[0])}`;
|
|
700
|
+
}
|
|
701
|
+
if (changed.length === 0 && deleted.length === 1) {
|
|
702
|
+
return `Rebuild after delete: ${this.formatUri(deleted[0])}`;
|
|
703
|
+
}
|
|
704
|
+
return `Rebuild documents (${changed.length} changed, ${deleted.length} deleted)`;
|
|
705
|
+
}
|
|
706
|
+
/** Short description of what triggered the build, repeated on every phase line. Override to customise wording. */
|
|
707
|
+
buildTriggerLabel(changed, deleted) {
|
|
708
|
+
if (changed.length === 0 && deleted.length === 0) {
|
|
709
|
+
return 'nothing';
|
|
710
|
+
}
|
|
711
|
+
if (changed.length === 1 && deleted.length === 0) {
|
|
712
|
+
return this.formatUri(changed[0]);
|
|
713
|
+
}
|
|
714
|
+
if (changed.length === 0 && deleted.length === 1) {
|
|
715
|
+
return `deleted ${this.formatUri(deleted[0])}`;
|
|
716
|
+
}
|
|
717
|
+
return `${changed.length} changed, ${deleted.length} deleted`;
|
|
718
|
+
}
|
|
719
|
+
// ============================================================
|
|
531
720
|
// Logging — phase-reached listeners
|
|
532
721
|
// ============================================================
|
|
533
722
|
registerPhaseListeners() {
|
|
@@ -540,12 +729,34 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
540
729
|
const now = performance.now();
|
|
541
730
|
const elapsedMs = Math.round(now - this.lastPhaseMs);
|
|
542
731
|
this.lastPhaseMs = now;
|
|
732
|
+
// Counted before the line is formatted, so the formatter stays a pure
|
|
733
|
+
// function of state a caller can also set up in a test.
|
|
734
|
+
if (this.activeSession) {
|
|
735
|
+
this.activeSession.phasesLogged++;
|
|
736
|
+
}
|
|
543
737
|
this.log(this.phaseReachedLine(state, documents, elapsedMs));
|
|
544
738
|
}
|
|
545
|
-
/**
|
|
739
|
+
/**
|
|
740
|
+
* Format the phase-reached log line. Override to customise wording.
|
|
741
|
+
*
|
|
742
|
+
* Within a session the line names what triggered the build, so a phase read
|
|
743
|
+
* in isolation still says which rebuild it belongs to. `elapsedMs` is ignored
|
|
744
|
+
* for the FIRST phase of a session: it measures from the previous build's
|
|
745
|
+
* last phase, an idle gap that says nothing about this build.
|
|
746
|
+
*/
|
|
546
747
|
phaseReachedLine(state, documents, elapsedMs) {
|
|
547
|
-
const
|
|
548
|
-
|
|
748
|
+
const session = this.activeSession;
|
|
749
|
+
let docInfo;
|
|
750
|
+
if (session) {
|
|
751
|
+
docInfo = session.triggerCountsDocs ? `building ${session.trigger}` : `building ${session.trigger}, ${documents.length} docs`;
|
|
752
|
+
}
|
|
753
|
+
else {
|
|
754
|
+
docInfo = documents.length === 1 ? this.formatUri(documents[0].uri) : `${documents.length} docs`;
|
|
755
|
+
}
|
|
756
|
+
const elapsedInfo = session && session.phasesLogged <= 1
|
|
757
|
+
? `${Math.round(performance.now() - session.startMs)}ms since build start`
|
|
758
|
+
: `${elapsedMs}ms since previous phase`;
|
|
759
|
+
return `Reached phase '${DocumentState[state]}' [${docInfo}, ${elapsedInfo}]`;
|
|
549
760
|
}
|
|
550
761
|
// ============================================================
|
|
551
762
|
// Logging — slow-listener breakdown on notifyDocumentPhase
|
|
@@ -558,8 +769,12 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
558
769
|
// build settling inside that window therefore appends after this call has
|
|
559
770
|
// already deduped, and the appended duplicate is published by the listener
|
|
560
771
|
// of the build that deduped. Only `serializeBuilds` closes the window.
|
|
772
|
+
//
|
|
773
|
+
// Dedupe before rendering: rendering is deterministic, so it cannot
|
|
774
|
+
// change which entries are structurally equal, and fewer survive to render.
|
|
561
775
|
if (state === DocumentState.Validated) {
|
|
562
776
|
this.dedupeDiagnostics(document);
|
|
777
|
+
this.renderDiagnostics(document);
|
|
563
778
|
}
|
|
564
779
|
if (this.logLevel === 'off') {
|
|
565
780
|
return super.notifyDocumentPhase(document, state, cancelToken);
|
|
@@ -718,11 +933,83 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
718
933
|
document.diagnostics = unique;
|
|
719
934
|
}
|
|
720
935
|
}
|
|
936
|
+
/**
|
|
937
|
+
* Render every diagnostic on `document` through the bound message renderer,
|
|
938
|
+
* in ONE pass over the finished list.
|
|
939
|
+
*
|
|
940
|
+
* All three heads read `document.diagnostics` — the LSP publish,
|
|
941
|
+
* `TransferEncoder.toTransferDiagnostic` and the GLSP validation path — so
|
|
942
|
+
* one pass here is what keeps the render from happening per head. It is also
|
|
943
|
+
* the only placement that covers lexer and parser errors, which Langium
|
|
944
|
+
* pushes onto the document without routing them through `toDiagnostic`.
|
|
945
|
+
*
|
|
946
|
+
* Running here rather than from a `Validated` phase listener needs no
|
|
947
|
+
* ordering assumption: Langium publishes from `addDiagnosticsHandler`, a free
|
|
948
|
+
* function it registers as such a listener, which can only be outrun.
|
|
949
|
+
*
|
|
950
|
+
* **It inherits {@link dedupeDiagnostics}'s window, and therefore the same
|
|
951
|
+
* precondition.** A build settling inside the listener window appends
|
|
952
|
+
* diagnostics this pass never saw, and the publisher of the build that
|
|
953
|
+
* rendered sends them — unrendered. `ModelServiceOptions.serializeBuilds`
|
|
954
|
+
* closes it and defaults to `true`, so "every diagnostic is rendered" holds
|
|
955
|
+
* by default and is an opt-out rather than a guarantee. Opting out accepts
|
|
956
|
+
* unrendered diagnostics on exactly the terms it already accepts duplicates.
|
|
957
|
+
*
|
|
958
|
+
* Entries are REPLACED rather than mutated: `sendDiagnostics` passes the
|
|
959
|
+
* array by reference and serialises later, so an in-place message mutation
|
|
960
|
+
* reaches the wire even when it runs after the publisher — which would make
|
|
961
|
+
* a test for the ordering pass in either state.
|
|
962
|
+
*/
|
|
963
|
+
renderDiagnostics(document) {
|
|
964
|
+
const diagnostics = document.diagnostics;
|
|
965
|
+
if (!diagnostics || diagnostics.length === 0) {
|
|
966
|
+
return;
|
|
967
|
+
}
|
|
968
|
+
let changed = false;
|
|
969
|
+
// No try/catch: `renderDiagnostic` carries a no-throw contract, because an
|
|
970
|
+
// error escaping this phase strands the document at `Validated` with
|
|
971
|
+
// Langium's publisher never invoked.
|
|
972
|
+
const rendered = diagnostics.map(diagnostic => {
|
|
973
|
+
const text = this.messageRenderer.renderDiagnostic(diagnostic);
|
|
974
|
+
// Against the message's STRING FORM, not the field. `renderDiagnostic`
|
|
975
|
+
// answers a `string` by contract, while `Diagnostic.message` is
|
|
976
|
+
// `string | MarkupContent` since LSP 3.17 — so comparing the answer
|
|
977
|
+
// against the field never matches for a markup message, and a pass
|
|
978
|
+
// that replaced on mismatch flattened every un-identified markup
|
|
979
|
+
// diagnostic to its own plain text. That is silent data loss on the
|
|
980
|
+
// path whose whole job is to leave such entries alone.
|
|
981
|
+
if (text === Diagnostic.getMessageString(diagnostic)) {
|
|
982
|
+
return diagnostic;
|
|
983
|
+
}
|
|
984
|
+
changed = true;
|
|
985
|
+
return { ...diagnostic, message: text };
|
|
986
|
+
});
|
|
987
|
+
if (changed) {
|
|
988
|
+
document.diagnostics = rendered;
|
|
989
|
+
}
|
|
990
|
+
}
|
|
721
991
|
// ============================================================
|
|
722
992
|
// Internal helpers
|
|
723
993
|
// ============================================================
|
|
724
|
-
/**
|
|
994
|
+
/**
|
|
995
|
+
* Dispatch a log line at the configured log level; a no-op when `logLevel ===
|
|
996
|
+
* 'off'`.
|
|
997
|
+
*
|
|
998
|
+
* Held on the active session when it buffers, so the "was this build worth a
|
|
999
|
+
* per-phase breakdown" decision — which needs the build's total duration, and
|
|
1000
|
+
* so cannot be taken by anything that runs while the lines are produced — is
|
|
1001
|
+
* deferred to {@link flushSession}.
|
|
1002
|
+
*/
|
|
725
1003
|
log(message) {
|
|
1004
|
+
const session = this.activeSession;
|
|
1005
|
+
if (session?.buffers) {
|
|
1006
|
+
session.bufferedLines.push(message);
|
|
1007
|
+
return;
|
|
1008
|
+
}
|
|
1009
|
+
this.emit(message);
|
|
1010
|
+
}
|
|
1011
|
+
/** Write a line out, bypassing session buffering. The single sink every framework log line reaches. */
|
|
1012
|
+
emit(message) {
|
|
726
1013
|
this.tracer.logAt(this.logLevel, message);
|
|
727
1014
|
}
|
|
728
1015
|
}
|