@hydranium/core 1.0.0-next.30 → 1.0.0-next.32
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/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 +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/model-service/model-service.d.ts +26 -0
- package/lib/langium/model-service/model-service.d.ts.map +1 -1
- package/lib/langium/model-service/model-service.js +31 -3
- 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/scope/hydranium-scope-provider.d.ts +10 -6
- package/lib/langium/scope/hydranium-scope-provider.d.ts.map +1 -1
- package/lib/langium/scope/hydranium-scope-provider.js +15 -11
- package/lib/langium/scope/hydranium-scope-provider.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 +66 -1
- package/lib/langium/validation/document-validator.d.ts.map +1 -1
- package/lib/langium/validation/document-validator.js +101 -1
- package/lib/langium/validation/document-validator.js.map +1 -1
- package/lib/langium/workspace/hydranium-workspace-manager.d.ts +11 -1
- package/lib/langium/workspace/hydranium-workspace-manager.d.ts.map +1 -1
- package/lib/langium/workspace/hydranium-workspace-manager.js +15 -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 +49 -0
- package/lib/locale/server-locale.d.ts.map +1 -0
- package/lib/locale/server-locale.js +51 -0
- package/lib/locale/server-locale.js.map +1 -0
- package/lib/messages/carriers.d.ts +7 -6
- package/lib/messages/carriers.d.ts.map +1 -1
- package/lib/messages/carriers.js +8 -7
- 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/fake-document.d.ts +14 -3
- package/lib/testing/fake-document.d.ts.map +1 -1
- package/lib/testing/fake-document.js +18 -3
- package/lib/testing/fake-document.js.map +1 -1
- package/lib/testing/make-noop-shared-services.d.ts +14 -0
- package/lib/testing/make-noop-shared-services.d.ts.map +1 -1
- package/lib/testing/make-noop-shared-services.js +28 -2
- package/lib/testing/make-noop-shared-services.js.map +1 -1
- package/lib/testing/make-test-services.d.ts +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/ast-extension/ast-node-builder.ts +66 -22
- package/src/langium/bootstrap.ts +8 -1
- package/src/langium/document-builder/document-builder.ts +70 -2
- package/src/langium/model-service/model-service.ts +33 -2
- 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/scope/hydranium-scope-provider.ts +15 -11
- package/src/langium/shared-services.ts +13 -2
- package/src/langium/validation/document-validator.ts +117 -1
- package/src/langium/workspace/hydranium-workspace-manager.ts +18 -1
- package/src/langium/workspace/initialize-workspace.ts +34 -5
- package/src/locale/index.ts +10 -0
- package/src/locale/server-locale.ts +61 -0
- package/src/messages/carriers.ts +8 -8
- package/src/messages/index.ts +3 -0
- package/src/messages/renderer.ts +184 -0
- package/src/testing/fake-document.ts +22 -4
- package/src/testing/make-noop-shared-services.ts +50 -2
- package/src/testing/make-test-services.ts +43 -1
|
@@ -78,15 +78,13 @@ export type AstNodeBuilder<TMap> = <TType extends string & keyof TMap>(
|
|
|
78
78
|
* AST-interface mapping, so call sites get full inference from the type
|
|
79
79
|
* constant alone — no explicit generic parameter at every call site.
|
|
80
80
|
*
|
|
81
|
-
* Runtime behaviour:
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* TS-augmented fields (declared via `declare module './generated/ast.js'`)
|
|
89
|
-
* are unaffected by the runtime defaulting but remain typed at call sites.
|
|
81
|
+
* Runtime behaviour: pre-fills every grammar-declared default (see
|
|
82
|
+
* {@link withTypeDefaults}) before merging the caller's `init`, so containment
|
|
83
|
+
* lists and `?=`-style boolean flags default automatically. TS-augmented fields
|
|
84
|
+
* (declared via `declare module './generated/ast.js'`) are unaffected by the
|
|
85
|
+
* runtime defaulting but remain typed at call sites.
|
|
86
|
+
*
|
|
87
|
+
* Use {@link buildAstNode} instead when the type name is only known at runtime.
|
|
90
88
|
*
|
|
91
89
|
* The init shape only relaxes array-typed fields to optional (via
|
|
92
90
|
* {@link ArrayKeys}) — there is no equivalent structural signal for "this
|
|
@@ -101,19 +99,7 @@ export function makeAstNodeBuilder<TMap>(reflection: AstReflection): AstNodeBuil
|
|
|
101
99
|
init: AstNodeInit<Extract<TMap[TType], AstNode>>,
|
|
102
100
|
extras?: Record<string, unknown>
|
|
103
101
|
): Extract<TMap[TType], AstNode> {
|
|
104
|
-
const
|
|
105
|
-
const result: Record<string, unknown> = { $type: typeConstant.$type };
|
|
106
|
-
if (meta?.properties) {
|
|
107
|
-
for (const [propName, propInfo] of Object.entries(meta.properties)) {
|
|
108
|
-
const defaultValue = propInfo.defaultValue;
|
|
109
|
-
if (defaultValue === undefined) {
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
// Arrays are duplicated so each node carries its own mutable instance;
|
|
113
|
-
// scalars are immutable and safe to copy by reference.
|
|
114
|
-
result[propName] = Array.isArray(defaultValue) ? [...defaultValue] : defaultValue;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
102
|
+
const result = withTypeDefaults(reflection, typeConstant.$type);
|
|
117
103
|
Object.assign(result, init);
|
|
118
104
|
if (extras) {
|
|
119
105
|
// Extras win over init: this is the explicit escape hatch, so when a
|
|
@@ -123,3 +109,61 @@ export function makeAstNodeBuilder<TMap>(reflection: AstReflection): AstNodeBuil
|
|
|
123
109
|
return result as unknown as Extract<TMap[TType], AstNode>;
|
|
124
110
|
};
|
|
125
111
|
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Build a node whose type is only known as a RUNTIME string.
|
|
115
|
+
*
|
|
116
|
+
* The typed {@link makeAstNodeBuilder} cannot express this: its `TMap` generic
|
|
117
|
+
* resolves the AST interface from a `$type` literal, and a type name that
|
|
118
|
+
* arrives over the wire — a protocol-layer reference request naming a node that
|
|
119
|
+
* does not exist yet — has no literal to resolve from. Callers that DO know the
|
|
120
|
+
* type at compile time want the typed builder, which checks their mandatory
|
|
121
|
+
* fields; this one checks nothing beyond the reflection lookup.
|
|
122
|
+
*
|
|
123
|
+
* Applies the same reflection-driven defaulting, so a node built here carries
|
|
124
|
+
* grammar-declared containment arrays rather than leaving them `undefined`. An
|
|
125
|
+
* unknown type name yields a node with `$type` and whatever `init` supplied,
|
|
126
|
+
* because reflection answers no metadata for it and refusing would turn a
|
|
127
|
+
* permissive lookup into a throw at a call site that can only guess.
|
|
128
|
+
*
|
|
129
|
+
* **The `type` argument is authoritative: `init` cannot rebind `$type`.** The
|
|
130
|
+
* typed builder gets this for free — `AstNodeInit` omits `$type`, so a call site
|
|
131
|
+
* cannot reach it — but here `init` is loosely typed, and the case that needs
|
|
132
|
+
* the guarantee is RETYPING: a caller spreading an existing node to produce one
|
|
133
|
+
* of a different type (`{ ...source }`) carries the SOURCE's `$type` in, which
|
|
134
|
+
* would silently win over the type actually requested and hand back a node of
|
|
135
|
+
* the wrong type with no error anywhere.
|
|
136
|
+
*/
|
|
137
|
+
export function buildAstNode<TAst extends AstNode = AstNode>(
|
|
138
|
+
reflection: AstReflection,
|
|
139
|
+
type: string,
|
|
140
|
+
init?: Partial<AstNode> & Record<string, unknown>
|
|
141
|
+
): TAst {
|
|
142
|
+
const result = withTypeDefaults(reflection, type);
|
|
143
|
+
if (init) {
|
|
144
|
+
Object.assign(result, init);
|
|
145
|
+
result.$type = type;
|
|
146
|
+
}
|
|
147
|
+
return result as unknown as TAst;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Seed a node with `$type` plus every property the grammar declares a default
|
|
152
|
+
* for. Array defaults are materialised as a fresh `[]` per call — never shared
|
|
153
|
+
* with the metadata's own array instance, which downstream callers mutate —
|
|
154
|
+
* while scalar defaults are copied as-is since they are immutable.
|
|
155
|
+
*/
|
|
156
|
+
function withTypeDefaults(reflection: AstReflection, type: string): Record<string, unknown> {
|
|
157
|
+
const result: Record<string, unknown> = { $type: type };
|
|
158
|
+
const meta = reflection.getTypeMetaData(type);
|
|
159
|
+
if (meta?.properties) {
|
|
160
|
+
for (const [propName, propInfo] of Object.entries(meta.properties)) {
|
|
161
|
+
const defaultValue = propInfo.defaultValue;
|
|
162
|
+
if (defaultValue === undefined) {
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
result[propName] = Array.isArray(defaultValue) ? [...defaultValue] : defaultValue;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return result;
|
|
169
|
+
}
|
package/src/langium/bootstrap.ts
CHANGED
|
@@ -73,7 +73,14 @@ const EXPECTED_SHARED_SLOTS: readonly ExpectedSlot[] = [
|
|
|
73
73
|
side: 'shared',
|
|
74
74
|
path: 'workspace.BuildPipelineIntegration',
|
|
75
75
|
get: services => nested(services, 'workspace', 'BuildPipelineIntegration')
|
|
76
|
-
}
|
|
76
|
+
},
|
|
77
|
+
// Unbound, this fails where the cause is least visible: the render pass runs
|
|
78
|
+
// inside the `Validated` phase, so a `TypeError` there propagates out of
|
|
79
|
+
// `notifyDocumentPhase` and the document reaches `Validated` with Langium's
|
|
80
|
+
// publisher never invoked — the client receives no diagnostics for the file
|
|
81
|
+
// and the stack names the document builder.
|
|
82
|
+
{ side: 'shared', path: 'MessageRenderer', get: services => nested(services, 'MessageRenderer') },
|
|
83
|
+
{ side: 'shared', path: 'ServerLocale', get: services => nested(services, 'ServerLocale') }
|
|
77
84
|
];
|
|
78
85
|
|
|
79
86
|
/**
|
|
@@ -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
|
// ============================================================
|
|
@@ -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
|
|
|
@@ -878,13 +896,26 @@ export class ModelService<
|
|
|
878
896
|
this.syncChains.set(uri, chain);
|
|
879
897
|
}
|
|
880
898
|
|
|
899
|
+
/**
|
|
900
|
+
* The undo-stack label for a server-authored write, in the locale the server
|
|
901
|
+
* was handed at init.
|
|
902
|
+
*
|
|
903
|
+
* One method rather than the literal at each `applyEdit`, because the two
|
|
904
|
+
* call sites are the same edit — a push and its full-replace retry — and an
|
|
905
|
+
* undo menu showing two different words for one operation would read as two
|
|
906
|
+
* operations.
|
|
907
|
+
*/
|
|
908
|
+
protected editLabel(): string {
|
|
909
|
+
return this.services.MessageRenderer.renderMessage(MODEL_UPDATE_EDIT);
|
|
910
|
+
}
|
|
911
|
+
|
|
881
912
|
protected async drainSyncQueue(uri: string): Promise<void> {
|
|
882
913
|
const uriLogger = this.tracer.withUri(uri);
|
|
883
914
|
while (this.pendingSync.has(uri)) {
|
|
884
915
|
const text = this.pendingSync.get(uri)!;
|
|
885
916
|
this.pendingSync.delete(uri);
|
|
886
917
|
try {
|
|
887
|
-
let result = await this.services.workspace.TextDocuments.applyEditToLanguageClient(uri, text, { label:
|
|
918
|
+
let result = await this.services.workspace.TextDocuments.applyEditToLanguageClient(uri, text, { label: this.editLabel() });
|
|
888
919
|
if (result?.applied === false && !this.pendingSync.has(uri)) {
|
|
889
920
|
// The push is addressed at the client's LAST DECLARED VERSION, so a
|
|
890
921
|
// rejection normally means the client's buffer moved while the
|
|
@@ -905,7 +936,7 @@ export class ModelService<
|
|
|
905
936
|
// queued — best-effort, since a settle arriving later simply pushes
|
|
906
937
|
// after this and still wins.
|
|
907
938
|
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:
|
|
939
|
+
result = await this.services.workspace.TextDocuments.applyEditToLanguageClient(uri, text, { label: this.editLabel() });
|
|
909
940
|
if (result?.applied === false) {
|
|
910
941
|
uriLogger.warn(`Language client rejected the full-replace retry too — client content is stale`);
|
|
911
942
|
}
|
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
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
WorkspaceCache,
|
|
35
35
|
stream
|
|
36
36
|
} from '@hydranium/langium';
|
|
37
|
+
import { buildAstNode } from '../ast-extension/ast-node-builder.js';
|
|
37
38
|
import { type LogNameOptions } from '../diagnostics/logger.js';
|
|
38
39
|
import { type HydraniumLanguageServices } from '../language-module.js';
|
|
39
40
|
import { type NameProvider } from '../naming/name-provider.js';
|
|
@@ -469,12 +470,13 @@ export class HydraniumScopeProvider extends DefaultScopeProvider {
|
|
|
469
470
|
* Convert a protocol-layer {@link ReferenceContext} into a Langium
|
|
470
471
|
* {@link ReferenceInfo} the rest of the scope/linking machinery accepts.
|
|
471
472
|
*
|
|
472
|
-
* Walks `syntheticPath` by FABRICATING a
|
|
473
|
-
*
|
|
474
|
-
*
|
|
475
|
-
*
|
|
476
|
-
*
|
|
477
|
-
* the
|
|
473
|
+
* Walks `syntheticPath` by FABRICATING a stub per step, so a scope can be
|
|
474
|
+
* queried for an element that does not exist yet — which is what synthetic
|
|
475
|
+
* paths are for. A stub carries the grammar's declared defaults and nothing
|
|
476
|
+
* else, so its containment lists are present but EMPTY: a caller that needs
|
|
477
|
+
* to read a populated collection off the leaf wants
|
|
478
|
+
* {@link resolveReferenceSource} instead, which walks the same path into the
|
|
479
|
+
* real tree.
|
|
478
480
|
*
|
|
479
481
|
* Throws if the context references an unresolvable source; callers
|
|
480
482
|
* that prefer a soft failure should catch and fall back to
|
|
@@ -486,16 +488,15 @@ export class HydraniumScopeProvider extends DefaultScopeProvider {
|
|
|
486
488
|
throw new Error('Invalid reference source');
|
|
487
489
|
}
|
|
488
490
|
for (const step of ctx.syntheticPath ?? []) {
|
|
489
|
-
container = {
|
|
491
|
+
container = buildAstNode(this.services.shared.AstReflection, step.type, {
|
|
490
492
|
$container: container,
|
|
491
493
|
$containerProperty: step.containerProperty,
|
|
492
494
|
// Part of Langium's own container contract, so a stub that omits it
|
|
493
495
|
// is an under-specified node: anything reading position off the
|
|
494
496
|
// chain (a key provider, an adopter scope extension) sees
|
|
495
497
|
// `undefined` where the caller named a slot.
|
|
496
|
-
$containerIndex: step.index
|
|
497
|
-
|
|
498
|
-
};
|
|
498
|
+
$containerIndex: step.index
|
|
499
|
+
});
|
|
499
500
|
}
|
|
500
501
|
return {
|
|
501
502
|
reference: { $refText: '', ref: undefined },
|
|
@@ -605,13 +606,16 @@ export class HydraniumScopeProvider extends DefaultScopeProvider {
|
|
|
605
606
|
* `createEmptyDocument`. Overriding is still open to a consumer whose
|
|
606
607
|
* "container" is an inner element rather than the parse root, or one that
|
|
607
608
|
* deliberately declines to answer for an absent document.
|
|
609
|
+
*
|
|
610
|
+
* The stub carries the grammar's declared defaults, so an extension reading a
|
|
611
|
+
* containment list off it sees an empty array rather than `undefined`.
|
|
608
612
|
*/
|
|
609
613
|
protected resolveSyntheticSource(source: SyntheticSource): AstNode | undefined {
|
|
610
614
|
const uri = UriUtils.toUri(source.uri);
|
|
611
615
|
const document =
|
|
612
616
|
this.langiumDocuments.getDocument(uri) ??
|
|
613
617
|
this.langiumDocuments.createEmptyDocument(uri, this.services.LanguageMetaData.languageId);
|
|
614
|
-
return
|
|
618
|
+
return buildAstNode(this.services.shared.AstReflection, source.type, { $container: document.parseResult.value });
|
|
615
619
|
}
|
|
616
620
|
|
|
617
621
|
/**
|
|
@@ -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`
|