@hydranium/core 1.0.0-next.31 → 1.0.0-next.33
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/hydranium-text-documents.d.ts.map +1 -1
- package/lib/documents/hydranium-text-documents.js +12 -1
- package/lib/documents/hydranium-text-documents.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/langium/bootstrap.d.ts.map +1 -1
- package/lib/langium/bootstrap.js +8 -1
- package/lib/langium/bootstrap.js.map +1 -1
- package/lib/langium/document-builder/document-builder.d.ts +33 -1
- package/lib/langium/document-builder/document-builder.d.ts.map +1 -1
- package/lib/langium/document-builder/document-builder.js +68 -2
- package/lib/langium/document-builder/document-builder.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 +39 -2
- package/lib/langium/model-service/model-service.d.ts.map +1 -1
- package/lib/langium/model-service/model-service.js +44 -5
- package/lib/langium/model-service/model-service.js.map +1 -1
- package/lib/langium/module.d.ts +20 -0
- package/lib/langium/module.d.ts.map +1 -1
- package/lib/langium/module.js +4 -0
- 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 -1
- package/lib/langium/naming/name-separator-validation.d.ts.map +1 -1
- package/lib/langium/naming/name-separator-validation.js +22 -0
- package/lib/langium/naming/name-separator-validation.js.map +1 -1
- package/lib/langium/shared-services.d.ts +13 -2
- package/lib/langium/shared-services.d.ts.map +1 -1
- package/lib/langium/shared-services.js.map +1 -1
- package/lib/langium/validation/document-validator.d.ts +128 -2
- 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/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/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/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 +59 -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/messages/carriers.d.ts +15 -7
- package/lib/messages/carriers.d.ts.map +1 -1
- package/lib/messages/carriers.js +19 -8
- package/lib/messages/carriers.js.map +1 -1
- package/lib/messages/index.d.ts +3 -0
- package/lib/messages/index.d.ts.map +1 -1
- package/lib/messages/index.js +3 -0
- package/lib/messages/index.js.map +1 -1
- package/lib/messages/renderer.d.ts +117 -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/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 +27 -0
- package/lib/testing/make-test-services.d.ts.map +1 -1
- package/lib/testing/make-test-services.js +17 -1
- package/lib/testing/make-test-services.js.map +1 -1
- package/package.json +5 -5
- package/src/documents/hydranium-text-documents.ts +12 -1
- package/src/index.ts +1 -0
- package/src/langium/bootstrap.ts +8 -1
- package/src/langium/document-builder/document-builder.ts +70 -2
- package/src/langium/keys/containment.ts +87 -0
- package/src/langium/keys/index.ts +1 -0
- package/src/langium/keys/name-based-key-provider.ts +4 -0
- package/src/langium/model-service/model-service.ts +46 -4
- package/src/langium/module.ts +22 -0
- package/src/langium/naming/name-provider.ts +10 -0
- package/src/langium/naming/name-separator-validation.ts +25 -3
- package/src/langium/shared-services.ts +13 -2
- package/src/langium/validation/document-validator.ts +238 -4
- package/src/langium/workspace/hydranium-workspace-manager.ts +30 -1
- package/src/langium/workspace/initialize-workspace.ts +34 -5
- package/src/locale/index.ts +10 -0
- package/src/locale/server-locale.ts +71 -0
- package/src/messages/carriers.ts +20 -10
- package/src/messages/index.ts +3 -0
- package/src/messages/renderer.ts +184 -0
- package/src/testing/make-noop-shared-services.ts +50 -2
- package/src/testing/make-test-services.ts +43 -1
|
@@ -21,8 +21,12 @@ import {
|
|
|
21
21
|
interruptAndCheck,
|
|
22
22
|
isOperationCancelled
|
|
23
23
|
} from '@hydranium/langium';
|
|
24
|
-
|
|
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';
|
|
25
28
|
import { type LogNameOptions } from '../diagnostics/logger.js';
|
|
29
|
+
import type { ServerMessageRenderer } from '../../messages/renderer.js';
|
|
26
30
|
import { CST_REHYDRATION_RESET_STATE, isCstShed } from '../residency/cst-residency-service.js';
|
|
27
31
|
import { type ExtendedServiceRegistry } from '../service-registry.js';
|
|
28
32
|
import { type ServerSharedServicesMinimal } from '../shared-services.js';
|
|
@@ -119,7 +123,9 @@ export interface DocumentBuilderOptions extends LogNameOptions {
|
|
|
119
123
|
* - **In-place rebuild helpers** — {@link reparse} and
|
|
120
124
|
* {@link reparseAndRelink} — for a build-phase listener that mutated a
|
|
121
125
|
* document's AST and must reconcile it within the same build.
|
|
122
|
-
* - **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}).
|
|
123
129
|
* - **Build sessions** ({@link BuildSession}): each `update` / `build` call is
|
|
124
130
|
* one correlated unit carrying an id, a trigger label, a start time and
|
|
125
131
|
* cancellation lineage, so every line of a rebuild reads as belonging to it
|
|
@@ -152,6 +158,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
152
158
|
protected readonly phaseDetailMs: ObservableValue<number>;
|
|
153
159
|
protected readonly uriPolicy: DocumentUriPolicy;
|
|
154
160
|
protected readonly clock: Clock;
|
|
161
|
+
protected readonly messageRenderer: ServerMessageRenderer;
|
|
155
162
|
/** Narrower handle on the same registry as the inherited `serviceRegistry`, for {@link ExtendedServiceRegistry.registrations}. */
|
|
156
163
|
protected readonly languageRegistry: ExtendedServiceRegistry;
|
|
157
164
|
protected languageFileExtensions: string[] = [];
|
|
@@ -184,6 +191,7 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
184
191
|
this.languageRegistry = services.ServiceRegistry;
|
|
185
192
|
this.uriPolicy = services.workspace.DocumentUriPolicy;
|
|
186
193
|
this.clock = services.Clock;
|
|
194
|
+
this.messageRenderer = services.MessageRenderer;
|
|
187
195
|
this.tracer = services.Tracer.for(options.logName ?? 'DocumentBuilder').trace('instantiated');
|
|
188
196
|
this.logLevel = options.logLevel ?? 'debug';
|
|
189
197
|
this.loggedPhases = options.loggedPhases ?? DEFAULT_LOGGED_PHASES;
|
|
@@ -893,8 +901,12 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
893
901
|
// build settling inside that window therefore appends after this call has
|
|
894
902
|
// already deduped, and the appended duplicate is published by the listener
|
|
895
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.
|
|
896
907
|
if (state === DocumentState.Validated) {
|
|
897
908
|
this.dedupeDiagnostics(document);
|
|
909
|
+
this.renderDiagnostics(document);
|
|
898
910
|
}
|
|
899
911
|
if (this.logLevel === 'off') {
|
|
900
912
|
return super.notifyDocumentPhase(document, state, cancelToken);
|
|
@@ -1070,6 +1082,62 @@ export class HydraniumDocumentBuilder extends DefaultDocumentBuilder {
|
|
|
1070
1082
|
}
|
|
1071
1083
|
}
|
|
1072
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
|
+
|
|
1073
1141
|
// ============================================================
|
|
1074
1142
|
// Internal helpers
|
|
1075
1143
|
// ============================================================
|
|
@@ -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
|
+
/**
|
|
11
|
+
* Containment-array maintenance for callers that build or delete AST nodes
|
|
12
|
+
* programmatically — a GLSP operation handler being the usual one.
|
|
13
|
+
*
|
|
14
|
+
* **These live beside the key provider because the constraint is the key
|
|
15
|
+
* provider's.** `NameBasedKeyProvider` keys a node the `NameProvider` gives no
|
|
16
|
+
* name from its position, as `` `${$containerProperty}@${$containerIndex}` ``,
|
|
17
|
+
* so a node appended with a bare `array.push` carries neither and
|
|
18
|
+
* `getElementKey` answers `undefined` — the element has no key at all, and the
|
|
19
|
+
* GLSP index cannot address it. Deleting from the middle of such a list must
|
|
20
|
+
* renumber the survivors, or an id derived later in the same command names the
|
|
21
|
+
* wrong node. Shipping the constraint's statement without the code that
|
|
22
|
+
* discharges it leaves every adopter in that position re-deriving thirty lines
|
|
23
|
+
* from prose, and both failures are silent.
|
|
24
|
+
*
|
|
25
|
+
* The population is narrower than "anyone creating elements from a diagram": it
|
|
26
|
+
* takes a grammar with UNNAMED element types, programmatic creation or deletion
|
|
27
|
+
* of them, and this key provider. A grammar whose diagram elements are all
|
|
28
|
+
* named never reaches it, and the two ways out are named on the provider —
|
|
29
|
+
* give the type a name, or bind a provider whose fallback is content-derived.
|
|
30
|
+
*
|
|
31
|
+
* **Free functions, and deliberately not a step on the AST builder.** Building a
|
|
32
|
+
* node detached and appending it later is legitimate, so a containment step
|
|
33
|
+
* cannot be mandatory; and an optional fluent step could not check the index
|
|
34
|
+
* against the array unless it were handed the array, at which point it is these
|
|
35
|
+
* signatures with more ceremony. `AstNodeInit` already accepts the three fields
|
|
36
|
+
* for a caller who has them, which is the case these cover: it is the INDEX that
|
|
37
|
+
* cannot be known without reading the array.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
import type { AstNode } from '@hydranium/langium';
|
|
41
|
+
import type { Mutable } from '@hydranium/protocol';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Append `child` to `children`, stamping the Langium containment plumbing
|
|
45
|
+
* (`$container`, `$containerProperty`, `$containerIndex`) so a positional key
|
|
46
|
+
* can address it.
|
|
47
|
+
*
|
|
48
|
+
* `property` and `children` are separate parameters rather than one property
|
|
49
|
+
* name the function dereferences: the array is what the index is derived from,
|
|
50
|
+
* so taking it directly is what makes the two agree by construction instead of
|
|
51
|
+
* by a lookup that a typo could point elsewhere.
|
|
52
|
+
*
|
|
53
|
+
* @returns `child`, so a caller can append and use it in one expression.
|
|
54
|
+
*/
|
|
55
|
+
export function appendChild<TChild extends AstNode>(container: AstNode, property: string, children: TChild[], child: TChild): TChild {
|
|
56
|
+
const mutable = child as Mutable<TChild>;
|
|
57
|
+
mutable.$container = container;
|
|
58
|
+
mutable.$containerProperty = property;
|
|
59
|
+
mutable.$containerIndex = children.length;
|
|
60
|
+
children.push(child);
|
|
61
|
+
return child;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Remove every entry of `children` that is in `toRemove`, then renumber the
|
|
66
|
+
* survivors' `$containerIndex`.
|
|
67
|
+
*
|
|
68
|
+
* Mutates `children` in place rather than returning a new array, because the
|
|
69
|
+
* caller's array IS the AST's containment list — replacing the reference would
|
|
70
|
+
* leave the parent pointing at the old one.
|
|
71
|
+
*
|
|
72
|
+
* @returns how many entries were removed, so a caller can tell a no-op delete
|
|
73
|
+
* from one that changed the model without comparing lengths itself.
|
|
74
|
+
*/
|
|
75
|
+
export function removeChildren<TChild extends AstNode>(children: TChild[], toRemove: ReadonlySet<TChild>): number {
|
|
76
|
+
if (toRemove.size === 0) {
|
|
77
|
+
return 0;
|
|
78
|
+
}
|
|
79
|
+
const survivors = children.filter(child => !toRemove.has(child));
|
|
80
|
+
const removed = children.length - survivors.length;
|
|
81
|
+
children.length = 0;
|
|
82
|
+
for (const [index, child] of survivors.entries()) {
|
|
83
|
+
(child as Mutable<TChild>).$containerIndex = index;
|
|
84
|
+
children.push(child);
|
|
85
|
+
}
|
|
86
|
+
return removed;
|
|
87
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
* SPDX-License-Identifier: MIT
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
|
+
export * from './containment.js';
|
|
10
11
|
export * from './element-key-provider.js';
|
|
11
12
|
export * from './name-based-key-provider.js';
|
|
12
13
|
export * from './positional-key-provider.js';
|
|
@@ -55,6 +55,10 @@ import { type NameProvider } from '../naming/name-provider.js';
|
|
|
55
55
|
* - After a removal, surviving siblings need their `$containerIndex`
|
|
56
56
|
* renumbered, or a key derived afterwards addresses the wrong node.
|
|
57
57
|
*
|
|
58
|
+
* {@link appendChild} and {@link removeChildren} discharge both, and ship
|
|
59
|
+
* beside this provider because the constraint is this provider's rather than
|
|
60
|
+
* any caller's.
|
|
61
|
+
*
|
|
58
62
|
* Adopters that need insert / delete stability for unnamed types should
|
|
59
63
|
* give those types a name in the grammar, or bind a key provider whose
|
|
60
64
|
* fallback is content-derived rather than positional.
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
type CanonicalUri,
|
|
12
12
|
type CloseModelArgs,
|
|
13
13
|
ConflictError,
|
|
14
|
+
defineMessage,
|
|
14
15
|
Logger,
|
|
15
16
|
type MaybeObservableValue,
|
|
16
17
|
type MaybePromise,
|
|
@@ -34,6 +35,23 @@ import { labelPhaseListener } from '../document-builder/labeled-phase-listener.j
|
|
|
34
35
|
import { LANGUAGE_CLIENT_ID } from '../../documents/client-ids.js';
|
|
35
36
|
import { type ServerSharedServices } from '../module.js';
|
|
36
37
|
|
|
38
|
+
/**
|
|
39
|
+
* The undo-stack entry for a server-authored write pushed to the editor.
|
|
40
|
+
*
|
|
41
|
+
* **A user-facing LABEL, not a log string**, which is easy to miss because it
|
|
42
|
+
* travels as an options field rather than as a message: LSP specifies
|
|
43
|
+
* `ApplyWorkspaceEditParams.label` as "presented in the user interface for
|
|
44
|
+
* example on an undo stack to undo the workspace edit". So a user who edits
|
|
45
|
+
* through a form or drags a diagram node reads this in their editor's undo menu
|
|
46
|
+
* — which is why it is rendered like any other message the server sends rather
|
|
47
|
+
* than left as the English literal it was.
|
|
48
|
+
*
|
|
49
|
+
* Parameterless deliberately. The obvious improvement is to name the document,
|
|
50
|
+
* and it is the wrong one: an undo menu is already grouped under the file, so
|
|
51
|
+
* the URI would be noise in the one place it is redundant.
|
|
52
|
+
*/
|
|
53
|
+
export const MODEL_UPDATE_EDIT = defineMessage('hydranium/core/model-update-edit', 'Update Model');
|
|
54
|
+
|
|
37
55
|
/** Max time {@link ModelService.settleSave} waits for the build to settle and the sync chain to drain. */
|
|
38
56
|
const SAVE_SETTLE_TIMEOUT_MS = 10_000;
|
|
39
57
|
|
|
@@ -484,11 +502,22 @@ export class ModelService<
|
|
|
484
502
|
*
|
|
485
503
|
* Phase invariants encoded in the return type:
|
|
486
504
|
* - `parsed` / `linked` / `settled` / `indexed` return
|
|
487
|
-
* `AstDocument<TAst, never>` — diagnostics
|
|
488
|
-
*
|
|
505
|
+
* `AstDocument<TAst, never>` — no diagnostics have been computed at
|
|
506
|
+
* those phases.
|
|
489
507
|
* - `validated` returns `AstDocument<TAst, TDiagnostic>` — diagnostics
|
|
490
508
|
* are populated.
|
|
491
509
|
*
|
|
510
|
+
* **The `never` is a claim about the PHASE, not a guarantee about the
|
|
511
|
+
* instance, and the gap is reachable rather than theoretical.** The wait
|
|
512
|
+
* underneath resolves at or ABOVE the requested state, so a document
|
|
513
|
+
* something else already carried past `Validated` comes back from
|
|
514
|
+
* `settled()` with a populated diagnostics array typed `never`. Nothing
|
|
515
|
+
* strips it — the envelope copies the live document's array verbatim — and
|
|
516
|
+
* any host that validates its workspace before a consumer asks produces
|
|
517
|
+
* exactly that. So read an empty array as "none were computed, or there are
|
|
518
|
+
* none", never as "this document is clean", and call {@link validated} when
|
|
519
|
+
* the answer has to mean the second.
|
|
520
|
+
*
|
|
492
521
|
* `settled` is the integrity-overlay name for "all integrity rules
|
|
493
522
|
* have fired"; it maps to {@link IntegrityService.SettledState} (which
|
|
494
523
|
* equals `DocumentState.IndexedReferences`), but the dedicated method
|
|
@@ -878,13 +907,26 @@ export class ModelService<
|
|
|
878
907
|
this.syncChains.set(uri, chain);
|
|
879
908
|
}
|
|
880
909
|
|
|
910
|
+
/**
|
|
911
|
+
* The undo-stack label for a server-authored write, in the locale the server
|
|
912
|
+
* was handed at init.
|
|
913
|
+
*
|
|
914
|
+
* One method rather than the literal at each `applyEdit`, because the two
|
|
915
|
+
* call sites are the same edit — a push and its full-replace retry — and an
|
|
916
|
+
* undo menu showing two different words for one operation would read as two
|
|
917
|
+
* operations.
|
|
918
|
+
*/
|
|
919
|
+
protected editLabel(): string {
|
|
920
|
+
return this.services.MessageRenderer.renderMessage(MODEL_UPDATE_EDIT);
|
|
921
|
+
}
|
|
922
|
+
|
|
881
923
|
protected async drainSyncQueue(uri: string): Promise<void> {
|
|
882
924
|
const uriLogger = this.tracer.withUri(uri);
|
|
883
925
|
while (this.pendingSync.has(uri)) {
|
|
884
926
|
const text = this.pendingSync.get(uri)!;
|
|
885
927
|
this.pendingSync.delete(uri);
|
|
886
928
|
try {
|
|
887
|
-
let result = await this.services.workspace.TextDocuments.applyEditToLanguageClient(uri, text, { label:
|
|
929
|
+
let result = await this.services.workspace.TextDocuments.applyEditToLanguageClient(uri, text, { label: this.editLabel() });
|
|
888
930
|
if (result?.applied === false && !this.pendingSync.has(uri)) {
|
|
889
931
|
// The push is addressed at the client's LAST DECLARED VERSION, so a
|
|
890
932
|
// rejection normally means the client's buffer moved while the
|
|
@@ -905,7 +947,7 @@ export class ModelService<
|
|
|
905
947
|
// queued — best-effort, since a settle arriving later simply pushes
|
|
906
948
|
// after this and still wins.
|
|
907
949
|
uriLogger.warn(`Language client rejected applyEdit at its declared version — re-pushing a full replace`);
|
|
908
|
-
result = await this.services.workspace.TextDocuments.applyEditToLanguageClient(uri, text, { label:
|
|
950
|
+
result = await this.services.workspace.TextDocuments.applyEditToLanguageClient(uri, text, { label: this.editLabel() });
|
|
909
951
|
if (result?.applied === false) {
|
|
910
952
|
uriLogger.warn(`Language client rejected the full-replace retry too — client content is stale`);
|
|
911
953
|
}
|
package/src/langium/module.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
********************************************************************************/
|
|
9
9
|
|
|
10
10
|
import { type Clock, type Logger, type Project, type Tracer, type TransferDiagnostic, NoopLogger, SystemClock } from '@hydranium/protocol';
|
|
11
|
+
import { ServerLocale } from '../locale/server-locale.js';
|
|
12
|
+
import { ServerMessageRenderer } from '../messages/renderer.js';
|
|
11
13
|
import { ServerTracer } from './diagnostics/server-tracer.js';
|
|
12
14
|
import { HydraniumLangiumProfiler } from './diagnostics/hydranium-langium-profiler.js';
|
|
13
15
|
import { type AstNode, type Module } from '@hydranium/langium';
|
|
@@ -92,6 +94,24 @@ export interface ServerAddedSharedServices<TProject extends Project = Project> {
|
|
|
92
94
|
* plain `DefaultTracer` with their own `MemoryReader`.
|
|
93
95
|
*/
|
|
94
96
|
Tracer: Tracer;
|
|
97
|
+
/**
|
|
98
|
+
* Renders each user-facing message once, before the server sends it — so
|
|
99
|
+
* every message is rendered by the side that knows the reading user's
|
|
100
|
+
* language. All three heads inherit one diagnostics pass, which is what
|
|
101
|
+
* makes this the single slot an adopter with i18n rebinds; the same binding
|
|
102
|
+
* serves framework codes and their own `defineMessage` codes alike.
|
|
103
|
+
*
|
|
104
|
+
* The framework ships English only and selects no locale, so the default
|
|
105
|
+
* returns every sentence unchanged. Adopters subclass and override
|
|
106
|
+
* `translationsFor`.
|
|
107
|
+
*/
|
|
108
|
+
MessageRenderer: ServerMessageRenderer;
|
|
109
|
+
/**
|
|
110
|
+
* The locale an init handed the server, for whoever renders in it. Held
|
|
111
|
+
* apart from the renderer so replacing the renderer cannot drop locale
|
|
112
|
+
* handling.
|
|
113
|
+
*/
|
|
114
|
+
ServerLocale: ServerLocale;
|
|
95
115
|
/**
|
|
96
116
|
* LSP-bound slots layered on top of Langium's `LangiumSharedLSPServices`.
|
|
97
117
|
* The framework contributes a single string slot here —
|
|
@@ -334,6 +354,8 @@ export function createServerSharedModule(
|
|
|
334
354
|
ServiceRegistry: services => new ExtendedServiceRegistry<ServerLanguageServices>(services),
|
|
335
355
|
Logger: () => new NoopLogger(),
|
|
336
356
|
Tracer: services => new ServerTracer(services.Logger, services.Clock),
|
|
357
|
+
ServerLocale: services => new ServerLocale(services),
|
|
358
|
+
MessageRenderer: services => new ServerMessageRenderer(services),
|
|
337
359
|
// Bind Langium's per-grammar-rule / per-`$type` parse/link/validate
|
|
338
360
|
// profiler (the data the framework's own `Tracer`/`ProfileSession` passes
|
|
339
361
|
// cannot produce), routed through our `Logger` and debug-gated. At the
|
|
@@ -59,6 +59,16 @@ export interface NameProviderOptions {
|
|
|
59
59
|
* an `id` field) override explicitly; the explicit override at
|
|
60
60
|
* the adopter side documents the grammar's convention rather than
|
|
61
61
|
* burying it in a framework default.
|
|
62
|
+
*
|
|
63
|
+
* **The override is not optional where `name` is a display LABEL rather
|
|
64
|
+
* than an identifier**, and getting it wrong is quiet at first and then
|
|
65
|
+
* loud. A `name=STRING` holding `"Order.Line"` is legitimate content, but
|
|
66
|
+
* the default reads it as the identifier: `getName` composes a qualified
|
|
67
|
+
* name whose segments cannot be told apart from the label's own dots, and
|
|
68
|
+
* `nameSeparatorCheck` reports `hydranium/core/separator-in-name` on every
|
|
69
|
+
* such node. That diagnostic then names the wrong remedy — it asks for a
|
|
70
|
+
* different character, when the fix is to point this option at the property
|
|
71
|
+
* that really is the identifier.
|
|
62
72
|
*/
|
|
63
73
|
readonly nameProperties?: readonly string[];
|
|
64
74
|
}
|
|
@@ -10,14 +10,36 @@
|
|
|
10
10
|
import { type AstNode, type ValidationAcceptor, type ValidationChecks } from '@hydranium/langium';
|
|
11
11
|
import { defineMessage } from '@hydranium/protocol';
|
|
12
12
|
import { acceptMessage } from '../../messages/carriers.js';
|
|
13
|
+
import { type ServerLanguageServices } from '../language-module.js';
|
|
14
|
+
import { type ValidationCheckContribution, type ValidationCheckRegistry } from '../validation/validation-contribution.js';
|
|
15
|
+
import type { NameProvider } from './name-provider.js';
|
|
13
16
|
|
|
17
|
+
/**
|
|
18
|
+
* A name value that collides with the qualified-name separator.
|
|
19
|
+
*
|
|
20
|
+
* **The sentence addresses a MODELLER, and the remedy it names is theirs**:
|
|
21
|
+
* where `name` really is the identifier, a different character is the fix and
|
|
22
|
+
* the only one available to whoever is typing.
|
|
23
|
+
*
|
|
24
|
+
* **The adopter-facing failure is a different one, and this message cannot
|
|
25
|
+
* carry it.** With `nameProperties` left at its default `['name']` over a
|
|
26
|
+
* grammar where `name` is a display LABEL — a `STRING` legitimately holding
|
|
27
|
+
* `"Order.Line"` — this fires on every dotted label at once, and "use a
|
|
28
|
+
* different character" is then advice nobody can act on: the content is
|
|
29
|
+
* correct and the configuration is not. A burst of this diagnostic across
|
|
30
|
+
* unrelated nodes is that misconfiguration, not a naming problem, and the fix
|
|
31
|
+
* is `nameProperties`. Widening the sentence to say both was rejected: a
|
|
32
|
+
* modeller cannot act on a DI option, and naming one in an editor squiggle
|
|
33
|
+
* teaches the wrong audience.
|
|
34
|
+
*
|
|
35
|
+
* Unreachable from a grammar whose identifier charset excludes the separator,
|
|
36
|
+
* which is every example here and the reference adopter — so it reads as dead
|
|
37
|
+
* and is not: it guards the configuration, not the content.
|
|
38
|
+
*/
|
|
14
39
|
export const SEPARATOR_IN_NAME = defineMessage(
|
|
15
40
|
'hydranium/core/separator-in-name',
|
|
16
41
|
"Name '{name}' contains the configured name separator '{separator}', which is reserved for qualified-name composition — use a different character."
|
|
17
42
|
);
|
|
18
|
-
import { type ServerLanguageServices } from '../language-module.js';
|
|
19
|
-
import { type ValidationCheckContribution, type ValidationCheckRegistry } from '../validation/validation-contribution.js';
|
|
20
|
-
import type { NameProvider } from './name-provider.js';
|
|
21
43
|
|
|
22
44
|
/**
|
|
23
45
|
* Per-node validation check: flag name-bearing AST nodes whose name
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
import type { Clock, Logger, Project, Tracer } from '@hydranium/protocol';
|
|
11
11
|
import type { LangiumSharedCoreServices } from '@hydranium/langium';
|
|
12
|
+
import type { ServerLocale } from '../locale/server-locale.js';
|
|
13
|
+
import type { ServerMessageRenderer } from '../messages/renderer.js';
|
|
12
14
|
import type { SelfSaveRegistry } from '../documents/self-save-registry.js';
|
|
13
15
|
import type { WritableFileSystemProvider } from '../documents/ast-document-manager.js';
|
|
14
16
|
import type { HydraniumDocumentRegistry } from './workspace/langium-documents.js';
|
|
@@ -28,8 +30,9 @@ import type { AdditionalDocumentContribution } from './workspace/additional-docu
|
|
|
28
30
|
* framework additions that other framework services consume: the dedicated
|
|
29
31
|
* {@link Clock}, {@link Logger} and {@link Tracer} top-level slots (injectable
|
|
30
32
|
* time source, emission-only logger, and the measure-and-emit tracer composed
|
|
31
|
-
* from the other two), the {@link AdditionalDocumentContribution} group,
|
|
32
|
-
* {@link
|
|
33
|
+
* from the other two), the {@link AdditionalDocumentContribution} group, the
|
|
34
|
+
* {@link ServerMessageRenderer} and the {@link ServerLocale} it renders in,
|
|
35
|
+
* an {@link ExtendedServiceRegistry}, and on `workspace` a writable file-system
|
|
33
36
|
* provider plus {@link HydraniumWorkspaceManager}, {@link ProjectManager},
|
|
34
37
|
* {@link SelfSaveRegistry}, {@link BuildPipelineIntegration},
|
|
35
38
|
* {@link BuildPhasePassService}, {@link CstResidencyService} and
|
|
@@ -58,6 +61,14 @@ export interface ServerSharedServicesMinimal<TProject extends Project = Project>
|
|
|
58
61
|
* adopters deep-merge contributions that seed built-in / stdlib documents.
|
|
59
62
|
*/
|
|
60
63
|
additionalDocuments: Record<string, AdditionalDocumentContribution>;
|
|
64
|
+
/**
|
|
65
|
+
* Renders each user-facing message once, before the server sends it. On the
|
|
66
|
+
* shared tier with no workspace dependency, because all three heads'
|
|
67
|
+
* messages pass through it.
|
|
68
|
+
*/
|
|
69
|
+
MessageRenderer: ServerMessageRenderer;
|
|
70
|
+
/** The locale an init handed the server, for whoever renders in it. */
|
|
71
|
+
ServerLocale: ServerLocale;
|
|
61
72
|
/**
|
|
62
73
|
* Narrows Langium's base `ServiceRegistry` slot to the framework impl the
|
|
63
74
|
* framework always binds, so the abstaining lookups — `getServicesFor`
|